Sorting languages by script.

* Clarified naming: separated regions from region groups.
* New utility functions for sorting and grouping languages.
* JSHint fixes.
* Added tests.

Change-Id: I8153a2b89fbc7b9a7d6b7deeb87208efc9f4d021
This commit is contained in:
Amir E. Aharoni
2012-07-02 08:49:57 +03:00
parent 47b1a7f16f
commit 607abaa201
5 changed files with 199 additions and 63 deletions

View File

@@ -3,10 +3,12 @@
*
* @file
* @author Santhosh Thottingal
* @copyright Copyright © 2012 Santhosh Thottingal
* @author Amir E. Aharoni
* @copyright Copyright © 2012 Santhosh Thottingal, Amir E. Aharoni
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
*/
( function () {
"use strict";
module( "ext.uls", QUnit.newMwEnvironment() );
@@ -16,7 +18,7 @@ module( "ext.uls", QUnit.newMwEnvironment() );
*/
var orphanScript = function () {
for ( var language in $.uls.data.languages ) {
var script = $.uls.data.languages[language][0];
var script = $.uls.data.script( language );
if ( $.uls.data.groupOfScript( script ) === 'Other' ) {
return script;
}
@@ -31,16 +33,28 @@ test( "-- Initial check", function() {
} );
test( "-- $.uls.data testing", function() {
expect( 12 );
expect( 15 );
// This test assumes that we don't want any scripts to be in the 'Other'
// group. Actually, this may become wrong some day.
strictEqual( orphanScript(), '', 'No orphan scripts found.' );
strictEqual( $.uls.data.groupOfScript( 'Beng' ), 'SouthAsian', 'Bengali script belongs to the SouthAsian group.' );
strictEqual(
$.uls.data.groupOfScript( 'Beng' ),
'SouthAsian',
'Bengali script belongs to the SouthAsian group.'
);
strictEqual(
$.uls.data.scriptGroupOfLanguage( 'iu' ),
'NativeAmerican',
'The script of the Inupiaq language belongs to the NativeAmerican group.'
);
strictEqual( $.uls.data.script( 'ii' ), 'Yiii', 'Correct script of the Yi language was selected' );
deepEqual( $.uls.data.regions( 'lzz' ), [ 'EU', 'ME' ], 'Correct regions of the Laz language were selected' );
var allLanguagesByRegionAndScript = $.uls.data.allLanguagesByRegionAndScript();
deepEqual( allLanguagesByRegionAndScript['3']['AS']['SouthEastAsian']['Bugi'], ['bug'], 'All languages in the Buginese script in Asia were selected' );
deepEqual( $.uls.data.languagesInRegion( 'AU' ), ["en", "en-gb", "hif", "hif-latn", "mi", "na"], "languages of region AU are selected correctly" );
deepEqual( $.uls.data.languagesInRegions( ['NA', 'WW'] ),
[
@@ -62,10 +76,13 @@ test( "-- $.uls.data testing", function() {
deepEqual( $.uls.data.regionsInGroup( 1 ), ["NA", "LA", "SA"], "regions in group 1 are selected correctly" );
deepEqual( $.uls.data.regionsInGroup( 4 ), ["WW"], "regions in group 4 are selected correctly" );
languagesByScriptInNA = $.uls.data.languagesByScriptInRegion( 'NA' );
var languagesByScriptInNA = $.uls.data.languagesByScriptInRegion( 'NA' );
deepEqual( languagesByScriptInNA['Cans'], ["cr", "ike-cans", "iu"], "correct languages in Cans in NA selected" );
strictEqual( $.uls.data.autonym( 'pa' ), 'ਪੰਜਾਬੀ', 'Correct autonym of the Punjabi language was selected' );
var languagesByScriptGroupInEMEA = $.uls.data.languagesByScriptGroupInRegions( $.uls.data.regionsInGroup( 2 ) );
deepEqual( languagesByScriptGroupInEMEA['WestCaucasian'], ['hy', 'ka', 'xmf'], 'Correct languages in WestCaucasian script group selected' );
} );
}() );