Merge "Upgrade jquery.i18n library from v1.0.2 to v1.0.3"

This commit is contained in:
jenkins-bot
2015-07-10 06:59:32 +00:00
committed by Gerrit Code Review
13 changed files with 1334 additions and 396 deletions

View File

@@ -197,6 +197,7 @@ $wgResourceModules['jquery.i18n'] = array(
'lib/jquery.i18n/jquery.i18n.messagestore.js', 'lib/jquery.i18n/jquery.i18n.messagestore.js',
'lib/jquery.i18n/jquery.i18n.parser.js', 'lib/jquery.i18n/jquery.i18n.parser.js',
'lib/jquery.i18n/jquery.i18n.emitter.js', 'lib/jquery.i18n/jquery.i18n.emitter.js',
'lib/jquery.i18n/jquery.i18n.emitter.bidi.js',
'lib/jquery.i18n/jquery.i18n.language.js', 'lib/jquery.i18n/jquery.i18n.language.js',
), ),
'dependencies' => 'mediawiki.libs.pluralruleparser', 'dependencies' => 'mediawiki.libs.pluralruleparser',

9
lib/jquery.i18n/CREDITS Normal file
View File

@@ -0,0 +1,9 @@
Credits
=======
Santhosh Thottingal
Amir E. Aharoni
Siebrand Mazeland
Niklas Laxström
Neil Kandalgaonkar
David Chan

342
lib/jquery.i18n/GPL-LICENSE Normal file
View File

@@ -0,0 +1,342 @@
== GNU GENERAL PUBLIC LICENSE ==
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
=== Preamble ===
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
== TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION ==
'''0.''' This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
'''1.''' You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
'''2.''' You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
'''a)''' You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
'''b)''' You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
'''c)''' If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
'''3.''' You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
'''a)''' Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
'''b)''' Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
'''c)''' Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
'''4.''' You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
'''5.''' You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
'''6.''' Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
'''7.''' If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
'''8.''' If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
'''9.''' The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
'''10.''' If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
=== NO WARRANTY ===
'''11.''' BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
'''12.''' IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
'''END OF TERMS AND CONDITIONS'''
== How to Apply These Terms to Your New Programs ==
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View File

@@ -0,0 +1,21 @@
Copyright (c) 2012-2013 Santhosh Thottingal and other
contributors. See CREDITS for a list.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

432
lib/jquery.i18n/README.md Normal file
View File

