summaryrefslogtreecommitdiff
path: root/resources/mediawiki.language
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2013-08-12 09:28:15 +0200
committerPierre Schmitz <pierre@archlinux.de>2013-08-12 09:28:15 +0200
commit08aa4418c30cfc18ccc69a0f0f9cb9e17be6c196 (patch)
tree577a29fb579188d16003a209ce2a2e9c5b0aa2bd /resources/mediawiki.language
parentcacc939b34e315b85e2d72997811eb6677996cc1 (diff)
Update to MediaWiki 1.21.1
Diffstat (limited to 'resources/mediawiki.language')
-rw-r--r--resources/mediawiki.language/languages/bs.js6
-rw-r--r--resources/mediawiki.language/languages/dsb.js6
-rw-r--r--resources/mediawiki.language/languages/fi.js15
-rw-r--r--resources/mediawiki.language/languages/ga.js7
-rw-r--r--resources/mediawiki.language/languages/he.js14
-rw-r--r--resources/mediawiki.language/languages/hsb.js6
-rw-r--r--resources/mediawiki.language/languages/hu.js6
-rw-r--r--resources/mediawiki.language/languages/hy.js16
-rw-r--r--resources/mediawiki.language/languages/la.js6
-rw-r--r--resources/mediawiki.language/languages/os.js29
-rw-r--r--resources/mediawiki.language/languages/ru.js46
-rw-r--r--resources/mediawiki.language/languages/sl.js6
-rw-r--r--resources/mediawiki.language/languages/uk.js28
-rw-r--r--resources/mediawiki.language/mediawiki.cldr.js23
-rw-r--r--resources/mediawiki.language/mediawiki.language.init.js4
-rw-r--r--resources/mediawiki.language/mediawiki.language.js51
-rw-r--r--resources/mediawiki.language/mediawiki.language.numbers.js243
17 files changed, 376 insertions, 136 deletions
diff --git a/resources/mediawiki.language/languages/bs.js b/resources/mediawiki.language/languages/bs.js
index c0c77aaf..65eb5a6d 100644
--- a/resources/mediawiki.language/languages/bs.js
+++ b/resources/mediawiki.language/languages/bs.js
@@ -2,10 +2,10 @@
* Bosnian (bosanski) language functions
*/
-mediaWiki.language.convertGrammar = function( word, form ) {
- var grammarForms = mw.language.getData( 'bs', 'grammarForms' );
+mediaWiki.language.convertGrammar = function ( word, form ) {
+ var grammarForms = mediaWiki.language.getData( 'bs', 'grammarForms' );
if ( grammarForms && grammarForms[form] ) {
- return grammarForms[form][word] ;
+ return grammarForms[form][word];
}
switch ( form ) {
case 'instrumental': // instrumental
diff --git a/resources/mediawiki.language/languages/dsb.js b/resources/mediawiki.language/languages/dsb.js
index a42a8f7f..b2c9c081 100644
--- a/resources/mediawiki.language/languages/dsb.js
+++ b/resources/mediawiki.language/languages/dsb.js
@@ -2,10 +2,10 @@
* Lower Sorbian (Dolnoserbski) language functions
*/
-mediaWiki.language.convertGrammar = function( word, form ) {
- var grammarForms = mw.language.getData( 'dsb', 'grammarForms' );
+mediaWiki.language.convertGrammar = function ( word, form ) {
+ var grammarForms = mediaWiki.language.getData( 'dsb', 'grammarForms' );
if ( grammarForms && grammarForms[form] ) {
- return grammarForms[form][word] ;
+ return grammarForms[form][word];
}
switch ( form ) {
case 'instrumental': // instrumental
diff --git a/resources/mediawiki.language/languages/fi.js b/resources/mediawiki.language/languages/fi.js
index 374698dc..61c6c104 100644
--- a/resources/mediawiki.language/languages/fi.js
+++ b/resources/mediawiki.language/languages/fi.js
@@ -3,21 +3,24 @@
* @author Santhosh Thottingal
*/
-mediaWiki.language.convertGrammar = function( word, form ) {
- var grammarForms = mw.language.getData( 'fi', 'grammarForms' );
+mediaWiki.language.convertGrammar = function ( word, form ) {
+ var grammarForms, aou, origWord;
+
+ grammarForms = mediaWiki.language.getData( 'fi', 'grammarForms' );
if ( grammarForms && grammarForms[form] ) {
- return grammarForms[form][word] ;
+ return grammarForms[form][word];
}
// vowel harmony flag
- var aou = word.match( /[aou][^äöy]*$/i );
- var origWord = word;
+ aou = word.match( /[aou][^äöy]*$/i );
+ origWord = word;
if ( word.match( /wiki$/i ) ) {
aou = false;
}
//append i after final consonant
- if ( word.match( /[bcdfghjklmnpqrstvwxz]$/i ) )
+ if ( word.match( /[bcdfghjklmnpqrstvwxz]$/i ) ) {
word += 'i';
+ }
switch ( form ) {
case 'genitive':
diff --git a/resources/mediawiki.language/languages/ga.js b/resources/mediawiki.language/languages/ga.js
index a27b489d..c13e8321 100644
--- a/resources/mediawiki.language/languages/ga.js
+++ b/resources/mediawiki.language/languages/ga.js
@@ -2,10 +2,11 @@
* Irish (Gaeilge) language functions
*/
-mediaWiki.language.convertGrammar = function( word, form ) {
- var grammarForms = mw.language.getData( 'ga', 'grammarForms' );
+mediaWiki.language.convertGrammar = function ( word, form ) {
+ /*jshint onecase:true */
+ var grammarForms = mediaWiki.language.getData( 'ga', 'grammarForms' );
if ( grammarForms && grammarForms[form] ) {
- return grammarForms[form][word] ;
+ return grammarForms[form][word];
}
switch ( form ) {
case 'ainmlae':
diff --git a/resources/mediawiki.language/languages/he.js b/resources/mediawiki.language/languages/he.js
index d35f77ed..13d457b2 100644
--- a/resources/mediawiki.language/languages/he.js
+++ b/resources/mediawiki.language/languages/he.js
@@ -3,26 +3,26 @@
*/
mediaWiki.language.convertGrammar = function( word, form ) {
- var grammarForms = mw.language.getData( 'he', 'grammarForms' );
+ var grammarForms = mediaWiki.language.getData( 'he', 'grammarForms' );
if ( grammarForms && grammarForms[form] ) {
- return grammarForms[form][word] ;
+ return grammarForms[form][word];
}
switch ( form ) {
case 'prefixed':
case 'תחילית': // the same word in Hebrew
// Duplicate prefixed "Waw", but only if it's not already double
- if ( word.substr( 0, 1 ) === "ו" && word.substr( 0, 2 ) !== "וו" ) {
- word = "ו" + word;
+ if ( word.substr( 0, 1 ) === 'ו' && word.substr( 0, 2 ) !== 'וו' ) {
+ word = 'ו' + word;
}
// Remove the "He" if prefixed
- if ( word.substr( 0, 1 ) === "ה" ) {
+ if ( word.substr( 0, 1 ) === 'ה' ) {
word = word.substr( 1, word.length );
}
// Add a hyphen (maqaf) before numbers and non-Hebrew letters
- if ( word.substr( 0, 1 ) < "א" || word.substr( 0, 1 ) > "ת" ) {
- word = "־" + word;
+ if ( word.substr( 0, 1 ) < 'א' || word.substr( 0, 1 ) > 'ת' ) {
+ word = '־' + word;
}
}
return word;
diff --git a/resources/mediawiki.language/languages/hsb.js b/resources/mediawiki.language/languages/hsb.js
index 211d67b5..77dca75e 100644
--- a/resources/mediawiki.language/languages/hsb.js
+++ b/resources/mediawiki.language/languages/hsb.js
@@ -2,10 +2,10 @@
* Upper Sorbian (Hornjoserbsce) language functions
*/
-mediaWiki.language.convertGrammar = function( word, form ) {
- var grammarForms =mw.language.getData( 'hsb', 'grammarForms' );
+mediaWiki.language.convertGrammar = function ( word, form ) {
+ var grammarForms = mediaWiki.language.getData( 'hsb', 'grammarForms' );
if ( grammarForms && grammarForms[form] ) {
- return grammarForms[form][word] ;
+ return grammarForms[form][word];
}
switch ( form ) {
case 'instrumental': // instrumental
diff --git a/resources/mediawiki.language/languages/hu.js b/resources/mediawiki.language/languages/hu.js
index eb3f1f3a..23b0c125 100644
--- a/resources/mediawiki.language/languages/hu.js
+++ b/resources/mediawiki.language/languages/hu.js
@@ -3,10 +3,10 @@
* @author Santhosh Thottingal
*/
-mediaWiki.language.convertGrammar = function( word, form ) {
- var grammarForms = mw.language.getData( 'hu', 'grammarForms' );
+mediaWiki.language.convertGrammar = function ( word, form ) {
+ var grammarForms = mediaWiki.language.getData( 'hu', 'grammarForms' );
if ( grammarForms && grammarForms[form] ) {
- return grammarForms[form][word] ;
+ return grammarForms[form][word];
}
switch ( form ) {
case 'rol':
diff --git a/resources/mediawiki.language/languages/hy.js b/resources/mediawiki.language/languages/hy.js
index 215e7504..65081bdd 100644
--- a/resources/mediawiki.language/languages/hy.js
+++ b/resources/mediawiki.language/languages/hy.js
@@ -2,10 +2,11 @@
* Armenian (Հայերեն) language functions
*/
-mediaWiki.language.convertGrammar = function( word, form ) {
- var grammarForms = mw.language.getData( 'hy', 'grammarForms' );
+mediaWiki.language.convertGrammar = function ( word, form ) {
+ /*jshint onecase:true */
+ var grammarForms = mediaWiki.language.getData( 'hy', 'grammarForms' );
if ( grammarForms && grammarForms[form] ) {
- return grammarForms[form][word] ;
+ return grammarForms[form][word];
}
// These rules are not perfect, but they are currently only used for site names so it doesn't
@@ -13,14 +14,15 @@ mediaWiki.language.convertGrammar = function( word, form ) {
switch ( form ) {
case 'genitive': // սեռական հոլով
- if ( word.substr( -1 ) === 'ա' )
+ if ( word.substr( -1 ) === 'ա' ) {
word = word.substr( 0, word.length -1 ) + 'այի';
- else if ( word.substr( -1 ) === 'ո' )
+ } else if ( word.substr( -1 ) === 'ո' ) {
word = word.substr( 0, word.length - 1 ) + 'ոյի';
- else if ( word.substr( -4 ) === 'գիրք' )
+ } else if ( word.substr( -4 ) === 'գիրք' ) {
word = word.substr( 0, word.length - 4 ) + 'գրքի';
- else
+ } else {
word = word + 'ի';
+ }
break;
}
return word;
diff --git a/resources/mediawiki.language/languages/la.js b/resources/mediawiki.language/languages/la.js
index 313bb1c2..27110241 100644
--- a/resources/mediawiki.language/languages/la.js
+++ b/resources/mediawiki.language/languages/la.js
@@ -3,10 +3,10 @@
* @author Santhosh Thottingal
*/
-mediaWiki.language.convertGrammar = function( word, form ) {
- var grammarForms = mw.language.getData( 'la', 'grammarForms' );
+mediaWiki.language.convertGrammar = function ( word, form ) {
+ var grammarForms = mediaWiki.language.getData( 'la', 'grammarForms' );
if ( grammarForms && grammarForms[form] ) {
- return grammarForms[form][word] ;
+ return grammarForms[form][word];
}
switch ( form ) {
case 'genitive':
diff --git a/resources/mediawiki.language/languages/os.js b/resources/mediawiki.language/languages/os.js
index 431e38c8..682b3903 100644
--- a/resources/mediawiki.language/languages/os.js
+++ b/resources/mediawiki.language/languages/os.js
@@ -4,23 +4,24 @@
*/
-mediaWiki.language.convertGrammar = function( word, form ) {
- var grammarForms = mw.language.getData( 'os', 'grammarForms' );
+mediaWiki.language.convertGrammar = function ( word, form ) {
+ var grammarForms = mediaWiki.language.getData( 'os', 'grammarForms' ),
+ // Ending for allative case
+ endAllative = 'мæ',
+ // Variable for 'j' beetwen vowels
+ jot = '',
+ // Variable for "-" for not Ossetic words
+ hyphen = '',
+ // Variable for ending
+ ending = '';
+
if ( grammarForms && grammarForms[form] ) {
- return grammarForms[form][word] ;
+ return grammarForms[form][word];
}
- // Ending for allative case
- var end_allative = 'мæ';
- // Variable for 'j' beetwen vowels
- var jot = '';
- // Variable for "-" for not Ossetic words
- var hyphen = '';
- // Variable for ending
- var ending = '';
// Checking if the $word is in plural form
if ( word.match( /тæ$/i ) ) {
word = word.substring( 0, word.length - 1 );
- end_allative = 'æм';
+ endAllative = 'æм';
}
// Works if word is in singular form.
// Checking if word ends on one of the vowels: е, ё, и, о, ы, э, ю, я.
@@ -45,10 +46,10 @@ mediaWiki.language.convertGrammar = function( word, form ) {
ending = hyphen + jot + 'æн';
break;
case 'allative':
- ending = hyphen + end_allative;
+ ending = hyphen + endAllative;
break;
case 'ablative':
- if ( jot == 'й' ) {
+ if ( jot === 'й' ) {
ending = hyphen + jot + 'æ';
}
else {
diff --git a/resources/mediawiki.language/languages/ru.js b/resources/mediawiki.language/languages/ru.js
index cfdbfc3b..1bc06326 100644
--- a/resources/mediawiki.language/languages/ru.js
+++ b/resources/mediawiki.language/languages/ru.js
@@ -2,27 +2,51 @@
* Russian (Русский) language functions
*/
-mediaWiki.language.convertGrammar = function( word, form ) {
- var grammarForms = mw.language.getData( 'ru', 'grammarForms' );
+// These tests were originally made for names of Wikimedia
+// websites, so they don't currently cover all the possible
+// cases.
+
+mediaWiki.language.convertGrammar = function ( word, form ) {
+ 'use strict';
+
+ var grammarForms = mediaWiki.language.getData( 'ru', 'grammarForms' );
if ( grammarForms && grammarForms[form] ) {
- return grammarForms[form][word] ;
+ return grammarForms[form][word];
}
switch ( form ) {
case 'genitive': // родительный падеж
- if ( ( word.substr( word.length - 4 ) == 'вики' ) || ( word.substr( word.length - 4 ) == 'Вики' ) ) {
- }
- else if ( word.substr( word.length - 1 ) == 'ь' )
+ if ( word.substr( word.length - 1 ) === 'ь' ) {
word = word.substr(0, word.length - 1 ) + 'я';
- else if ( word.substr( word.length - 2 ) == 'ия' )
+ } else if ( word.substr( word.length - 2 ) === 'ия' ) {
word = word.substr(0, word.length - 2 ) + 'ии';
- else if ( word.substr( word.length - 2 ) == 'ка' )
+ } else if ( word.substr( word.length - 2 ) === 'ка' ) {
word = word.substr(0, word.length - 2 ) + 'ки';
- else if ( word.substr( word.length - 2 ) == 'ти' )
+ } else if ( word.substr( word.length - 2 ) === 'ти' ) {
word = word.substr(0, word.length - 2 ) + 'тей';
- else if ( word.substr( word.length - 2 ) == 'ды' )
+ } else if ( word.substr( word.length - 2 ) === 'ды' ) {
word = word.substr(0, word.length - 2 ) + 'дов';
- else if ( word.substr( word.length - 3 ) == 'ник' )
+ } else if ( word.substr( word.length - 3 ) === 'ные' ) {
+ word = word.substr(0, word.length - 3 ) + 'ных';
+ } else if ( word.substr( word.length - 3 ) === 'ник' ) {
word = word.substr(0, word.length - 3 ) + 'ника';
+ }
+ break;
+ case 'prepositional': // предложный падеж
+ if ( word.substr( word.length - 1 ) === 'ь' ) {
+ word = word.substr(0, word.length - 1 ) + 'е';
+ } else if ( word.substr( word.length - 2 ) === 'ия' ) {
+ word = word.substr(0, word.length - 2 ) + 'ии';
+ } else if ( word.substr( word.length - 2 ) === 'ка' ) {
+ word = word.substr(0, word.length - 2 ) + 'ке';
+ } else if ( word.substr( word.length - 2 ) === 'ти' ) {
+ word = word.substr(0, word.length - 2 ) + 'тях';
+ } else if ( word.substr( word.length - 2 ) === 'ды' ) {
+ word = word.substr(0, word.length - 2 ) + 'дах';
+ } else if ( word.substr( word.length - 3 ) === 'ные' ) {
+ word = word.substr(0, word.length - 3 ) + 'ных';
+ } else if ( word.substr( word.length - 3 ) === 'ник' ) {
+ word = word.substr(0, word.length - 3 ) + 'нике';
+ }
break;
}
return word;
diff --git a/resources/mediawiki.language/languages/sl.js b/resources/mediawiki.language/languages/sl.js
index acd00bfd..fb335b6a 100644
--- a/resources/mediawiki.language/languages/sl.js
+++ b/resources/mediawiki.language/languages/sl.js
@@ -2,10 +2,10 @@
* Slovenian (Slovenščina) language functions
*/
-mediaWiki.language.convertGrammar = function( word, form ) {
- var grammarForms = mw.language.getData( 'sl', 'grammarForms' );
+mediaWiki.language.convertGrammar = function ( word, form ) {
+ var grammarForms = mediaWiki.language.getData( 'sl', 'grammarForms' );
if ( grammarForms && grammarForms[form] ) {
- return grammarForms[form][word] ;
+ return grammarForms[form][word];
}
switch ( form ) {
case 'mestnik': // locative
diff --git a/resources/mediawiki.language/languages/uk.js b/resources/mediawiki.language/languages/uk.js
index ee110b06..5e56b66f 100644
--- a/resources/mediawiki.language/languages/uk.js
+++ b/resources/mediawiki.language/languages/uk.js
@@ -2,33 +2,35 @@
* Ukrainian (Українська) language functions
*/
-mediaWiki.language.convertGrammar = function( word, form ) {
- var grammarForms = mw.language.getData( 'uk', 'grammarForms' );
+mediaWiki.language.convertGrammar = function ( word, form ) {
+ /*jshint noempty:false */
+ var grammarForms = mediaWiki.language.getData( 'uk', 'grammarForms' );
if ( grammarForms && grammarForms[form] ) {
- return grammarForms[form][word] ;
+ return grammarForms[form][word];
}
switch ( form ) {
case 'genitive': // родовий відмінок
- if ( ( word.substr( word.length - 4 ) == 'вікі' ) || ( word.substr( word.length - 4 ) == 'Вікі' ) ) {
- }
- else if ( word.substr( word.length - 1 ) == 'ь' )
+ if ( ( word.substr( word.length - 4 ) === 'вікі' ) || ( word.substr( word.length - 4 ) === 'Вікі' ) ) {
+ } else if ( word.substr( word.length - 1 ) === 'ь' ) {
word = word.substr(0, word.length - 1 ) + 'я';
- else if ( word.substr( word.length - 2 ) == 'ія' )
+ } else if ( word.substr( word.length - 2 ) === 'ія' ) {
word = word.substr(0, word.length - 2 ) + 'ії';
- else if ( word.substr( word.length - 2 ) == 'ка' )
+ } else if ( word.substr( word.length - 2 ) === 'ка' ) {
word = word.substr(0, word.length - 2 ) + 'ки';
- else if ( word.substr( word.length - 2 ) == 'ти' )
+ } else if ( word.substr( word.length - 2 ) === 'ти' ) {
word = word.substr(0, word.length - 2 ) + 'тей';
- else if ( word.substr( word.length - 2 ) == 'ды' )
+ } else if ( word.substr( word.length - 2 ) === 'ды' ) {
word = word.substr(0, word.length - 2 ) + 'дов';
- else if ( word.substr( word.length - 3 ) == 'ник' )
+ } else if ( word.substr( word.length - 3 ) === 'ник' ) {
word = word.substr(0, word.length - 3 ) + 'ника';
+ }
break;
case 'accusative': // знахідний відмінок
- if ( ( word.substr( word.length - 4 ) == 'вікі' ) || ( word.substr( word.length - 4 ) == 'Вікі' ) ) {
+ if ( ( word.substr( word.length - 4 ) === 'вікі' ) || ( word.substr( word.length - 4 ) === 'Вікі' ) ) {
}
- else if ( word.substr( word.length - 2 ) == 'ія' )
+ else if ( word.substr( word.length - 2 ) === 'ія' ) {
word = word.substr(0, word.length - 2 ) + 'ію';
+ }
break;
}
return word;
diff --git a/resources/mediawiki.language/mediawiki.cldr.js b/resources/mediawiki.language/mediawiki.cldr.js
index 6660eca4..c3023cd5 100644
--- a/resources/mediawiki.language/mediawiki.cldr.js
+++ b/resources/mediawiki.language/mediawiki.cldr.js
@@ -1,8 +1,8 @@
/**
- * CLDR related utility methods
+ * CLDR related utility methods.
*/
-( function( mw ) {
- "use strict";
+( function ( mw ) {
+ 'use strict';
var cldr = {
/**
@@ -10,19 +10,20 @@
* In case none of the rules passed, we return pluralRules.length
* That means it is the "other" form.
* @param number
- * @param pluralRules
- * @return plural form index
+ * @param {Array} pluralRules
+ * @return {number} plural form index
*/
- getPluralForm: function( number, pluralRules ) {
- var pluralFormIndex = 0;
- for ( pluralFormIndex = 0; pluralFormIndex < pluralRules.length; pluralFormIndex++ ) {
- if ( mw.libs.pluralRuleParser( pluralRules[pluralFormIndex], number ) ) {
+ getPluralForm: function ( number, pluralRules ) {
+ var i;
+ for ( i = 0; i < pluralRules.length; i++ ) {
+ if ( mw.libs.pluralRuleParser( pluralRules[i], number ) ) {
break;
}
}
- return pluralFormIndex;
+ return i;
}
};
mw.cldr = cldr;
-} )( mediaWiki );
+
+}( mediaWiki ) );
diff --git a/resources/mediawiki.language/mediawiki.language.init.js b/resources/mediawiki.language/mediawiki.language.init.js
index 30307a37..937b89bb 100644
--- a/resources/mediawiki.language/mediawiki.language.init.js
+++ b/resources/mediawiki.language/mediawiki.language.init.js
@@ -2,7 +2,7 @@
* Base language object with methods for storing and getting
* language data.
*/
-( function ( mw, $ ) {
+( function ( mw ) {
var language = {
/**
@@ -58,4 +58,4 @@
mw.language = language;
-}( mediaWiki, jQuery ) );
+}( mediaWiki ) );
diff --git a/resources/mediawiki.language/mediawiki.language.js b/resources/mediawiki.language/mediawiki.language.js
index 935d4ff6..7f729bdc 100644
--- a/resources/mediawiki.language/mediawiki.language.js
+++ b/resources/mediawiki.language/mediawiki.language.js
@@ -43,12 +43,14 @@ var language = {
* @param forms array List of plural forms
* @return string Correct form for quantifier in this language
*/
- convertPlural: function( count, forms ) {
- var pluralFormIndex = 0;
+ convertPlural: function ( count, forms ) {
+ var pluralRules,
+ pluralFormIndex = 0;
+
if ( !forms || forms.length === 0 ) {
return '';
}
- var pluralRules = mw.language.getData( mw.config.get( 'wgUserLanguage' ), 'pluralRules' );
+ pluralRules = mw.language.getData( mw.config.get( 'wgUserLanguage' ), 'pluralRules' );
if ( !pluralRules ) {
// default fallback.
return ( count === 1 ) ? forms[0] : forms[1];
@@ -73,43 +75,6 @@ var language = {
},
/**
- * Converts a number using digitTransformTable.
- *
- * @param {num} number Value to be converted
- * @param {boolean} integer Convert the return value to an integer
- */
- convertNumber: function( num, integer ) {
- var i, tmp, transformTable;
-
- if ( !mw.language.digitTransformTable ) {
- return num;
- }
- // Set the target Transform table:
- transformTable = mw.language.digitTransformTable;
- // Check if the "restore" to Latin number flag is set:
- if ( integer ) {
- if ( parseInt( num, 10 ) === num ) {
- return num;
- }
- tmp = [];
- for ( i in transformTable ) {
- tmp[ transformTable[ i ] ] = i;
- }
- transformTable = tmp;
- }
- var numberString = '' + num;
- var convertedNumber = '';
- for ( i = 0; i < numberString.length; i++ ) {
- if ( transformTable[ numberString[i] ] ) {
- convertedNumber += transformTable[numberString[i]];
- } else {
- convertedNumber += numberString[i];
- }
- }
- return integer ? parseInt( convertedNumber, 10 ) : convertedNumber;
- },
-
- /**
* Provides an alternative text depending on specified gender.
* Usage {{gender:[gender|user object]|masculine|feminine|neutral}}.
* If second or third parameter are not specified, masculine is used.
@@ -121,7 +86,7 @@ var language = {
*
* @return string
*/
- gender: function( gender, forms ) {
+ gender: function ( gender, forms ) {
if ( !forms || forms.length === 0 ) {
return '';
}
@@ -151,10 +116,8 @@ var language = {
return grammarForms[form][word] || word;
}
return word;
- },
+ }
- // Digit Transform Table, populated by language classes where applicable
- digitTransformTable: mw.language.getData( mw.config.get( 'wgUserLanguage' ), 'digitTransformTable' )
};
$.extend( mw.language, language );
diff --git a/resources/mediawiki.language/mediawiki.language.numbers.js b/resources/mediawiki.language/mediawiki.language.numbers.js
new file mode 100644
index 00000000..fada6ce1
--- /dev/null
+++ b/resources/mediawiki.language/mediawiki.language.numbers.js
@@ -0,0 +1,243 @@
+/*
+ * Number related utilities for mediawiki.language
+ */
+( function ( mw, $ ) {
+
+ /**
+ * Pad a string to guarantee that it is at least `size` length by
+ * filling with the character `ch` at either the start or end of the
+ * string. Pads at the start, by default.
+ * example:
+ * Fill the string to length 10 with '+' characters on the right. Yields 'blah++++++'.
+ * pad('blah', 10, '+', true);
+ *
+ * @param {string} text The string to pad
+ * @param {Number} size To provide padding
+ * @param {string} ch Character to pad, defaults to '0'
+ * @param {Boolean} end Adds padding at the end if true, otherwise pads at start
+ * @return {string}
+ */
+ function pad ( text, size, ch, end ) {
+ if ( !ch ) {
+ ch = '0';
+ }
+
+ var out = String( text ),
+ padStr = replicate( ch, Math.ceil( ( size - out.length ) / ch.length ) );
+
+ return end ? out + padStr : padStr + out;
+ }
+
+ /**
+ * Efficiently replicate a string n times.
+ *
+ * @param {string} str The string to replicate
+ * @param {Number} num Number of times to replicate the string
+ * @return {string}
+ */
+ function replicate ( str, num ) {
+ if ( num <= 0 || !str ) {
+ return '';
+ }
+
+ var buf = [];
+ while (num) {
+ buf.push( str );
+ str += str;
+ }
+ return buf.join( '' );
+ }
+
+ /**
+ * Apply numeric pattern to absolute value using options. Gives no
+ * consideration to local customs.
+ *
+ * Adapted from dojo/number library with thanks
+ * http://dojotoolkit.org/reference-guide/1.8/dojo/number.html
+ *
+ * @param {Number} value the number to be formatted, ignores sign
+ * @param {string} pattern the number portion of a pattern (e.g. `#,##0.00`)
+ * @param {string} options.decimalThe decimal separator
+ * @param {string} options.group The group separator
+ *
+ * @return {string}
+ */
+ function commafyNumber( value, pattern, options ) {
+ options = options || {
+ group: ',',
+ decimal: '.'
+ };
+
+ if ( isNaN( value) ) {
+ return value;
+ }
+
+ var padLength,
+ patternDigits,
+ index,
+ whole,
+ off,
+ remainder,
+ patternParts = pattern.split( '.' ),
+ maxPlaces = ( patternParts[1] || [] ).length,
+ valueParts = String( Math.abs( value ) ).split( '.' ),
+ fractional = valueParts[1] || '',
+ groupSize = 0,
+ groupSize2 = 0,
+ pieces = [];
+
+ if ( patternParts[1] ) {
+ // Pad fractional with trailing zeros
+ padLength = ( patternParts[1] && patternParts[1].lastIndexOf( '0' ) + 1 );
+
+ if ( padLength > fractional.length ) {
+ valueParts[1] = pad( fractional, padLength, '0', true );
+ }
+
+ // Truncate fractional
+ if ( maxPlaces < fractional.length ) {
+ valueParts[1] = fractional.substr( 0, maxPlaces );
+ }
+ } else {
+ if ( valueParts[1] ) {
+ valueParts.pop();
+ }
+ }
+
+ // Pad whole with leading zeros
+ patternDigits = patternParts[0].replace( ',', '' );
+
+ padLength = patternDigits.indexOf( '0' );
+
+ if ( padLength !== -1 ) {
+ padLength = patternDigits.length - padLength;
+
+ if ( padLength > valueParts[0].length ) {
+ valueParts[0] = pad( valueParts[0], padLength );
+ }
+
+ // Truncate whole
+ if ( patternDigits.indexOf( '#' ) === -1 ) {
+ valueParts[0] = valueParts[0].substr( valueParts[0].length - padLength );
+ }
+ }
+
+ // Add group separators
+ index = patternParts[0].lastIndexOf( ',' );
+
+ if ( index !== -1 ) {
+ groupSize = patternParts[0].length - index - 1;
+ remainder = patternParts[0].substr( 0, index );
+ index = remainder.lastIndexOf( ',' );
+ if ( index !== -1 ) {
+ groupSize2 = remainder.length - index - 1;
+ }
+ }
+
+ for ( whole = valueParts[0]; whole; ) {
+ off = whole.length - groupSize;
+
+ pieces.push( ( off > 0 ) ? whole.substr( off ) : whole );
+ whole = ( off > 0 ) ? whole.slice( 0, off ) : '';
+
+ if ( groupSize2 ) {
+ groupSize = groupSize2;
+ }
+ }
+ valueParts[0] = pieces.reverse().join( options.group );
+
+ return valueParts.join( options.decimal );
+ }
+
+ $.extend( mw.language, {
+
+ /**
+ * Converts a number using digitTransformTable.
+ *
+ * @param {Number} num Value to be converted
+ * @param {boolean} integer Convert the return value to an integer
+ * @return {Number|string} Formatted number
+ */
+ convertNumber: function ( num, integer ) {
+ var i, tmp, transformTable, numberString, convertedNumber, pattern;
+
+ pattern = mw.language.getData( mw.config.get( 'wgUserLanguage' ),
+ 'digitGroupingPattern' ) || '#,##0.###';
+
+ // Set the target transform table:
+ transformTable = mw.language.getDigitTransformTable();
+
+ if ( !transformTable ) {
+ return num;
+ }
+
+ // Check if the 'restore' to Latin number flag is set:
+ if ( integer ) {
+ if ( parseInt( num, 10 ) === num ) {
+ return num;
+ }
+ tmp = [];
+ for ( i in transformTable ) {
+ tmp[ transformTable[ i ] ] = i;
+ }
+ transformTable = tmp;
+ numberString = num + '';
+ } else {
+ numberString = mw.language.commafy( num, pattern );
+ }
+
+ convertedNumber = '';
+ for ( i = 0; i < numberString.length; i++ ) {
+ if ( transformTable[ numberString[i] ] ) {
+ convertedNumber += transformTable[numberString[i]];
+ } else {
+ convertedNumber += numberString[i];
+ }
+ }
+ return integer ? parseInt( convertedNumber, 10 ) : convertedNumber;
+ },
+
+ getDigitTransformTable: function () {
+ return mw.language.getData( mw.config.get( 'wgUserLanguage' ),
+ 'digitTransformTable' ) || [];
+ },
+
+ getSeparatorTransformTable: function () {
+ return mw.language.getData( mw.config.get( 'wgUserLanguage' ),
+ 'separatorTransformTable' ) || [];
+ },
+
+ /**
+ * Apply pattern to format value as a string using as per
+ * unicode.org TR35 - http://www.unicode.org/reports/tr35/#Number_Format_Patterns.
+ *
+ * @param {Number} value
+ * @param {string} pattern Pattern string as described by Unicode TR35
+ * @throws Error
+ * @returns {String}
+ */
+ commafy: function ( value, pattern ) {
+ var numberPattern,
+ transformTable = mw.language.getSeparatorTransformTable(),
+ group = transformTable[','] || ',',
+ numberPatternRE = /[#0,]*[#0](?:\.0*#*)?/, // not precise, but good enough
+ decimal = transformTable['.'] || '.',
+ patternList = pattern.split( ';' ),
+ positivePattern = patternList[0];
+
+ pattern = patternList[ ( value < 0 ) ? 1 : 0] || ( '-' + positivePattern );
+ numberPattern = positivePattern.match( numberPatternRE );
+
+ if ( !numberPattern ) {
+ throw new Error( 'unable to find a number expression in pattern: ' + pattern );
+ }
+
+ return pattern.replace( numberPatternRE, commafyNumber( value, numberPattern[0], {
+ decimal: decimal,
+ group: group
+ } ) );
+ }
+
+ } );
+
+}( mediaWiki, jQuery ) );