r111734 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111733‎ | r111734 | r111735 >
Date:09:33, 17 February 2012
Author:santhosh
Status:ok (Comments)
Tags:i18nreview 
Comment:
Do not set the grammarForms from test, a mistake in r111727
in [lang].js directly use the language code instead of getting from mw.config.
convertGrammar for hy and updates for bs, he, hsb
Modified paths:
  • /branches/jsgrammar/resources/mediawiki.language/languages/bs.js (modified) (history)
  • /branches/jsgrammar/resources/mediawiki.language/languages/he.js (modified) (history)
  • /branches/jsgrammar/resources/mediawiki.language/languages/hsb.js (modified) (history)
  • /branches/jsgrammar/resources/mediawiki.language/languages/hy.js (modified) (history)
  • /branches/jsgrammar/tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js (modified) (history)

Diff [purge]

Index: branches/jsgrammar/tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js
@@ -17,18 +17,6 @@
1818 test( "Grammar Test", function() {
1919 expect( opt.test.length);
2020 for ( var i= 0 ; i < opt.test.length; i++ ) {
21 - var langData = mw.language.data;
22 - var grammarForms = [];
23 - if ( langData[opt.language] === undefined ) {
24 - langData[opt.language] = new mw.Map();
25 - }else{
26 - grammarForms = langData[opt.language].get( 'grammarForms' );
27 - }
28 - if ( grammarForms[ opt.test[i].grammarForm ] === undefined ) {
29 - grammarForms[ opt.test[i].grammarForm ] = [] ;
30 - }
31 - grammarForms[opt.test[i].grammarForm][opt.test[i].word] = opt.test[i].expected ;
32 - langData[opt.language].set( 'grammarForms', grammarForms );
3321 equal( mw.language.convertGrammar( opt.test[i].word, opt.test[i].grammarForm ), opt.test[i].expected, opt.test[i].description );
3422 }
3523 } );
@@ -36,13 +24,6 @@
3725 }
3826
3927 mw.language.grammartest({
40 - language: 'en',
41 - test: [
42 - { word: 'pen', grammarForm: 'genitive', expected: 'pen\'s', description: 'Grammar test for English' }
43 - ]
44 -});
45 -
46 -mw.language.grammartest({
4728 language: 'bs',
4829 test: [
4930 { word: 'word', grammarForm: 'instrumental', expected: 's word', description: 'Grammar test for Bosnian, instrumental case' },
@@ -67,3 +48,13 @@
6849 { word: 'word', grammarForm: 'lokatiw', expected: 'wo word', description: 'Grammar test for Upper Sorbian, lokatiw case' }
6950 ]
7051 });
 52+
 53+mw.language.grammartest({
 54+ language: 'hy',
 55+ test: [
 56+ { word: 'Մաունա', grammarForm: 'genitive', expected: 'Մաունայի', description: 'Grammar test for Armenian, genitive case' },
 57+ { word: 'հետո', grammarForm: 'genitive', expected: 'հետոյի', description: 'Grammar test for Armenian, genitive case' },
 58+ { word: 'գիրք', grammarForm: 'genitive', expected: 'գրքի', description: 'Grammar test for Armenian, genitive case' },
 59+ { word: 'ժամանակի', grammarForm: 'genitive', expected: 'ժամանակիի', description: 'Grammar test for Armenian, genitive case' }
 60+ ]
 61+});
Index: branches/jsgrammar/resources/mediawiki.language/languages/bs.js
@@ -20,7 +20,7 @@
2121 };
2222
2323 mediaWiki.language.convertGrammar = function( word, form ) {
24 - var grammarForms = mw.language.data[ mw.config.get( 'wgContentLanguage' )].get( 'grammarForms' );
 24+ var grammarForms = mw.language.data[ 'bs' ].get( 'grammarForms' );
2525 if ( grammarForms && grammarForms[form] ) {
2626 return grammarForms[form][word] ;
2727 }
Index: branches/jsgrammar/resources/mediawiki.language/languages/hsb.js
@@ -19,7 +19,7 @@
2020
2121
2222 mediaWiki.language.convertGrammar = function( word, form ) {
23 - var grammarForms = mw.language.data[ mw.config.get( 'wgContentLanguage' )].get( 'grammarForms' );
 23+ var grammarForms = mw.language.data[ 'hsb' ].get( 'grammarForms' );
2424 if ( grammarForms && grammarForms[form] ) {
2525 return grammarForms[form][word] ;
2626 }
@@ -28,7 +28,7 @@
2929 word = 'z ' + word;
3030 break;
3131 case 'lokatiw': // lokatiw
32 - $word = 'wo ' + word;
 32+ word = 'wo ' + word;
3333 break;
3434 }
3535 return word;
Index: branches/jsgrammar/resources/mediawiki.language/languages/hy.js
@@ -6,3 +6,27 @@
77 forms = mediaWiki.language.preConvertPlural( forms, 2 );
88 return ( Math.abs( count ) <= 1 ) ? forms[0] : forms[1];
99 };
 10+
 11+mediaWiki.language.convertGrammar = function( word, form ) {
 12+ var grammarForms = mw.language.data[ 'hy' ].get( 'grammarForms' );
 13+ if ( grammarForms && grammarForms[form] ) {
 14+ return grammarForms[form][word] ;
 15+ }
 16+
 17+ // These rules are not perfect, but they are currently only used for site names so it doesn't
 18+ // matter if they are wrong sometimes. Just add a special case for your site name if necessary.
 19+
 20+ switch ( form ) {
 21+ case 'genitive': // սեռական հոլով
 22+ if ( word.substr( -1 ) === 'ա' )
 23+ word = word.substr( 0, word.length -1 ) + 'այի';
 24+ else if ( word.substr( -1 ) === 'ո' )
 25+ word = word.substr( 0, word.length - 1 ) + 'ոյի';
 26+ else if ( word.substr( -4 ) === 'գիրք' )
 27+ word = word.substr( 0, word.length - 4 ) + 'գրքի';
 28+ else
 29+ word = word + 'ի';
 30+ break;
 31+ }
 32+ return word;
 33+};
Index: branches/jsgrammar/resources/mediawiki.language/languages/he.js
@@ -14,8 +14,8 @@
1515 };
1616
1717 mediaWiki.language.convertGrammar = function( word, form ) {
18 - var grammarForms = mw.config.get( 'wgGrammarForms' );
19 - if ( grammarForms && grammarForms['he'] && grammarForms['he'][form] ) {
 18+ var grammarForms = mw.language.data[ 'he' ].get( 'grammarForms' );
 19+ if ( grammarForms && grammarForms[form] ) {
2020 return grammarForms[form][word] ;
2121 }
2222 switch ( form ) {

Sign-offs

UserFlagDate
Amire80inspected22:25, 19 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111727Port the convertGrammar method of bs and he to js...santhosh06:25, 17 February 2012

Comments

#Comment by Krinkle (talk | contribs)   01:30, 5 March 2012

We should probably add mw.language.data to the list of context-sensitive objects that should be reset in the teardown of each unit test (just like mw.messages and mw.config).

Not setting it from the test is also fine, but if you want to do a test like that. It's possible as long as you reset it afterwards (or implement it in QUnit.newMwEnvironment)

Status & tagging log