Index: branches/jsgrammar/tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js |
— | — | @@ -9,35 +9,53 @@ |
10 | 10 | mw.language.grammartest = function( options ) { |
11 | 11 | var opt = $.extend({ |
12 | 12 | language: '', |
13 | | - grammarForm: null, |
14 | | - word: '', |
15 | | - expected: '', |
16 | | - description: '' |
| 13 | + test: [], |
17 | 14 | }, options); |
18 | 15 | // The test works only if the content language is opt.language |
19 | 16 | // because it require [lang].js to be loaded. |
20 | 17 | 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 ); |
30 | 34 | } |
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 ); |
34 | 35 | } ); |
35 | 36 | } |
36 | 37 | } |
37 | 38 | |
38 | 39 | mw.language.grammartest({ |
39 | 40 | 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 | + ] |
44 | 44 | }); |
| 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 @@ |
19 | 19 | return forms[2]; |
20 | 20 | } |
21 | 21 | }; |
| 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 @@ |
13 | 13 | } |
14 | 14 | return forms[1]; |
15 | 15 | }; |
| 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 | +}; |