r111727 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111726‎ | r111727 | r111728 >
Date:06:25, 17 February 2012
Author:santhosh
Status:resolved (Comments)
Tags:i18nreview 
Comment:
Port the convertGrammar method of bs and he to js
Add qunit test cases for the same
Modified paths:
  • /branches/jsgrammar/resources/mediawiki.language/languages/bs.js (modified) (history)
  • /branches/jsgrammar/resources/mediawiki.language/languages/he.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
@@ -9,35 +9,53 @@
1010 mw.language.grammartest = function( options ) {
1111 var opt = $.extend({
1212 language: '',
13 - grammarForm: null,
14 - word: '',
15 - expected: '',
16 - description: ''
 13+ test: [],
1714 }, options);
1815 // The test works only if the content language is opt.language
1916 // because it require [lang].js to be loaded.
2017 if( mw.config.get ( 'wgContentLanguage' ) === opt.language ) {
21 - test( opt.description, function() {
22 - expect( 1 );
23 - var langData = mw.language.data;
24 - var grammarForms = [];
25 - grammarForms[ opt.grammarForm ] = [] ;
26 - if ( langData[opt.language] === undefined ) {
27 - langData[opt.language] = new mw.Map();
28 - }else{
29 - grammarForms = langData[opt.language].get( 'grammarForms' );
 18+ test( "Grammar Test", function() {
 19+ expect( opt.test.length);
 20+ 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 );
 33+ equal( mw.language.convertGrammar( opt.test[i].word, opt.test[i].grammarForm ), opt.test[i].expected, opt.test[i].description );
3034 }
31 - grammarForms[opt.grammarForm][opt.word] = opt.expected ;
32 - langData[opt.language].set( 'grammarForms', grammarForms );
33 - equal( mw.language.convertGrammar( opt.word, opt.grammarForm ), opt.expected, opt.description );
3435 } );
3536 }
3637 }
3738
3839 mw.language.grammartest({
3940 language: 'en',
40 - word: 'pen',
41 - grammarForm: 'genitive',
42 - expected: 'pen\'s',
43 - description: 'Grammar test for English'
 41+ test: [
 42+ { word: 'pen', grammarForm: 'genitive', expected: 'pen\'s', description: 'Grammar test for English' }
 43+ ]
4444 });
 45+
 46+mw.language.grammartest({
 47+ language: 'bs',
 48+ test: [
 49+ { word: 'word', grammarForm: 'instrumental', expected: 's word', description: 'Grammar test for Bosnian, instrumental case' },
 50+ { word: 'word', grammarForm: 'lokativ', expected: 'o word', description: 'Grammar test for Bosnian, lokativ case' }
 51+ ]
 52+});
 53+
 54+mw.language.grammartest({
 55+ language: 'he',
 56+ test: [
 57+ { word: "ויקיפדיה", grammarForm: 'prefixed', expected: "וויקיפדיה", description: 'Grammar test for Hebrew, Duplicate the "Waw" if prefixed' },
 58+ { word: "וויקיפדיה", grammarForm: 'prefixed', expected: "וויקיפדיה", description: 'Grammar test for Hebrew, Duplicate the "Waw" if prefixed, but not if it is already duplicated.' },
 59+ { word: "הקובץ", grammarForm: 'prefixed', expected: "קובץ", description: 'Grammar test for Hebrew, Remove the "He" if prefixed' },
 60+ { word: 'wikipedia', grammarForm: 'תחילית', expected: '־wikipedia', description: 'Grammar test for Hebrew, Add a hyphen (maqaf) if non-Hebrew letters' }
 61+ ]
 62+});
Index: branches/jsgrammar/resources/mediawiki.language/languages/bs.js
@@ -18,3 +18,19 @@
1919 return forms[2];
2020 }
2121 };
 22+
 23+mediaWiki.language.convertGrammar = function( word, form ) {
 24+ var grammarForms = mw.language.data[ mw.config.get( 'wgContentLanguage' )].get( 'grammarForms' );
 25+ if ( grammarForms && grammarForms[form] ) {
 26+ return grammarForms[form][word] ;
 27+ }
 28+ switch ( form ) {
 29+ case 'instrumental': // instrumental
 30+ word = 's ' + word;
 31+ break;
 32+ case 'lokativ': // locative
 33+ word = 'o ' + word;
 34+ break;
 35+ }
 36+ return word;
 37+};
Index: branches/jsgrammar/resources/mediawiki.language/languages/he.js
@@ -12,3 +12,29 @@
1313 }
1414 return forms[1];
1515 };
 16+
 17+mediaWiki.language.convertGrammar = function( word, form ) {
 18+ var grammarForms = mw.config.get( 'wgGrammarForms' );
 19+ if ( grammarForms && grammarForms['he'] && grammarForms['he'][form] ) {
 20+ return grammarForms[form][word] ;
 21+ }
 22+ switch ( form ) {
 23+ case 'prefixed':
 24+ case 'תחילית':
 25+ // Duplicate the "Waw" if prefixed
 26+ if ( word.substr( 0, 1 ) === "ו" && word.substr( 0, 2 ) !== "וו" ) {
 27+ word = "ו" + word;
 28+ }
 29+
 30+ // Remove the "He" if prefixed
 31+ if ( word.substr( 0, 1 ) === "ה" ) {
 32+ word = word.substr( 1, word.length );
 33+ }
 34+
 35+ // Add a hyphen (maqaf) if non-Hebrew letters
 36+ if ( word.substr( 0, 1 ) < "א" || word.substr( 0, 1 ) > "ת" ) {
 37+ word = "־" + word;
 38+ }
 39+ }
 40+ return word;
 41+};

Sign-offs

UserFlagDate
Amire80inspected22:09, 19 February 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r111734Do not set the grammarForms from test, a mistake in r111727...santhosh09:33, 17 February 2012

Comments

#Comment by Krinkle (talk | contribs)   01:40, 5 March 2012
 mw.language.grammartest({
 	language: 'en',
-	word: 'pen',
-	grammarForm: 'genitive',
-	expected: 'pen\'s',
-	description: 'Grammar test for English'
+	test: [ 
+		{ word: 'pen', grammarForm: 'genitive', expected: 'pen\'s', description: 'Grammar test for English' }
+	]
});

These lines (especially in later commits) tend to get very long, perhaps just put each property on its own line. Looks fine otherwise

Status & tagging log