Merge branch 'extra_languages' of git://github.com/amire80/jquery.uls into amire80-extra_languages

Conflicts:
	src/jquery.uls.data.js
	src/jquery.uls.data.utils.js

Change-Id: I9c321891707b0d68328f4e4c8be1bd451794072d
This commit is contained in:
Santhosh Thottingal
2013-01-07 15:43:13 +05:30
7 changed files with 72 additions and 14 deletions

View File

@@ -551,6 +551,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",
@@ -15,7 +16,7 @@
"uls-region-PA": "Pacific",
"uls-no-results-found": "No results found",
"uls-common-languages": "Common languages",
"uls-no-results-suggestion-title": "You may be interested in:",
"uls-no-results-suggestion-title": "You may be interested in:",
"uls-search-help": "You can search by language name, script name, ISO code of language or you can browse by region:",
"uls-search-placeholder": "Language search"
}

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",
@@ -18,4 +19,4 @@
"uls-no-results-suggestion-title": "Title for language suggestion in 'no results found' screen",
"uls-search-help": "Help text for searching. After this text, there will be a set of links for regions",
"uls-search-placeholder": "Placeholder text in search box"
}
}

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.

View File

@@ -421,4 +421,38 @@
$.uls.data.getLanguagesInTerritory = function ( territory ) {
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

@@ -147,7 +147,10 @@
$rowDiv.append( $ul );
}
$divRegionCode.show();
// Don't show the region unless it was enabled
if ( $.inArray( regionCode, this.options.showRegions ) > -1 ) {
$divRegionCode.show();
}
return $ul;
},
@@ -158,6 +161,7 @@
regions = {
// These are fallback text when i18n library not present
WW: 'Worldwide',
SP: 'Special',
AM: 'America',
EU: 'Europe',
ME: 'Middle East',
@@ -317,6 +321,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 ) );