Merge branch 'prevent_dupes' into 2013-01-09-fixes
This commit is contained in:
@@ -220,7 +220,6 @@
|
|||||||
return $.uls.data.getLanguagesByScriptGroupInRegions( [ region ] );
|
return $.uls.data.getLanguagesByScriptGroupInRegions( [ region ] );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an associative array of all languages,
|
* Returns an associative array of all languages,
|
||||||
* grouped by script group.
|
* grouped by script group.
|
||||||
@@ -237,23 +236,20 @@
|
|||||||
*/
|
*/
|
||||||
$.uls.data.getLanguagesByScriptGroup = function ( languages ) {
|
$.uls.data.getLanguagesByScriptGroup = function ( languages ) {
|
||||||
var languagesByScriptGroup = {},
|
var languagesByScriptGroup = {},
|
||||||
scriptGroup,
|
language, codeToAdd, langScriptGroup;
|
||||||
language,
|
|
||||||
langScriptGroup;
|
|
||||||
|
|
||||||
for ( scriptGroup in $.uls.data.scriptgroups ) {
|
for ( language in languages ) {
|
||||||
for ( language in languages ) {
|
codeToAdd = $.uls.data.isRedirect( language ) || language;
|
||||||
langScriptGroup = $.uls.data.getScriptGroupOfLanguage( language );
|
|
||||||
|
|
||||||
if ( langScriptGroup !== scriptGroup ) {
|
langScriptGroup = $.uls.data.getScriptGroupOfLanguage( codeToAdd );
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !languagesByScriptGroup[scriptGroup] ) {
|
if ( !languagesByScriptGroup[langScriptGroup] ) {
|
||||||
languagesByScriptGroup[scriptGroup] = [];
|
languagesByScriptGroup[langScriptGroup] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
languagesByScriptGroup[scriptGroup].push( language );
|
// Prevent duplicate adding of redirects
|
||||||
|
if ( $.inArray( codeToAdd, languagesByScriptGroup[langScriptGroup] ) === -1 ) {
|
||||||
|
languagesByScriptGroup[langScriptGroup].push( codeToAdd );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,10 +80,17 @@
|
|||||||
// Get the languages grouped by script group
|
// Get the languages grouped by script group
|
||||||
var languagesByScriptGroup = $.uls.data.getLanguagesByScriptGroup( this.options.languages );
|
var languagesByScriptGroup = $.uls.data.getLanguagesByScriptGroup( this.options.languages );
|
||||||
|
|
||||||
for ( var scriptGroup in languagesByScriptGroup ) {
|
// Make sure that we go by the original order
|
||||||
|
// of script groups
|
||||||
|
for ( var scriptGroup in $.uls.data.scriptgroups ) {
|
||||||
// Get the languages for the script group
|
// Get the languages for the script group
|
||||||
var languages = languagesByScriptGroup[scriptGroup];
|
var languages = languagesByScriptGroup[scriptGroup];
|
||||||
|
|
||||||
|
// It's possible that some script groups are missing
|
||||||
|
if ( !languages ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Sort it based on autonym
|
// Sort it based on autonym
|
||||||
languages.sort( $.uls.data.sortByAutonym );
|
languages.sort( $.uls.data.sortByAutonym );
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@
|
|||||||
assert.ok( $.fn.uls, "$.fn.uls is defined" );
|
assert.ok( $.fn.uls, "$.fn.uls is defined" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test( "-- $.uls.data testing", 45, function ( assert ) {
|
test( "-- $.uls.data testing", 46, function ( assert ) {
|
||||||
// Add a language in run time.
|
// Add a language in run time.
|
||||||
// This is done early to make sure that it doesn't break other functions.
|
// This is done early to make sure that it doesn't break other functions.
|
||||||
$.uls.data.addLanguage( 'qqq', {
|
$.uls.data.addLanguage( 'qqq', {
|
||||||
@@ -198,6 +198,24 @@
|
|||||||
assert.strictEqual( $.uls.data.getAutonym( 'pa' ), 'ਪੰਜਾਬੀ', 'Correct autonym of the Punjabi language was selected using code pa.' );
|
assert.strictEqual( $.uls.data.getAutonym( 'pa' ), 'ਪੰਜਾਬੀ', 'Correct autonym of the Punjabi language was selected using code pa.' );
|
||||||
assert.strictEqual( $.uls.data.getAutonym( 'pa-guru' ), 'ਪੰਜਾਬੀ', 'Correct autonym of the Punjabi language was selected using code pa-guru.' );
|
assert.strictEqual( $.uls.data.getAutonym( 'pa-guru' ), 'ਪੰਜਾਬੀ', 'Correct autonym of the Punjabi language was selected using code pa-guru.' );
|
||||||
|
|
||||||
|
var languagesToGroup = {
|
||||||
|
'en': 'English',
|
||||||
|
'fiu-vro': 'Võro', // Alias before target
|
||||||
|
'ru': 'русский',
|
||||||
|
'sr': 'српски', // Alias before target
|
||||||
|
'sr-cyrl': 'српски', // Target before alias
|
||||||
|
'sr-latn': 'srpski', // Target before alias
|
||||||
|
'sr-el': 'srpski', // Alias after target
|
||||||
|
'vro': 'Võro' // Target after alias
|
||||||
|
},
|
||||||
|
groupedLanguages = {
|
||||||
|
Latin: [ 'en', 'vro', 'sr-latn' ],
|
||||||
|
Cyrillic: [ 'ru', 'sr-cyrl' ]
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.deepEqual( $.uls.data.getLanguagesByScriptGroup( languagesToGroup ), groupedLanguages,
|
||||||
|
'A custom list of languages is grouped correctly using getLanguagesByScriptGroup.' );
|
||||||
|
|
||||||
var languagesByScriptGroupInEMEA = $.uls.data.getLanguagesByScriptGroupInRegions( $.uls.data.getRegionsInGroup( 3 ) );
|
var languagesByScriptGroupInEMEA = $.uls.data.getLanguagesByScriptGroupInRegions( $.uls.data.getRegionsInGroup( 3 ) );
|
||||||
assert.deepEqual( languagesByScriptGroupInEMEA['WestCaucasian'], [
|
assert.deepEqual( languagesByScriptGroupInEMEA['WestCaucasian'], [
|
||||||
'hy', 'ka', 'xmf'
|
'hy', 'ka', 'xmf'
|
||||||
|
|||||||
Reference in New Issue
Block a user