Prevent appearance of redirects in the rendered list
utils.getLanguagesByScriptGroup() runs on the object's languages property and not on all the langdb languages. This caused the redirects to be counted as languages. I fixed this, and added a test to prevent it. Also update JS langdb, because it went out of sync in of the previous commits.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -220,7 +220,6 @@
|
||||
return $.uls.data.getLanguagesByScriptGroupInRegions( [ region ] );
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns an associative array of all languages,
|
||||
* grouped by script group.
|
||||
@@ -237,23 +236,20 @@
|
||||
*/
|
||||
$.uls.data.getLanguagesByScriptGroup = function ( languages ) {
|
||||
var languagesByScriptGroup = {},
|
||||
scriptGroup,
|
||||
language,
|
||||
langScriptGroup;
|
||||
language, codeToAdd, langScriptGroup;
|
||||
|
||||
for ( scriptGroup in $.uls.data.scriptgroups ) {
|
||||
for ( language in languages ) {
|
||||
langScriptGroup = $.uls.data.getScriptGroupOfLanguage( language );
|
||||
for ( language in languages ) {
|
||||
codeToAdd = $.uls.data.isRedirect( language ) || language;
|
||||
|
||||
if ( langScriptGroup !== scriptGroup ) {
|
||||
continue;
|
||||
}
|
||||
langScriptGroup = $.uls.data.getScriptGroupOfLanguage( codeToAdd );
|
||||
|
||||
if ( !languagesByScriptGroup[scriptGroup] ) {
|
||||
languagesByScriptGroup[scriptGroup] = [];
|
||||
}
|
||||
if ( !languagesByScriptGroup[langScriptGroup] ) {
|
||||
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
|
||||
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
|
||||
var languages = languagesByScriptGroup[scriptGroup];
|
||||
|
||||
// It's possible that some script groups are missing
|
||||
if ( !languages ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sort it based on autonym
|
||||
languages.sort( $.uls.data.sortByAutonym );
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
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.
|
||||
// This is done early to make sure that it doesn't break other functions.
|
||||
$.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-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 ) );
|
||||
assert.deepEqual( languagesByScriptGroupInEMEA['WestCaucasian'], [
|
||||
'hy', 'ka', 'xmf'
|
||||
|
||||
Reference in New Issue
Block a user