@@ -0,0 +1,432 @@
jQuery.i18n
===========
jQuery.i18n is a jQuery based Javascript internationalization library. It helps you to internationalize your web applications easily.
This is a project by Wikimedia foundation's [Language Engineering team](http://wikimediafoundation.org/wiki/Language_Engineering_team) and used in some of the Wikimedia Foundation projects like Universal Language Selector.
The jquery.i18n library uses a json based localization file format, "banana", which is used as the localization file format for MediaWiki and other projects.
Features
========
* Simple file format - JSON. Easily readable for humans and machines.
* Author and metadata information is not lost anywhere. There are other file formats using comments to store this.
* Uses MediaWiki convention for placeholders. Easily readable and proven convention. Example: ```There are $1 cars```
* Supports plural conversion without using extra messages for all plural forms. Plural rule handling is done using CLDR. Covers a wide range of languages
* Supports gender. By passing the gender value, you get correct sentences according to gender.
* Supports grammar forms. jquery.i18n has a basic but extensible grammar conversion support
* Fallback chains for all languages.
* Data api- the message key. Example: ```<li data-i18n="message-key"></li>```.
* Dynamic change of interface language without refreshing a webpage.
* Nestable grammar, plural, gender support. These constructs can be nested to any arbitrary level for supporting sophisticated message localization
* Message documentation through special language code ```qqq```
* Extensible message parser to add or customize magic words in the messages. Example: ```{sitename}``` or ```[[link]]``
Quick start
-----------
```bash
git clone https://github.com/wikimedia/jquery.i18n.git
cd jquery.i18n
git submodule update --init
```
Testing
-------
```shell
npm install
```
To run tests locally, run `npm test`, and this will run the tests.
Message File Format
===================
The message files are json formatted. As a convention you can have a folder named i18n inside your source code. For each language or locale, have a file named like languagecode.json.
Example:
```
App
|--src
|--doc
|--i18n
|--ar.json
|--de.json
|--en.json
|--he.json
|--hi.json
|--fr.json
|--qqq.json
```
A simple en.json file example is given below
```json
{
"@metadata": {
"authors": [
"Alice",
"David",
"Santhosh"
],
"last-updated": "2012-09-21",
"locale": "en",
"message-documentation": "qqq",
"AnotherMetadata": "AnotherMedatadataValue"
},
"appname-title": "Example Application",
"appname-sub-title": "An example application with jquery.i18n",
"appname-header-introduction": "Introduction",
"appname-about": "About this application",
"appname-footer": "Footer text"
}
```
The json file should be a valid json. The ```@metadata``` holds all kind of data that are not messages. You can store author information, copyright, updated date or anything there.
Messages are key value pairs. It is a good convention to prefix your appname to message keys to make the messages unique. It acts as the namespace for the message keys. It is also a good convention to have the message keys with ```-``` separated words, all in lower case.
If you are curious to see some real jquery.i18n message file from other projects:
- message files of MediaWiki https://github.com/wikimedia/mediawiki-core/tree/master/languages/i18n
- message files from jquery.uls project https://github.com/wikimedia/jquery.uls/blob/master/i18n
Single message file for all languages
-------------------------------------
There are some alternate message file format supported for different use cases. If your application is not big, and want all the translation in a single file, you can have it as shown in the below example:
```json
{
"@metadata": {
"authors": [
"Alice",
"David",
"Santhosh"
],
"last-updated": "2012-09-21",
"locale": "en",
"message-documentation": "qqq",
"AnotherMetadata": "AnotherMedatadataValue"
},
"en": {
"appname-title": "Example Application",
"appname-sub-title": "An example application with jquery.i18n",
"appname-header-introduction": "Introduction",
"appname-about": "About this application",
"appname-footer": "Footer text"
},
"ml": {
"appname-title": "അപ്ലിക്കേഷന്‍ ഉദാഹരണം",
"appname-sub-title": "jquery.i18n ഉപയോഗിച്ചുള്ള അപ്ലിക്കേഷന്‍ ഉദാഹരണം",
"appname-header-introduction": "ആമുഖം",
"appname-about": "ഈ അപ്ലിക്കേഷനെപ്പറ്റി",
"appname-footer": "അടിക്കുറിപ്പു്"
}
}
```
Here the json file contains language code as key value and messagekey-message pairs as the value for all language pairs. You can choose this format or per-language file formats depending on your use case. Per-language files are more convenient for collaboration, version controlling, scalability, etc.
In this approach, it is also possible to give a file name as the value of language code.
```json
{
"@metadata": {
"authors": [
"Alice",
"David",
"Santhosh"
],
"last-updated": "2012-09-21",
"locale": "en",
"message-documentation": "qqq",
"AnotherMetadata": "AnotherMedatadataValue"
},
"en": {
"appname-title": "Example Application",
"appname-sub-title": "An example application with jquery.i18n",
"appname-header-introduction": "Introduction",
"appname-about": "About this application",
"appname-footer": "Footer text"
},
"ml": "path/to/ml.json"
}
```
Translation
===========
To translate the jquery.i18n application, depending on the expertise of the translator, there are multiple ways.
* Editing the json files directly - Suitable for translators with technical background. Also suitable if your application is small and you want to work with only a small number of languages
* Providing a translation interface along with your application: Suitable for proprietary or private applications with significant amount of translators
* Using open source translation platforms like translatewiki.net. The MediaWiki and jquery.uls from previous examples use translatewiki.net for crowdsourced message translation. Translatewiki.net can update your code repo in regular intervals with updated translations. Highly recommended if your application is opensource and want localized to as many as languages possible with maximum number of translators.
Usage
=====
## Switching locale
While initializing the `jquery.i18n`, the locale for the page can be given using the `locale` option. For example
```javascript
$.i18n( {
locale: 'he' // Locale is Hebrew
} );
```
In case locale option is not given, `jquery.i18n` plugin will use the language attribute given for the html tag. For example
```html
<html lang="he" dir="rtl">
```
In this case the locale will be he(Hebrew). If that `lang` attribute is also missing, it will try to use the locale specified by the browser.
It is possible to switch to another locale after plugin is initialized. See below example:
```javascript
$.i18n({
locale: 'he' // Locale is Hebrew
});
$.i18n( 'message_hello' ); // This will give the Hebrew translation of message key `message_hello`.
$.i18n().locale = 'ml'; // Now onwards locale is 'Malayalam'
$.i18n( 'message_hello' ); // This will give the Malayalam translation of message key `message_hello`.
```
## Message Loading
JSON formatted messages can be loaded to the plugin using multiple ways.
### Dynamic loading using `load` method.
Following example shows loading messages for two locales- localex, and localey. Here localex and localey are just examples. They should be valid IS0 639 language codes(eg: en, ml, hi, fr, ta etc)
```javascript
$.i18n().load( {
'localex' : {
'message-key1' : 'message1' // Message for localex.
},
'localey' : {
'message-key1' : 'message1'
}
} );
```
If we want to load the messages for a specific locale, it can be done like this:
```javascript
$.i18n().load({
'message-hello': 'Hello World',
'message-welcome': 'Welcome'
}, 'en');
```
Note the second argument for the `load` method. It should be a valid language code.
It is also possible to refer messages from an external URL. See below example
```javascript
$.i18n().load( {
en: {
message_hello: 'Hello World',
message_welcome: 'Welcome'
},
hi: 'i18n/messages-hi.json', // Messages for Hindi
de: 'i18n/messages-de.json'
} );
```
Messages for a locale can be also loaded in parts. Example
```javascript
$.i18n().load( {
en: {
message_hello: 'Hello World',
message_welcome: 'Welcome'
}
} );
$.i18n().load( {
// This does not remove the previous messages.
en: {
'message_header' : 'Header',
'message_footer' : 'Footer',
// This will overwrite message_welcome message
'message_welcome' : 'Welcome back'
}
} );
```
Since it is desirable to render interface messages instantly and not after a delay of loading the message files from a server, make sure that the messages are present at client side before using jQuery.i18n.
The library should expose an API to load an object containing key-value pair of messages. Example: ```$.i18n.load(data)```. This will return a ```jQuery.Promise```.
jquery.i18n plugin
=========================
The jQuery plugin defines ```$.i18n()``` and ```$.fn.i18n()```
```javascript
$.i18n( 'message-key-sample1' );
$.i18n( 'message-key-sample1' );
$.i18n( 'Found $1 {{plural:$1|result|results}}', 10 ); // Message key itself is message text
$.i18n( 'Showing $1 out of $2 {{plural:$2|result|results}}', 5,100 );
$.i18n(' User X updated {{gender|his|her}} profile', 'male' );
$( '#foo' ).i18n(); // to translate the element matching jquery selector based on data-i18n key
```
Data API
--------
It is possible to display localized messages without any custom JavaScript. For the HTML tags, add an attribute data-i18n with value as the message key. Example:
```html
<li data-i18n="message-key"></li>.
```
It is also possible to have the above li node with fallback text already in place.
```html
<li data-i18n="message-key">Fallback text</li>
```
The framework will place the localized message corresponding to message-key as the text value of the node. Similar to $('selector').i18n( ... ).
This will not work for dynamically created elements.
Note that if data-i18n contains html markup, that html will not be used as the element content, instead, the text version will be used. $.fn.i18n is always about replacing text of the element. If you want to change the html of the element, you may want to use: ```$(selector).html($.i18n(messagekey))```
Examples
========
See http://thottingal.in/projects/js/jquery.i18n/demo/
Message format
==============
## Placeholders
Messages take parameters. They are represented by $1, $2, $3, … in the message texts, and replaced at run time. Typical parameter values are numbers (Example: "Delete 3 versions?"), or user names (Example: "Page last edited by $1"), page names, links, and so on, or sometimes other messages.
```javascript
var message = "Welcome, $1";
$.i18n(message, 'Alice'); // This gives "Welcome, Alice"
```
## Plurals
To make the syntax of sentence correct, plural forms are required. jquery.i18n support plural forms in the message using the syntax `{{PLURAL:$1|pluralform1|pluralform2|...}}`
For example:
```javascript
var message = "Found $1 {{PLURAL:$1|result|results}}";
$.i18n(message, 1); // This gives "Found 1 result"
$.i18n(message, 4); // This gives "Found 4 results"
```
Note that {{PLURAL:...}} is not case sensitive. It can be {{plural:...}} too.
In case of English, there are only 2 plural forms, but many languages use more than 2 plural forms. All the plural forms can be given in the above syntax, separated by pipe(|)
## Gender
Similar to plural, depending on gender of placeholders, mostly user names, the syntax changes dynamically. An example in English is "Alice changed her profile picture" and "Bob changed his profile picture". To support this {{GENDER...}} syntax can be used as show in example
```javascript
var message = "$1 changed {{GENDER:$2|his|her}} profile picture";
$.i18n(message, 'Alice', 'female' ); // This gives "Alice changed her profile picture"
$.i18n(message, 'Bob', 'male' ); // This gives "Bob changed his profile picture"
```
Note that {{GENDER:...}} is not case sensitive. It can be {{gender:...}} too.
## Grammar
```javascript
$.i18n( { locale: 'fi' } );
var message = "{{grammar:genitive|$1}}";
$.i18n(message, 'talo' ); // This gives "talon"
$.i18n().locale = 'hy'; // Switch to locale Armenian
$.i18n(message, 'Մաունա'); // This gives "Մաունայի"
```
## Directionality-safe isolation
To avoid BIDI corruption that looks like "(Foo_(Bar", which happens when a string is inserted into a context with the reverse directionality, you can use `{{bidi:…}}`. Directionality-neutral characters at the edge of the string can get wrongly interpreted by the BIDI algorithm. This would let you embed your substituted string into a new BIDI context, //e.g.//:
"`Shalom, {{bidi:$1}}, hi!`"
The embedded context's directionality is determined by looking at the argument for `$1`, and then explicitly inserted into the Unicode text, ensuring correct rendering (because then the bidi algorithm "knows" the argument text is a separate context).
Fallback
========
The plugin takes an option 'fallback' with the default value 'en'. The library reuses the fallback data available in MediaWiki for calculating the language fallbacks. Fallbacks are used when a message key is not found in a locale. Example fallbacks: sa->hi->en or tt->tt-cyrl->ru.
See jquery.i18n.fallbacks.js in the source.
Magic word support
===================
* For plural, gender and grammar support, MediaWiki template-like syntax - {{...}} will be used.
* There will be a default implementation for all these in $.i18n.language['default']
* The plural, gender and grammar methods in ```$.i18n.language[ 'default' ]``` can be overridden or extended in ```$.i18n.language['languageCode']```.
* Language-specific rules about Gender and Grammar can be written in languages/langXYZ.js files
* Plural forms will be dynamically calculated using the CLDR plural parser.
Extending the parser
--------------------
Following example illustrates extending the parser to support more magic words
```javascript
$.extend( $.i18n.parser.emitter, {
// Handle SITENAME keywords
sitename: function () {
return 'Wikipedia';
},
// Handle LINK keywords
link: function ( nodes ) {
return '<a href="' + nodes[1] + '">' + nodes[0] + '</a>';
}
} );
```
This will parse the message
```javascript
$.i18n( '{{link:{{SITENAME}}|http://en.wikipedia.org}}' );
```
to
```html
<a href="http://en.wikipedia.org">Wikipedia</a>
```
Message documentation
=====================
The message keys and messages won't give a enough context about the message being translated to the translator. Whenever a developer adds a new message, it is a usual practice to document the message to a file named qqq.json
with same message key.
Example qqq.json:
```json
{
"@metadata": {
"authors": [
"Developer Name"
]
},
"appname-title": "Application name. Transliteration is recommended",
"appname-sub-title": "Brief explanation of the application",
"appname-header-introduction": "Text for the introduction header",
"appname-about": "About this application text",
"appname-footer": "Footer text"
}
```
In MediaWiki and its hundreds of extensions, message documentation is a strictly followed practice. There is a grunt task to check whether all messages are documented or not. See https://www.npmjs.org/package/grunt-banana-checker

File diff suppressed because one or more lines are too long

View File

@@ -16,171 +16,171 @@
$.i18n = $.i18n || {}; $.i18n = $.i18n || {};
$.extend( $.i18n.fallbacks, { $.extend( $.i18n.fallbacks, {
'ab': ['ru'], ab: [ 'ru' ],
'ace': ['id'], ace: [ 'id' ],
'aln': ['sq'], aln: [ 'sq' ],
// Not so standard - als is supposed to be Tosk Albanian, // Not so standard - als is supposed to be Tosk Albanian,
// but in Wikipedia it's used for a Germanic language. // but in Wikipedia it's used for a Germanic language.
'als': ['gsw', 'de'], als: [ 'gsw', 'de' ],
'an': ['es'], an: [ 'es' ],
'anp': ['hi'], anp: [ 'hi' ],
'arn': ['es'], arn: [ 'es' ],
'arz': ['ar'], arz: [ 'ar' ],
'av': ['ru'], av: [ 'ru' ],
'ay': ['es'], ay: [ 'es' ],
'ba': ['ru'], ba: [ 'ru' ],
'bar': ['de'], bar: [ 'de' ],
'bat-smg': ['sgs', 'lt'], 'bat-smg': [ 'sgs', 'lt' ],
'bcc': ['fa'], bcc: [ 'fa' ],
'be-x-old': ['be-tarask'], 'be-x-old': [ 'be-tarask' ],
'bh': ['bho'], bh: [ 'bho' ],
'bjn': ['id'], bjn: [ 'id' ],
'bm': ['fr'], bm: [ 'fr' ],
'bpy': ['bn'], bpy: [ 'bn' ],
'bqi': ['fa'], bqi: [ 'fa' ],
'bug': ['id'], bug: [ 'id' ],
'cbk-zam': ['es'], 'cbk-zam': [ 'es' ],
'ce': ['ru'], ce: [ 'ru' ],
'crh': ['crh-latn'], crh: [ 'crh-latn' ],
'crh-cyrl': ['ru'], 'crh-cyrl': [ 'ru' ],
'csb': ['pl'], csb: [ 'pl' ],
'cv': ['ru'], cv: [ 'ru' ],
'de-at': ['de'], 'de-at': [ 'de' ],
'de-ch': ['de'], 'de-ch': [ 'de' ],
'de-formal': ['de'], 'de-formal': [ 'de' ],
'dsb': ['de'], dsb: [ 'de' ],
'dtp': ['ms'], dtp: [ 'ms' ],
'egl': ['it'], egl: [ 'it' ],
'eml': ['it'], eml: [ 'it' ],
'ff': ['fr'], ff: [ 'fr' ],
'fit': ['fi'], fit: [ 'fi' ],
'fiu-vro': ['vro', 'et'], 'fiu-vro': [ 'vro', 'et' ],
'frc': ['fr'], frc: [ 'fr' ],
'frp': ['fr'], frp: [ 'fr' ],
'frr': ['de'], frr: [ 'de' ],
'fur': ['it'], fur: [ 'it' ],
'gag': ['tr'], gag: [ 'tr' ],
'gan': ['gan-hant', 'zh-hant', 'zh-hans'], gan: [ 'gan-hant', 'zh-hant', 'zh-hans' ],
'gan-hans': ['zh-hans'], 'gan-hans': [ 'zh-hans' ],
'gan-hant': ['zh-hant', 'zh-hans'], 'gan-hant': [ 'zh-hant', 'zh-hans' ],
'gl': ['pt'], gl: [ 'pt' ],
'glk': ['fa'], glk: [ 'fa' ],
'gn': ['es'], gn: [ 'es' ],
'gsw': ['de'], gsw: [ 'de' ],
'hif': ['hif-latn'], hif: [ 'hif-latn' ],
'hsb': ['de'], hsb: [ 'de' ],
'ht': ['fr'], ht: [ 'fr' ],
'ii': ['zh-cn', 'zh-hans'], ii: [ 'zh-cn', 'zh-hans' ],
'inh': ['ru'], inh: [ 'ru' ],
'iu': ['ike-cans'], iu: [ 'ike-cans' ],
'jut': ['da'], jut: [ 'da' ],
'jv': ['id'], jv: [ 'id' ],
'kaa': ['kk-latn', 'kk-cyrl'], kaa: [ 'kk-latn', 'kk-cyrl' ],
'kbd': ['kbd-cyrl'], kbd: [ 'kbd-cyrl' ],
'khw': ['ur'], khw: [ 'ur' ],
'kiu': ['tr'], kiu: [ 'tr' ],
'kk': ['kk-cyrl'], kk: [ 'kk-cyrl' ],
'kk-arab': ['kk-cyrl'], 'kk-arab': [ 'kk-cyrl' ],
'kk-latn': ['kk-cyrl'], 'kk-latn': [ 'kk-cyrl' ],
'kk-cn': ['kk-arab', 'kk-cyrl'], 'kk-cn': [ 'kk-arab', 'kk-cyrl' ],
'kk-kz': ['kk-cyrl'], 'kk-kz': [ 'kk-cyrl' ],
'kk-tr': ['kk-latn', 'kk-cyrl'], 'kk-tr': [ 'kk-latn', 'kk-cyrl' ],
'kl': ['da'], kl: [ 'da' ],
'ko-kp': ['ko'], 'ko-kp': [ 'ko' ],
'koi': ['ru'], koi: [ 'ru' ],
'krc': ['ru'], krc: [ 'ru' ],
'ks': ['ks-arab'], ks: [ 'ks-arab' ],
'ksh': ['de'], ksh: [ 'de' ],
'ku': ['ku-latn'], ku: [ 'ku-latn' ],
'ku-arab': ['ckb'], 'ku-arab': [ 'ckb' ],
'kv': ['ru'], kv: [ 'ru' ],
'lad': ['es'], lad: [ 'es' ],
'lb': ['de'], lb: [ 'de' ],
'lbe': ['ru'], lbe: [ 'ru' ],
'lez': ['ru'], lez: [ 'ru' ],
'li': ['nl'], li: [ 'nl' ],
'lij': ['it'], lij: [ 'it' ],
'liv': ['et'], liv: [ 'et' ],
'lmo': ['it'], lmo: [ 'it' ],
'ln': ['fr'], ln: [ 'fr' ],
'ltg': ['lv'], ltg: [ 'lv' ],
'lzz': ['tr'], lzz: [ 'tr' ],
'mai': ['hi'], mai: [ 'hi' ],
'map-bms': ['jv', 'id'], 'map-bms': [ 'jv', 'id' ],
'mg': ['fr'], mg: [ 'fr' ],
'mhr': ['ru'], mhr: [ 'ru' ],
'min': ['id'], min: [ 'id' ],
'mo': ['ro'], mo: [ 'ro' ],
'mrj': ['ru'], mrj: [ 'ru' ],
'mwl': ['pt'], mwl: [ 'pt' ],
'myv': ['ru'], myv: [ 'ru' ],
'mzn': ['fa'], mzn: [ 'fa' ],
'nah': ['es'], nah: [ 'es' ],
'nap': ['it'], nap: [ 'it' ],
'nds': ['de'], nds: [ 'de' ],
'nds-nl': ['nl'], 'nds-nl': [ 'nl' ],
'nl-informal': ['nl'], 'nl-informal': [ 'nl' ],
'no': ['nb'], no: [ 'nb' ],
'os': ['ru'], os: [ 'ru' ],
'pcd': ['fr'], pcd: [ 'fr' ],
'pdc': ['de'], pdc: [ 'de' ],
'pdt': ['de'], pdt: [ 'de' ],
'pfl': ['de'], pfl: [ 'de' ],
'pms': ['it'], pms: [ 'it' ],
'pt': ['pt-br'], pt: [ 'pt-br' ],
'pt-br': ['pt'], 'pt-br': [ 'pt' ],
'qu': ['es'], qu: [ 'es' ],
'qug': ['qu', 'es'], qug: [ 'qu', 'es' ],
'rgn': ['it'], rgn: [ 'it' ],
'rmy': ['ro'], rmy: [ 'ro' ],
'roa-rup': ['rup'], 'roa-rup': [ 'rup' ],
'rue': ['uk', 'ru'], rue: [ 'uk', 'ru' ],
'ruq': ['ruq-latn', 'ro'], ruq: [ 'ruq-latn', 'ro' ],
'ruq-cyrl': ['mk'], 'ruq-cyrl': [ 'mk' ],
'ruq-latn': ['ro'], 'ruq-latn': [ 'ro' ],
'sa': ['hi'], sa: [ 'hi' ],
'sah': ['ru'], sah: [ 'ru' ],
'scn': ['it'], scn: [ 'it' ],
'sg': ['fr'], sg: [ 'fr' ],
'sgs': ['lt'], sgs: [ 'lt' ],
'sli': ['de'], sli: [ 'de' ],
'sr': ['sr-ec'], sr: [ 'sr-ec' ],
'srn': ['nl'], srn: [ 'nl' ],
'stq': ['de'], stq: [ 'de' ],
'su': ['id'], su: [ 'id' ],
'szl': ['pl'], szl: [ 'pl' ],
'tcy': ['kn'], tcy: [ 'kn' ],
'tg': ['tg-cyrl'], tg: [ 'tg-cyrl' ],
'tt': ['tt-cyrl', 'ru'], tt: [ 'tt-cyrl', 'ru' ],
'tt-cyrl': ['ru'], 'tt-cyrl': [ 'ru' ],
'ty': ['fr'], ty: [ 'fr' ],
'udm': ['ru'], udm: [ 'ru' ],
'ug': ['ug-arab'], ug: [ 'ug-arab' ],
'uk': ['ru'], uk: [ 'ru' ],
'vec': ['it'], vec: [ 'it' ],
'vep': ['et'], vep: [ 'et' ],
'vls': ['nl'], vls: [ 'nl' ],
'vmf': ['de'], vmf: [ 'de' ],
'vot': ['fi'], vot: [ 'fi' ],
'vro': ['et'], vro: [ 'et' ],
'wa': ['fr'], wa: [ 'fr' ],
'wo': ['fr'], wo: [ 'fr' ],
'wuu': ['zh-hans'], wuu: [ 'zh-hans' ],
'xal': ['ru'], xal: [ 'ru' ],
'xmf': ['ka'], xmf: [ 'ka' ],
'yi': ['he'], yi: [ 'he' ],
'za': ['zh-hans'], za: [ 'zh-hans' ],
'zea': ['nl'], zea: [ 'nl' ],
'zh': ['zh-hans'], zh: [ 'zh-hans' ],
'zh-classical': ['lzh'], 'zh-classical': [ 'lzh' ],
'zh-cn': ['zh-hans'], 'zh-cn': [ 'zh-hans' ],
'zh-hant': ['zh-hans'], 'zh-hant': [ 'zh-hans' ],
'zh-hk': ['zh-hant', 'zh-hans'], 'zh-hk': [ 'zh-hant', 'zh-hans' ],
'zh-min-nan': ['nan'], 'zh-min-nan': [ 'nan' ],
'zh-mo': ['zh-hk', 'zh-hant', 'zh-hans'], 'zh-mo': [ 'zh-hk', 'zh-hant', 'zh-hans' ],
'zh-my': ['zh-sg', 'zh-hans'], 'zh-my': [ 'zh-sg', 'zh-hans' ],
'zh-sg': ['zh-hans'], 'zh-sg': [ 'zh-hans' ],
'zh-tw': ['zh-hant', 'zh-hans'], 'zh-tw': [ 'zh-hant', 'zh-hans' ],
'zh-yue': ['yue'] 'zh-yue': [ 'yue' ]
} ); } );
}( jQuery ) ); }( jQuery ) );

View File

@@ -123,9 +123,9 @@
* can also be passed. Example: * can also be passed. Example:
* <code> * <code>
* load( { * load( {
* 'bn': 'i18n/bn.json', * bn: 'i18n/bn.json',
* 'he': 'i18n/he.json', * he: 'i18n/he.json',
* 'en': 'i18n/en.json' * en: 'i18n/en.json'
* } ) * } )
* </code> * </code>
* *
@@ -138,12 +138,12 @@
*/ */
load: function ( source, locale ) { load: function ( source, locale ) {
var fallbackLocales, locIndex, fallbackLocale, sourceMap = {}; var fallbackLocales, locIndex, fallbackLocale, sourceMap = {};
if (!source && !locale) { if ( !source && !locale ) {
source = 'i18n/' + $.i18n().locale + '.json'; source = 'i18n/' + $.i18n().locale + '.json';
locale = $.i18n().locale; locale = $.i18n().locale;
} }
if ( typeof source === 'string' && if ( typeof source === 'string' &&
source.split('.').pop() !== 'json' source.split( '.' ).pop() !== 'json'
) { ) {
// Load specified locale then check for fallbacks when directory is specified in load() // Load specified locale then check for fallbacks when directory is specified in load()
sourceMap[locale] = source + '/' + locale + '.json'; sourceMap[locale] = source + '/' + locale + '.json';
@@ -173,7 +173,7 @@
// should probably not change the 'this.parser' but just // should probably not change the 'this.parser' but just
// pass it to the parser. // pass it to the parser.
this.parser.language = $.i18n.languages[$.i18n().locale] || $.i18n.languages['default']; this.parser.language = $.i18n.languages[$.i18n().locale] || $.i18n.languages['default'];
if( message === '' ) { if ( message === '' ) {
message = key; message = key;
} }
return this.parser.parse( message, parameters ); return this.parser.parse( message, parameters );

View File

@@ -5,262 +5,263 @@
var language = { var language = {
// CLDR plural rules generated using // CLDR plural rules generated using
// libs/CLDRPluralRuleParser/tools/PluralXML2JSON.html // libs/CLDRPluralRuleParser/tools/PluralXML2JSON.html
'pluralRules': { pluralRules: {
'ak': { ak: {
'one': 'n = 0..1' one: 'n = 0..1'
}, },
'am': { am: {
'one': 'i = 0 or n = 1' one: 'i = 0 or n = 1'
}, },
'ar': { ar: {
'zero': 'n = 0', zero: 'n = 0',
'one': 'n = 1', one: 'n = 1',
'two': 'n = 2', two: 'n = 2',
'few': 'n % 100 = 3..10', few: 'n % 100 = 3..10',
'many': 'n % 100 = 11..99' many: 'n % 100 = 11..99'
}, },
'be': { be: {
'one': 'n % 10 = 1 and n % 100 != 11', one: 'n % 10 = 1 and n % 100 != 11',
'few': 'n % 10 = 2..4 and n % 100 != 12..14', few: 'n % 10 = 2..4 and n % 100 != 12..14',
'many': 'n % 10 = 0 or n % 10 = 5..9 or n % 100 = 11..14' many: 'n % 10 = 0 or n % 10 = 5..9 or n % 100 = 11..14'
}, },
'bh': { bh: {
'one': 'n = 0..1' one: 'n = 0..1'
}, },
'bn': { bn: {
'one': 'i = 0 or n = 1' one: 'i = 0 or n = 1'
}, },
'br': { br: {
'one': 'n % 10 = 1 and n % 100 != 11,71,91', one: 'n % 10 = 1 and n % 100 != 11,71,91',
'two': 'n % 10 = 2 and n % 100 != 12,72,92', two: 'n % 10 = 2 and n % 100 != 12,72,92',
'few': 'n % 10 = 3..4,9 and n % 100 != 10..19,70..79,90..99', few: 'n % 10 = 3..4,9 and n % 100 != 10..19,70..79,90..99',
'many': 'n != 0 and n % 1000000 = 0' many: 'n != 0 and n % 1000000 = 0'
}, },
'bs': { bs: {
'one': 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11', one: 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11',
'few': 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14' few: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14'
}, },
'cs': { cs: {
'one': 'i = 1 and v = 0', one: 'i = 1 and v = 0',
'few': 'i = 2..4 and v = 0', few: 'i = 2..4 and v = 0',
'many': 'v != 0' many: 'v != 0'
}, },
'cy': { cy: {
'zero': 'n = 0', zero: 'n = 0',
'one': 'n = 1', one: 'n = 1',
'two': 'n = 2', two: 'n = 2',
'few': 'n = 3', few: 'n = 3',
'many': 'n = 6' many: 'n = 6'
}, },
'da': { da: {
'one': 'n = 1 or t != 0 and i = 0,1' one: 'n = 1 or t != 0 and i = 0,1'
}, },
'fa': { fa: {
'one': 'i = 0 or n = 1' one: 'i = 0 or n = 1'
}, },
'ff': { ff: {
'one': 'i = 0,1' one: 'i = 0,1'
}, },
'fil': { fil: {
'one': 'i = 0..1 and v = 0' one: 'i = 0..1 and v = 0'
}, },
'fr': { fr: {
'one': 'i = 0,1' one: 'i = 0,1'
}, },
'ga': { ga: {
'one': 'n = 1', one: 'n = 1',
'two': 'n = 2', two: 'n = 2',
'few': 'n = 3..6', few: 'n = 3..6',
'many': 'n = 7..10' many: 'n = 7..10'
}, },
'gd': { gd: {
'one': 'n = 1,11', one: 'n = 1,11',
'two': 'n = 2,12', two: 'n = 2,12',
'few': 'n = 3..10,13..19' few: 'n = 3..10,13..19'
}, },
'gu': { gu: {
'one': 'i = 0 or n = 1' one: 'i = 0 or n = 1'
}, },
'guw': { guw: {
'one': 'n = 0..1' one: 'n = 0..1'
}, },
'gv': { gv: {
'one': 'n % 10 = 1', one: 'n % 10 = 1',
'two': 'n % 10 = 2', two: 'n % 10 = 2',
'few': 'n % 100 = 0,20,40,60' few: 'n % 100 = 0,20,40,60'
}, },
'he': { he: {
'one': 'i = 1 and v = 0', one: 'i = 1 and v = 0',
'two': 'i = 2 and v = 0', two: 'i = 2 and v = 0',
'many': 'v = 0 and n != 0..10 and n % 10 = 0' many: 'v = 0 and n != 0..10 and n % 10 = 0'
}, },
'hi': { hi: {
'one': 'i = 0 or n = 1' one: 'i = 0 or n = 1'
}, },
'hr': { hr: {
'one': 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11', one: 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11',
'few': 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14' few: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14'
}, },
'hy': { hy: {
'one': 'i = 0,1' one: 'i = 0,1'
}, },
'is': { is: {
'one': 't = 0 and i % 10 = 1 and i % 100 != 11 or t != 0' one: 't = 0 and i % 10 = 1 and i % 100 != 11 or t != 0'
}, },
'iu': { iu: {
'one': 'n = 1', one: 'n = 1',
'two': 'n = 2' two: 'n = 2'
}, },
'iw': { iw: {
'one': 'i = 1 and v = 0', one: 'i = 1 and v = 0',
'two': 'i = 2 and v = 0', two: 'i = 2 and v = 0',
'many': 'v = 0 and n != 0..10 and n % 10 = 0' many: 'v = 0 and n != 0..10 and n % 10 = 0'
}, },
'kab': { kab: {
'one': 'i = 0,1' one: 'i = 0,1'
}, },
'kn': { kn: {
'one': 'i = 0 or n = 1' one: 'i = 0 or n = 1'
}, },
'kw': { kw: {
'one': 'n = 1', one: 'n = 1',
'two': 'n = 2' two: 'n = 2'
}, },
'lag': { lag: {
'zero': 'n = 0', zero: 'n = 0',
'one': 'i = 0,1 and n != 0' one: 'i = 0,1 and n != 0'
}, },
'ln': { ln: {
'one': 'n = 0..1' one: 'n = 0..1'
}, },
'lt': { lt: {
'one': 'n % 10 = 1 and n % 100 != 11..19', one: 'n % 10 = 1 and n % 100 != 11..19',
'few': 'n % 10 = 2..9 and n % 100 != 11..19', few: 'n % 10 = 2..9 and n % 100 != 11..19',
'many': 'f != 0' many: 'f != 0'
}, },
'lv': { lv: {
'zero': 'n % 10 = 0 or n % 100 = 11..19 or v = 2 and f % 100 = 11..19', zero: 'n % 10 = 0 or n % 100 = 11..19 or v = 2 and f % 100 = 11..19',
'one': 'n % 10 = 1 and n % 100 != 11 or v = 2 and f % 10 = 1 and f % 100 != 11 or v != 2 and f % 10 = 1' one: 'n % 10 = 1 and n % 100 != 11 or v = 2 and f % 10 = 1 and f % 100 != 11 or v != 2 and f % 10 = 1'
}, },
'mg': { mg: {
'one': 'n = 0..1' one: 'n = 0..1'
}, },
'mk': { mk: {
'one': 'v = 0 and i % 10 = 1 or f % 10 = 1' one: 'v = 0 and i % 10 = 1 or f % 10 = 1'
}, },
'mo': { mo: {
'one': 'i = 1 and v = 0', one: 'i = 1 and v = 0',
'few': 'v != 0 or n = 0 or n != 1 and n % 100 = 1..19' few: 'v != 0 or n = 0 or n != 1 and n % 100 = 1..19'
}, },
'mr': { mr: {
'one': 'i = 0 or n = 1' one: 'i = 0 or n = 1'
}, },
'mt': { mt: {
'one': 'n = 1', one: 'n = 1',
'few': 'n = 0 or n % 100 = 2..10', few: 'n = 0 or n % 100 = 2..10',
'many': 'n % 100 = 11..19' many: 'n % 100 = 11..19'
}, },
'naq': { naq: {
'one': 'n = 1', one: 'n = 1',
'two': 'n = 2' two: 'n = 2'
}, },
'nso': { nso: {
'one': 'n = 0..1' one: 'n = 0..1'
}, },
'pa': { pa: {
'one': 'n = 0..1' one: 'n = 0..1'
}, },
'pl': { pl: {
'one': 'i = 1 and v = 0', one: 'i = 1 and v = 0',
'few': 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14', few: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14',
'many': 'v = 0 and i != 1 and i % 10 = 0..1 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 12..14' many: 'v = 0 and i != 1 and i % 10 = 0..1 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 12..14'
}, },
'pt': { pt: {
'one': 'i = 1 and v = 0 or i = 0 and t = 1' one: 'i = 1 and v = 0 or i = 0 and t = 1'
}, },
'pt_PT': { // jscs:disable requireCamelCaseOrUpperCaseIdentifiers
'one': 'n = 1 and v = 0' pt_PT: {
one: 'n = 1 and v = 0'
}, },
'ro': { // jscs:enable requireCamelCaseOrUpperCaseIdentifiers
'one': 'i = 1 and v = 0', ro: {
'few': 'v != 0 or n = 0 or n != 1 and n % 100 = 1..19' one: 'i = 1 and v = 0',
few: 'v != 0 or n = 0 or n != 1 and n % 100 = 1..19'
}, },
'ru': { ru: {
'one': 'v = 0 and i % 10 = 1 and i % 100 != 11', one: 'v = 0 and i % 10 = 1 and i % 100 != 11',
'many': 'v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 11..14' many: 'v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 11..14'
}, },
'se': { se: {
'one': 'n = 1', one: 'n = 1',
'two': 'n = 2' two: 'n = 2'
}, },
'sh': { sh: {
'one': 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11', one: 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11',
'few': 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14' few: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14'
}, },
'shi': { shi: {
'one': 'i = 0 or n = 1', one: 'i = 0 or n = 1',
'few': 'n = 2..10' few: 'n = 2..10'
}, },
'si': { si: {
'one': 'n = 0,1 or i = 0 and f = 1' one: 'n = 0,1 or i = 0 and f = 1'
}, },
'sk': { sk: {
'one': 'i = 1 and v = 0', one: 'i = 1 and v = 0',
'few': 'i = 2..4 and v = 0', few: 'i = 2..4 and v = 0',
'many': 'v != 0' many: 'v != 0'
}, },
'sl': { sl: {
'one': 'v = 0 and i % 100 = 1', one: 'v = 0 and i % 100 = 1',
'two': 'v = 0 and i % 100 = 2', two: 'v = 0 and i % 100 = 2',
'few': 'v = 0 and i % 100 = 3..4 or v != 0' few: 'v = 0 and i % 100 = 3..4 or v != 0'
}, },
'sma': { sma: {
'one': 'n = 1', one: 'n = 1',
'two': 'n = 2' two: 'n = 2'
}, },
'smi': { smi: {
'one': 'n = 1', one: 'n = 1',
'two': 'n = 2' two: 'n = 2'
}, },
'smj': { smj: {
'one': 'n = 1', one: 'n = 1',
'two': 'n = 2' two: 'n = 2'
}, },
'smn': { smn: {
'one': 'n = 1', one: 'n = 1',
'two': 'n = 2' two: 'n = 2'
}, },
'sms': { sms: {
'one': 'n = 1', one: 'n = 1',
'two': 'n = 2' two: 'n = 2'
}, },
'sr': { sr: {
'one': 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11', one: 'v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11',
'few': 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14' few: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14'
}, },
'ti': { ti: {
'one': 'n = 0..1' one: 'n = 0..1'
}, },
'tl': { tl: {
'one': 'i = 0..1 and v = 0' one: 'i = 0..1 and v = 0'
}, },
'tzm': { tzm: {
'one': 'n = 0..1 or n = 11..99' one: 'n = 0..1 or n = 11..99'
}, },
'uk': { uk: {
'one': 'v = 0 and i % 10 = 1 and i % 100 != 11', one: 'v = 0 and i % 10 = 1 and i % 100 != 11',
'few': 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14', few: 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14',
'many': 'v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 11..14' many: 'v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 11..14'
}, },
'wa': { wa: {
'one': 'n = 0..1' one: 'n = 0..1'
}, },
'zu': { zu: {
'one': 'i = 0 or n = 1' one: 'i = 0 or n = 1'
} }
}, },
/** /**
* Plural form transformations, needed for some languages. * Plural form transformations, needed for some languages.
* *
@@ -274,7 +275,7 @@
var pluralRules, var pluralRules,
pluralFormIndex, pluralFormIndex,
index, index,
explicitPluralPattern = new RegExp('\\d+=', 'i'), explicitPluralPattern = new RegExp( '\\d+=', 'i' ),
formCount, formCount,
form; form;
@@ -344,13 +345,13 @@
* @param {number} num Value to be converted * @param {number} num Value to be converted
* @param {boolean} integer Convert the return value to an integer * @param {boolean} integer Convert the return value to an integer
*/ */
'convertNumber': function ( num, integer ) { convertNumber: function ( num, integer ) {
var tmp, item, i, var tmp, item, i,
transformTable, numberString, convertedNumber; transformTable, numberString, convertedNumber;
// Set the target Transform table: // Set the target Transform table:
transformTable = this.digitTransformTable( $.i18n().locale ); transformTable = this.digitTransformTable( $.i18n().locale );
numberString = '' + num; numberString = String( num );
convertedNumber = ''; convertedNumber = '';
if ( !transformTable ) { if ( !transformTable ) {
@@ -411,7 +412,7 @@
* *
* @return string * @return string
*/ */
'gender': function ( gender, forms ) { gender: function ( gender, forms ) {
if ( !forms || forms.length === 0 ) { if ( !forms || forms.length === 0 ) {
return ''; return '';
} }
@@ -453,8 +454,8 @@
my: '၀၁၂၃၄၅၆၇၈၉', my: '၀၁၂၃၄၅၆၇၈၉',
ta: '௦௧௨௩௪௫௬௭௮௯', ta: '௦௧௨௩௪௫௬௭௮௯',
te: '౦౧౨౩౪౫౬౭౮౯', te: '౦౧౨౩౪౫౬౭౮౯',
th: '๐๑๒๓๔๕๖๗๘๙', //FIXME use iso 639 codes th: '๐๑๒๓๔๕๖๗๘๙', // FIXME use iso 639 codes
bo: '༠༡༢༣༤༥༦༧༨༩' //FIXME use iso 639 codes bo: '༠༡༢༣༤༥༦༧༨༩' // FIXME use iso 639 codes
}; };
if ( !tables[language] ) { if ( !tables[language] ) {
@@ -466,6 +467,6 @@
}; };
$.extend( $.i18n.languages, { $.extend( $.i18n.languages, {
'default': language default: language
} ); } );
}( jQuery ) ); }( jQuery ) );

View File

@@ -88,7 +88,7 @@
* @param locale * @param locale
* @param messages * @param messages
*/ */
set: function( locale, messages ) { set: function ( locale, messages ) {
if ( !this.messages[locale] ) { if ( !this.messages[locale] ) {
this.messages[locale] = messages; this.messages[locale] = messages;
} else { } else {
@@ -107,7 +107,6 @@
} }
}; };
function jsonMessageLoader( url ) { function jsonMessageLoader( url ) {
var deferred = $.Deferred(); var deferred = $.Deferred();

View File

@@ -53,7 +53,7 @@
pos = 0; pos = 0;
// Try parsers until one works, if none work return null // Try parsers until one works, if none work return null
function choice ( parserSyntax ) { function choice( parserSyntax ) {
return function () { return function () {
var i, result; var i, result;
@@ -72,7 +72,7 @@
// Try several parserSyntax-es in a row. // Try several parserSyntax-es in a row.
// All must succeed; otherwise, return null. // All must succeed; otherwise, return null.
// This is the only eager one. // This is the only eager one.
function sequence ( parserSyntax ) { function sequence( parserSyntax ) {
var i, res, var i, res,
originalPos = pos, originalPos = pos,
result = []; result = [];
@@ -94,7 +94,7 @@
// Run the same parser over and over until it fails. // Run the same parser over and over until it fails.
// Must succeed a minimum of n times; otherwise, return null. // Must succeed a minimum of n times; otherwise, return null.
function nOrMore ( n, p ) { function nOrMore( n, p ) {
return function () { return function () {
var originalPos = pos, var originalPos = pos,
result = [], result = [],
@@ -117,7 +117,7 @@
// Helpers -- just make parserSyntax out of simpler JS builtin types // Helpers -- just make parserSyntax out of simpler JS builtin types
function makeStringParser ( s ) { function makeStringParser( s ) {
var len = s.length; var len = s.length;
return function () { return function () {
@@ -132,7 +132,7 @@
}; };
} }
function makeRegexParser ( regex ) { function makeRegexParser( regex ) {
return function () { return function () {
var matches = message.substr( pos ).match( regex ); var matches = message.substr( pos ).match( regex );
@@ -163,7 +163,7 @@
// But using this as a combinator seems to cause problems // But using this as a combinator seems to cause problems
// when combined with nOrMore(). // when combined with nOrMore().
// May be some scoping issue. // May be some scoping issue.
function transform ( p, fn ) { function transform( p, fn ) {
return function () { return function () {
var result = p(); var result = p();
@@ -174,19 +174,19 @@
// Used to define "literals" within template parameters. The pipe // Used to define "literals" within template parameters. The pipe
// character is the parameter delimeter, so by default // character is the parameter delimeter, so by default
// it is not a literal in the parameter // it is not a literal in the parameter
function literalWithoutBar () { function literalWithoutBar() {
var result = nOrMore( 1, escapedOrLiteralWithoutBar )(); var result = nOrMore( 1, escapedOrLiteralWithoutBar )();
return result === null ? null : result.join( '' ); return result === null ? null : result.join( '' );
} }
function literal () { function literal() {
var result = nOrMore( 1, escapedOrRegularLiteral )(); var result = nOrMore( 1, escapedOrRegularLiteral )();
return result === null ? null : result.join( '' ); return result === null ? null : result.join( '' );
} }
function escapedLiteral () { function escapedLiteral() {
var result = sequence( [ backslash, anyCharacter ] ); var result = sequence( [ backslash, anyCharacter ] );
return result === null ? null : result[1]; return result === null ? null : result[1];
@@ -196,7 +196,7 @@
escapedOrLiteralWithoutBar = choice( [ escapedLiteral, regularLiteralWithoutBar ] ); escapedOrLiteralWithoutBar = choice( [ escapedLiteral, regularLiteralWithoutBar ] );
escapedOrRegularLiteral = choice( [ escapedLiteral, regularLiteral ] ); escapedOrRegularLiteral = choice( [ escapedLiteral, regularLiteral ] );
function replacement () { function replacement() {
var result = sequence( [ dollar, digits ] ); var result = sequence( [ dollar, digits ] );
if ( result === null ) { if ( result === null ) {
@@ -216,7 +216,7 @@
} }
); );
function templateParam () { function templateParam() {
var expr, var expr,
result = sequence( [ pipe, nOrMore( 0, paramExpression ) ] ); result = sequence( [ pipe, nOrMore( 0, paramExpression ) ] );
@@ -231,13 +231,13 @@
return expr.length > 1 ? [ 'CONCAT' ].concat( expr ) : expr[0]; return expr.length > 1 ? [ 'CONCAT' ].concat( expr ) : expr[0];
} }
function templateWithReplacement () { function templateWithReplacement() {
var result = sequence( [ templateName, colon, replacement ] ); var result = sequence( [ templateName, colon, replacement ] );
return result === null ? null : [ result[0], result[2] ]; return result === null ? null : [ result[0], result[2] ];
} }
function templateWithOutReplacement () { function templateWithOutReplacement() {
var result = sequence( [ templateName, colon, paramExpression ] ); var result = sequence( [ templateName, colon, paramExpression ] );
return result === null ? null : [ result[0], result[2] ]; return result === null ? null : [ result[0], result[2] ];
@@ -270,7 +270,7 @@
openTemplate = makeStringParser( '{{' ); openTemplate = makeStringParser( '{{' );
closeTemplate = makeStringParser( '}}' ); closeTemplate = makeStringParser( '}}' );
function template () { function template() {
var result = sequence( [ openTemplate, templateContents, closeTemplate ] ); var result = sequence( [ openTemplate, templateContents, closeTemplate ] );
return result === null ? null : result[1]; return result === null ? null : result[1];
@@ -279,7 +279,7 @@
expression = choice( [ template, replacement, literal ] ); expression = choice( [ template, replacement, literal ] );
paramExpression = choice( [ template, replacement, literalWithoutBar ] ); paramExpression = choice( [ template, replacement, literalWithoutBar ] );
function start () { function start() {
var result = nOrMore( 0, expression )(); var result = nOrMore( 0, expression )();
if ( result === null ) { if ( result === null ) {

View File

@@ -20,22 +20,20 @@
// Variable for ending // Variable for ending
ending = ''; ending = '';
// Checking if the $word is in plural form
if ( word.match( /тæ$/i ) ) { if ( word.match( /тæ$/i ) ) {
// Checking if the $word is in plural form
word = word.substring( 0, word.length - 1 ); word = word.substring( 0, word.length - 1 );
endAllative = 'æм'; endAllative = 'æм';
} } else if ( word.match( /[аæеёиоыэюя]$/i ) ) {
// Works if word is in singular form. // Works if word is in singular form.
// Checking if word ends on one of the vowels: е, ё, и, о, ы, э, ю, // Checking if word ends on one of the vowels: е, ё, и, о, ы, э, ю,
// я. // я.
else if ( word.match( /[аæеёиоыэюя]$/i ) ) {
jot = 'й'; jot = 'й';
} } else if ( word.match( /у$/i ) ) {
// Checking if word ends on 'у'. 'У' can be either consonant 'W' or // Checking if word ends on 'у'. 'У' can be either consonant 'W' or
// vowel 'U' in cyrillic Ossetic. // vowel 'U' in cyrillic Ossetic.
// Examples: {{grammar:genitive|аунеу}} = аунеуы, // Examples: {{grammar:genitive|аунеу}} = аунеуы,
// {{grammar:genitive|лæппу}} = лæппуйы. // {{grammar:genitive|лæппу}} = лæппуйы.
else if ( word.match( /у$/i ) ) {
if ( !word.substring( word.length - 2, word.length - 1 ) if ( !word.substring( word.length - 2, word.length - 1 )
.match( /[аæеёиоыэюя]$/i ) ) { .match( /[аæеёиоыэюя]$/i ) ) {
jot = 'й'; jot = 'й';

View File

@@ -0,0 +1,47 @@
{
"name": "jquery.i18n",
"version": "1.0.3",
"description": "jQuery based internationalization library",
"homepage": "https://github.com/wikimedia/jquery.i18n",
"keywords": [
"internationalization",
"localization",
"i18n",
"jquery",
"l10n"
],
"author": {
"name": "Santhosh Thottingal",
"email": "santhosh.thottingal@gmail.com"
},
"contributors": [
"Amir Aharoni <amir.aharoni@mail.huji.ac.il>",
"Niklas Laxström <nlaxstrom@wikimedia.org>",
"Neil Kandalgaonkar <neilk@brevity.org>",
"David Chan <david@troi.org>"
],
"devDependencies": {
"qunit": "0.7.6",
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-contrib-jshint": "0.11.2",
"grunt-contrib-connect": "0.10.1",
"grunt-contrib-qunit": "0.7.0",
"grunt-contrib-watch": "0.6.1",
"grunt-jscs": "1.8.0"
},
"repository": {
"type": "git",
"url": "git://github.com/wikimedia/jquery.i18n.git"
},
"bugs": {
"url" : "http://github.com/wikimedia/jquery.i18n/issues"
},
"engine": {
"node": ">=0.8.x"
},
"license": "(MIT OR GPL-2.0)",
"scripts": {
"test": "grunt test --verbose"
}
}