r111744 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111743‎ | r111744 | r111745 >
Date:12:13, 17 February 2012
Author:santhosh
Status:resolved (Comments)
Tags:i18nreview 
Comment:
Russian and Finnish grammar rules in javascript and qunit test cases.
Modified paths:
  • /branches/jsgrammar/resources/Resources.php (modified) (history)
  • /branches/jsgrammar/resources/mediawiki.language/languages/fi.js (added) (history)
  • /branches/jsgrammar/resources/mediawiki.language/languages/ru.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
@@ -14,7 +14,7 @@
1515 // The test works only if the content language is opt.language
1616 // because it require [lang].js to be loaded.
1717 if( mw.config.get ( 'wgContentLanguage' ) === opt.language ) {
18 - test( "Grammar Test", function() {
 18+ test( "-- Grammar Test for "+ opt.language, function() {
1919 expect( opt.test.length);
2020 for ( var i= 0 ; i < opt.test.length; i++ ) {
2121 equal( mw.language.convertGrammar( opt.test[i].word, opt.test[i].grammarForm ), opt.test[i].expected, opt.test[i].description );
@@ -58,3 +58,28 @@
5959 { word: 'ժամանակի', grammarForm: 'genitive', expected: 'ժամանակիի', description: 'Grammar test for Armenian, genitive case' }
6060 ]
6161 });
 62+
 63+mw.language.grammartest({
 64+ language: 'fi',
 65+ test: [
 66+ { word: 'talo', grammarForm: 'genitive', expected: 'talon', description: 'Grammar test for Finnish, genitive case' },
 67+ { word: 'linux', grammarForm: 'genitive', expected: 'linuxin', description: 'Grammar test for Finnish, genitive case' },
 68+ { word: 'talo', grammarForm: 'elative', expected: 'talosta', description: 'Grammar test for Finnish, elative case' },
 69+ { word: 'pastöroitu', grammarForm: 'elative', expected: 'pastöroitusta', description: 'Grammar test for Finnish, elative case' },
 70+ { word: 'talo', grammarForm: 'partitive', expected: 'taloa', description: 'Grammar test for Finnish, partitive case' },
 71+ { word: 'talo', grammarForm: 'illative', expected: 'taloon', description: 'Grammar test for Finnish, illative case' },
 72+ { word: 'linux', grammarForm: 'inessive', expected: 'linuxissa', description: 'Grammar test for Finnish, inessive case' }
 73+ ]
 74+});
 75+
 76+mw.language.grammartest({
 77+ language: 'ru',
 78+ test: [
 79+ { word: 'честь', grammarForm: 'genitive', expected: 'честя', description: 'Grammar test for Russian, genitive case' },
 80+ { word: 'проведения', grammarForm: 'genitive', expected: 'проведении', description: 'Grammar test for Russian, genitive case' },
 81+ { word: 'Оснабрюка', grammarForm: 'genitive', expected: 'Оснабрюки', description: 'Grammar test for Russian, genitive case' },
 82+ { word: 'почти', grammarForm: 'genitive', expected: 'почтей', description: 'Grammar test for Russian, genitive case' },
 83+ { word: 'годы', grammarForm: 'genitive', expected: 'годов', description: 'Grammar test for Russian, genitive case' },
 84+ { word: 'песчаник', grammarForm: 'genitive', expected: 'песчаника', description: 'Grammar test for Russian, genitive case' }
 85+ ]
 86+});
Index: branches/jsgrammar/resources/Resources.php
@@ -670,6 +670,7 @@
671671 'cu' => 'resources/mediawiki.language/languages/cu.js',
672672 'cy' => 'resources/mediawiki.language/languages/cy.js',
673673 'dsb' => 'resources/mediawiki.language/languages/dsb.js',
 674+ 'fi' => 'resources/mediawiki.language/languages/fi.js',
674675 'fr' => 'resources/mediawiki.language/languages/fr.js',
675676 'ga' => 'resources/mediawiki.language/languages/ga.js',
676677 'gd' => 'resources/mediawiki.language/languages/gd.js',
Index: branches/jsgrammar/resources/mediawiki.language/languages/ru.js
@@ -21,3 +21,29 @@
2222 return forms[2];
2323 }
2424 };
 25+
 26+mediaWiki.language.convertGrammar = function( word, form ) {
 27+ var grammarForms = mw.language.data[ 'ru' ].get( 'grammarForms' );
 28+ if ( grammarForms && grammarForms[form] ) {
 29+ return grammarForms[form][word] ;
 30+ }
 31+ switch ( form ) {
 32+ case 'genitive': // родительный падеж
 33+ if ( ( word.substr( word.length - 4 ) == 'вики' ) || ( word.substr( word.length - 4 ) == 'Вики' ) ) {
 34+ }
 35+ else if ( word.substr( word.length - 1 ) == 'ь' )
 36+ word = word.substr(0, word.length - 1 ) + 'я';
 37+ else if ( word.substr( word.length - 2 ) == 'ия' )
 38+ word = word.substr(0, word.length - 2 ) + 'ии';
 39+ else if ( word.substr( word.length - 2 ) == 'ка' )
 40+ word = word.substr(0, word.length - 2 ) + 'ки';
 41+ else if ( word.substr( word.length - 2 ) == 'ти' )
 42+ word = word.substr(0, word.length - 2 ) + 'тей';
 43+ else if ( word.substr( word.length - 2 ) == 'ды' )
 44+ word = word.substr(0, word.length - 2 ) + 'дов';
 45+ else if ( word.substr( word.length - 3 ) == 'ник' )
 46+ word = word.substr(0, word.length - 3 ) + 'ника';
 47+ break;
 48+ }
 49+ return word;
 50+};
Index: branches/jsgrammar/resources/mediawiki.language/languages/fi.js
@@ -0,0 +1,41 @@
 2+/**
 3+ * Finnish (Suomi) language functions
 4+ * @author Santhosh Thottingal
 5+ */
 6+
 7+mediaWiki.language.convertGrammar = function( word, form ) {
 8+ var grammarForms = mw.language.data[ 'fi' ].get( 'grammarForms' );
 9+ if ( grammarForms && grammarForms[form] ) {
 10+ return grammarForms[form][word] ;
 11+ }
 12+
 13+ // vowel harmony flag
 14+ aou = word.match( /[aou][^äöy]*$/i );
 15+
 16+ if ( word.match( /wiki$/i ) ) {
 17+ aou = false;
 18+ }
 19+ //append i after final consonant
 20+ if ( word.match( /[bcdfghjklmnpqrstvwxz]$/i ) )
 21+ word += 'i';
 22+
 23+ switch ( form ) {
 24+ case 'genitive':
 25+ word += 'n';
 26+ break;
 27+ case 'elative':
 28+ word += ( aou ? 'sta' : 'stä' );
 29+ break;
 30+ case 'partitive':
 31+ word += ( aou ? 'a' : 'ä' );
 32+ break;
 33+ case 'illative':
 34+ // Double the last letter and add 'n'
 35+ word += word.substr( word.length-1 ) + 'n';
 36+ break;
 37+ case 'inessive':
 38+ word += ( aou ? 'ssa' : 'ssä' );
 39+ break;
 40+ }
 41+ return word;
 42+};
Property changes on: branches/jsgrammar/resources/mediawiki.language/languages/fi.js
___________________________________________________________________
Added: svn:eol-style
143 + native

Sign-offs

UserFlagDate
Amire80inspected22:27, 19 February 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r111910Port grammar rules of dsb, hu, ga to javascript with qunit tests...santhosh05:38, 20 February 2012
r111931Whitespace cleanups and change Finnish test case, pastöroitusta would not be...nikerabbit14:16, 20 February 2012

Comments

#Comment by Nikerabbit (talk | contribs)   20:50, 17 February 2012

Ah pastöroitu is bad example word because of consonant gradation the correct form is pastöroidusta.

Shouldn't it be var aou = ...;?

#Comment by Santhosh.thottingal (talk | contribs)   05:27, 20 February 2012

Can you suggest an alternate word for that test?

Status & tagging log