Adding a special region

This is supposed to allow adding special languages.

This region's section is hidden by default and can be enabled by
passing different options to the lcd object.
This commit is contained in:
Amir E. Aharoni
2012-12-31 23:09:48 +02:00
parent 680e14196d
commit 829c827483
8 changed files with 71 additions and 15 deletions

View File

@@ -550,6 +550,8 @@ rtlscripts:
regiongroups:
# Worldwide, international
WW: 1
# Special languages. To be shown near Worldwide when relevant.
SP: 1
# America
AM: 2
# Europe

View File

@@ -7,6 +7,7 @@
},
"uls-select-language": "Select Language",
"uls-region-WW": "Worldwide",
"uls-region-SP": "Special",
"uls-region-AM": "America",
"uls-region-AF": "Africa",
"uls-region-EU": "Europe",

View File

@@ -7,6 +7,7 @@
},
"uls-select-language": "Language Selector Title",
"uls-region-WW": "Label for worldwide languages. They are languages spoken in multiple countries. Eg: English, French, Spanish etc. This label is used in the map region of ULS and as the title of section showing worldwide languages. Translation should not be descriptive.",
"uls-region-SP": "Label for the special languages section. This section may include special custom languages that can be added in run time. It's shown after the Worldwide section.",
"uls-region-AM": "Label for America",
"uls-region-AF": "Label for Africa",
"uls-region-EU": "Label for Europe",

View File

@@ -236,7 +236,8 @@
quickList: uls.options.quickList,
clickhandler: $.proxy( uls.select, uls ),
lazyload: uls.options.lazyload,
source: uls.$languageFilter
source: uls.$languageFilter,
showRegions: uls.options.showRegions
} ).data( 'lcd' );
uls.$languageFilter.languagefilter( {
@@ -366,7 +367,8 @@
searchAPI: null, // Language search API
languages: $.uls.data.getAutonyms(), // Languages to be used for ULS, default is all languages
quickList: null, // Array of language codes or function that returns such
lazyload: true // Lazy load the language list when scrolled.
lazyload: true, // Lazy load the language list when scrolled.
showRegions: ['WW', 'AM', 'EU', 'ME', 'AF', 'AS', 'PA']
};
// Define a dummy i18n function, if jquery.i18n not integrated.

File diff suppressed because one or more lines are too long

View File

@@ -417,4 +417,36 @@
return $.uls.data.territories[territory];
};
/**
* Adds a language in run time and sets its options as provided.
* If the target option is provided, the language is defined as a redirect.
* Other possible options are script, regions and autonym.
*
* @param code string New language code.
* @param options Object Language properties.
* @return list of language codes
*/
$.uls.data.addLanguage = function( code, options ) {
if ( options.target ) {
$.uls.data.languages[code] = [options.target];
} else {
$.uls.data.languages[code] = [options.script, options.regions, options.autonym];
}
};
/**
* Removes a language from the langdb in run time.
*
* @param code string Language code to delete.
* @return true if the language was removed, false otherwise.
*/
$.uls.data.deleteLanguage = function( code ) {
if ( $.uls.data.languages[code] ) {
delete $.uls.data.languages[code];
return true;
}
return false;
};
} ( jQuery ) );

View File

@@ -146,7 +146,10 @@
$rowDiv.append( $ul );
}
// Don't show the region unless it was enabled
if ( $.inArray( regionCode, this.options.showRegions ) > -1 ) {
$divRegionCode.show();
}
return $ul;
},
@@ -157,6 +160,7 @@
regions = {
// These are fallback text when i18n library not present
WW: 'Worldwide',
SP: 'Special',
AM: 'America',
EU: 'Europe',
ME: 'Middle East',
@@ -307,6 +311,7 @@
$.fn.lcd.defaults = {
languages: null,
showRegions: ['WW', 'AM', 'EU', 'ME', 'AF', 'AS', 'PA'],
lazyload: true
};

View File

@@ -89,7 +89,16 @@
assert.ok( $.fn.uls, "$.fn.uls is defined" );
} );
test( "-- $.uls.data testing", 41, function ( assert ) {
test( "-- $.uls.data testing", 45, 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', {
script: 'Latn',
regions: ['SP'],
autonym: 'Language documentation'
} );
assert.ok( $.uls.data.getAutonym( 'qqq' ), 'Language documentation', 'Language qqq was added with the correct autonym' );
assert.strictEqual( $.uls.data.isRedirect( 'sr-ec' ), 'sr-cyrl', "'sr-ec' is a redirect to 'sr-cyrl'" );
var autonyms = $.uls.data.getAutonyms();
@@ -166,14 +175,14 @@
);
assert.deepEqual( $.uls.data.getRegionsInGroup( 3 ), [
"EU", "ME", "AF"
], "regions in group 3 are selected correctly" );
'EU', 'ME', 'AF'
], 'regions in group 3 are selected correctly' );
assert.deepEqual( $.uls.data.getRegionsInGroup( 2 ), [
"AM"
], "regions in group 2 are selected correctly" );
'AM'
], 'regions in group 2 are selected correctly' );
assert.deepEqual( $.uls.data.getRegionsInGroup( 1 ), [
"WW"
], "regions in group 1 are selected correctly" );
'WW', 'SP'
], 'regions in group 1 are selected correctly' );
var languagesByScriptInAM = $.uls.data.getLanguagesByScriptInRegion( "AM" );
assert.deepEqual( languagesByScriptInAM['Cans'], [
@@ -204,8 +213,8 @@
], 'All languages in the Greek script found' );
assert.deepEqual( $.uls.data.getAllRegions(), [
"WW", "AM", "EU", "ME", "AF", "AS", "PA"
], "All regions found" );
'WW', 'SP', 'AM', 'EU', 'ME', 'AF', 'AS', 'PA'
], 'All regions found' );
// autonyms: gn: avañe'ẽ, de: deutsch, hu: magyar, fi: suomi
assert.deepEqual( ['de', 'fi', 'gn', 'hu'].sort( $.uls.data.sortByAutonym ), [
@@ -219,6 +228,10 @@
assert.ok( $.inArray( "sah", $.uls.data.getLanguagesInTerritory( "RU" ) )
> -1, "Sakha language is spoken in Russia" );
assert.ok( $.uls.data.deleteLanguage( 'qqq' ), 'Deleting language qqq, which was added earlier, returns true.' );
assert.strictEqual( $.uls.data.languages['qqq'], undefined, 'Data about qqq is undefined after being deleted.' );
assert.ok( !$.uls.data.deleteLanguage( 'qqr' ), 'Deleting language qqr, which was never added, returns false.' );
} );
}( jQuery ) );