Merge branch 'master' of github.com:wikimedia/jquery.uls

This commit is contained in:
Siebrand Mazeland
2013-01-13 13:54:46 +00:00
10 changed files with 130 additions and 46 deletions

View File

@@ -127,7 +127,7 @@ languages:
fj: [Latn, [PA], Na Vosa Vakaviti] fj: [Latn, [PA], Na Vosa Vakaviti]
fo: [Latn, [EU], føroyskt] fo: [Latn, [EU], føroyskt]
fr: [Latn, [EU, AM, WW], français] fr: [Latn, [EU, AM, WW], français]
frc: [Latn, [EU], français cadien] frc: [Latn, [AM], français cadien]
frp: [Latn, [EU], arpetan] frp: [Latn, [EU], arpetan]
frr: [Latn, [EU], Nordfriisk] frr: [Latn, [EU], Nordfriisk]
fur: [Latn, [EU], furlan] fur: [Latn, [EU], furlan]
@@ -312,7 +312,8 @@ languages:
nl-informal: [Latn, [EU, AM], Nederlands (informeel)] nl-informal: [Latn, [EU, AM], Nederlands (informeel)]
nl: [Latn, [EU, AM], Nederlands] nl: [Latn, [EU, AM], Nederlands]
nn: [Latn, [EU], norsk (nynorsk)] nn: [Latn, [EU], norsk (nynorsk)]
"no": [Latn, [EU]] # There's also nb for Bokmål and nn for Nynorsk
"no": [Latn, [EU], norsk]
nov: [Latn, [WW], Novial] nov: [Latn, [WW], Novial]
nqo: [Nkoo, [AF], ߒߞߏ] nqo: [Nkoo, [AF], ߒߞߏ]
nrm: [Latn, [EU], Nouormand] nrm: [Latn, [EU], Nouormand]
@@ -551,6 +552,8 @@ rtlscripts:
regiongroups: regiongroups:
# Worldwide, international # Worldwide, international
WW: 1 WW: 1
# Special languages. To be shown near Worldwide when relevant.
SP: 1
# America # America
AM: 2 AM: 2
# Europe # Europe

View File

@@ -72,6 +72,7 @@ $json = json_encode( $parsedLangdb );
$js = <<<JAVASCRIPT $js = <<<JAVASCRIPT
// Please do not edit. This file is generated from data/langdb.yaml by ulsdata2json.php // Please do not edit. This file is generated from data/langdb.yaml by ulsdata2json.php
( function ( $ ) { ( function ( $ ) {
'use strict';
$.uls = $.uls || {}; $.uls = $.uls || {};
$.uls.data = $json; $.uls.data = $json;
} ( jQuery ) ); } ( jQuery ) );

View File

@@ -7,6 +7,7 @@
}, },
"uls-select-language": "Select Language", "uls-select-language": "Select Language",
"uls-region-WW": "Worldwide", "uls-region-WW": "Worldwide",
"uls-region-SP": "Special",
"uls-region-AM": "America", "uls-region-AM": "America",
"uls-region-AF": "Africa", "uls-region-AF": "Africa",
"uls-region-EU": "Europe", "uls-region-EU": "Europe",
@@ -15,7 +16,7 @@
"uls-region-PA": "Pacific", "uls-region-PA": "Pacific",
"uls-no-results-found": "No results found", "uls-no-results-found": "No results found",
"uls-common-languages": "Common languages", "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-help": "You can search by language name, script name, ISO code of language or you can browse by region:",
"uls-search-placeholder": "Language search" "uls-search-placeholder": "Language search"
} }

View File

@@ -7,6 +7,7 @@
}, },
"uls-select-language": "Language Selector Title", "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-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-AM": "Label for America",
"uls-region-AF": "Label for Africa", "uls-region-AF": "Label for Africa",
"uls-region-EU": "Label for Europe", "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-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-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" "uls-search-placeholder": "Placeholder text in search box"
} }

View File

@@ -236,7 +236,8 @@
quickList: uls.options.quickList, quickList: uls.options.quickList,
clickhandler: $.proxy( uls.select, uls ), clickhandler: $.proxy( uls.select, uls ),
lazyload: uls.options.lazyload, lazyload: uls.options.lazyload,
source: uls.$languageFilter source: uls.$languageFilter,
showRegions: uls.options.showRegions
} ).data( 'lcd' ); } ).data( 'lcd' );
uls.$languageFilter.languagefilter( { uls.$languageFilter.languagefilter( {
@@ -366,7 +367,8 @@
searchAPI: null, // Language search API searchAPI: null, // Language search API
languages: $.uls.data.getAutonyms(), // Languages to be used for ULS, default is all languages 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 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. // Define a dummy i18n function, if jquery.i18n not integrated.

File diff suppressed because one or more lines are too long

View File

@@ -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 );
} }
} }
@@ -421,4 +417,38 @@
$.uls.data.getLanguagesInTerritory = function ( territory ) { $.uls.data.getLanguagesInTerritory = function ( territory ) {
return $.uls.data.territories[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 ) ); } ( jQuery ) );

View File

@@ -147,7 +147,10 @@
$rowDiv.append( $ul ); $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; return $ul;
}, },
@@ -158,6 +161,7 @@
regions = { regions = {
// These are fallback text when i18n library not present // These are fallback text when i18n library not present
WW: 'Worldwide', WW: 'Worldwide',
SP: 'Special',
AM: 'America', AM: 'America',
EU: 'Europe', EU: 'Europe',
ME: 'Middle East', ME: 'Middle East',
@@ -268,7 +272,8 @@
// The region section need to be in sync with the map filter. // The region section need to be in sync with the map filter.
lcd.$element.scroll( function () { lcd.$element.scroll( function () {
var $ulsLanguageList = $( this ), var inview, inviewRegion,
$ulsLanguageList = $( this ),
scrollTop = $ulsLanguageList.position().top, scrollTop = $ulsLanguageList.position().top,
scrollBottom = $ulsLanguageList.height(); scrollBottom = $ulsLanguageList.height();
@@ -278,7 +283,7 @@
} }
} }
// The region section need to be in sync with the map filter. // The region section need to be in sync with the map filter.
var inviewRegion = 'WW'; inviewRegion = 'WW';
lcd.$element.find( 'div.uls-lcd-region-section' ).each( function () { lcd.$element.find( 'div.uls-lcd-region-section' ).each( function () {
var $lcdRegionSection = $( this ), var $lcdRegionSection = $( this ),
top = $lcdRegionSection.position().top, top = $lcdRegionSection.position().top,
@@ -292,7 +297,7 @@
} }
} ); } );
var inview = $.uls.data.regiongroups[inviewRegion]; inview = $.uls.data.regiongroups[inviewRegion];
$( '.regionselector' ).removeClass( 'active' ); $( '.regionselector' ).removeClass( 'active' );
$( '#uls-region-' + inview ).addClass( 'active' ); $( '#uls-region-' + inview ).addClass( 'active' );
} ); } );
@@ -317,6 +322,7 @@
$.fn.lcd.defaults = { $.fn.lcd.defaults = {
languages: null, languages: null,
showRegions: ['WW', 'AM', 'EU', 'ME', 'AF', 'AS', 'PA'],
lazyload: true lazyload: true
}; };

View File

@@ -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 );
@@ -110,21 +117,22 @@
}, },
next: function () { next: function () {
if ( !this.$element.hasClass( 'active') ) { var regionSelector = this;
if ( !this.$element.hasClass( 'active' ) ) {
return true; return true;
} }
var regionSelector = this;
// Do not respond to all scroll end events, but only after a short interval // Do not respond to all scroll end events, but only after a short interval
delay( function () { delay( function () {
var regiongroup = regionSelector.$element.data( 'regiongroup' ); var nextRegionGroupNumber = regionSelector.$element.data( 'regiongroup' ) + 1,
var nextRegiongroup = regiongroup + 1; $nextRegion = $( '#uls-region-' + nextRegionGroupNumber ),
nextRegionSelector = $nextRegion.length && $nextRegion.data( 'regionselector' );
var $nextRegion = $( '#uls-region-' + nextRegiongroup ); // If cache is defined, then it is already rendered and there's no need
var next = $nextRegion.length && $nextRegion.data( 'regionselector' ); // to re-render it.
if ( nextRegionSelector && nextRegionSelector.cache === null ) {
if ( next ) { nextRegionSelector.show();
next.show();
} }
}, 100 ); }, 100 );
@@ -133,7 +141,7 @@
listen: function () { listen: function () {
this.$element.on( 'click', $.proxy( this.click, this ) ); this.$element.on( 'click', $.proxy( this.click, this ) );
this.options.$target.$element.bind( 'scrollend', $.proxy( this.next, this) ); this.options.$target.$element.bind( 'scrollend', $.proxy( this.next, this ) );
}, },
click: function ( e ) { click: function ( e ) {

View File

@@ -89,7 +89,16 @@
assert.ok( $.fn.uls, "$.fn.uls is defined" ); assert.ok( $.fn.uls, "$.fn.uls is defined" );
} ); } );
test( "-- $.uls.data testing", 41, 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', {
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'" ); assert.strictEqual( $.uls.data.isRedirect( 'sr-ec' ), 'sr-cyrl', "'sr-ec' is a redirect to 'sr-cyrl'" );
var autonyms = $.uls.data.getAutonyms(); var autonyms = $.uls.data.getAutonyms();
@@ -144,7 +153,7 @@
assert.deepEqual( $.uls.data.getLanguagesInRegions( ["AM", "WW"] ), assert.deepEqual( $.uls.data.getLanguagesInRegions( ["AM", "WW"] ),
[ [
"akz", "arn", "aro", "ase", "avk", "ay", "cho", "chr", "chy", "cr", "cr-latn", "akz", "arn", "aro", "ase", "avk", "ay", "cho", "chr", "chy", "cr", "cr-latn",
"en-ca", "en", "eo", "es-419", "es-formal", "es", "esu", "fr", "gcf", "gn", "en-ca", "en", "eo", "es-419", "es-formal", "es", "esu", "fr", "frc", "gcf", "gn",
"guc", "haw", "ht", "ia", "ie", "ik", "ike-cans", "ike-latn", "io", "iu", "jam", "guc", "haw", "ht", "ia", "ie", "ik", "ike-cans", "ike-latn", "io", "iu", "jam",
"jbo", "kgp", "kl", "lad-latn", "lad-hebr", "lfn", "mfe", "mic", "mus", "nah", "nl-informal", "nl", "jbo", "kgp", "kl", "lad-latn", "lad-hebr", "lfn", "mfe", "mic", "mus", "nah", "nl-informal", "nl",
"nov", "nv", "pap", "pdc", "pdt", "ppl", "pt-br", "pt", "qu", "qug", "rap", "sei", "nov", "nv", "pap", "pdc", "pdt", "ppl", "pt-br", "pt", "qu", "qug", "rap", "sei",
@@ -166,14 +175,14 @@
); );
assert.deepEqual( $.uls.data.getRegionsInGroup( 3 ), [ assert.deepEqual( $.uls.data.getRegionsInGroup( 3 ), [
"EU", "ME", "AF" 'EU', 'ME', 'AF'
], "regions in group 3 are selected correctly" ); ], 'regions in group 3 are selected correctly' );
assert.deepEqual( $.uls.data.getRegionsInGroup( 2 ), [ assert.deepEqual( $.uls.data.getRegionsInGroup( 2 ), [
"AM" 'AM'
], "regions in group 2 are selected correctly" ); ], 'regions in group 2 are selected correctly' );
assert.deepEqual( $.uls.data.getRegionsInGroup( 1 ), [ assert.deepEqual( $.uls.data.getRegionsInGroup( 1 ), [
"WW" 'WW', 'SP'
], "regions in group 1 are selected correctly" ); ], 'regions in group 1 are selected correctly' );
var languagesByScriptInAM = $.uls.data.getLanguagesByScriptInRegion( "AM" ); var languagesByScriptInAM = $.uls.data.getLanguagesByScriptInRegion( "AM" );
assert.deepEqual( languagesByScriptInAM['Cans'], [ assert.deepEqual( languagesByScriptInAM['Cans'], [
@@ -189,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'
@@ -204,8 +231,8 @@
], 'All languages in the Greek script found' ); ], 'All languages in the Greek script found' );
assert.deepEqual( $.uls.data.getAllRegions(), [ assert.deepEqual( $.uls.data.getAllRegions(), [
"WW", "AM", "EU", "ME", "AF", "AS", "PA" 'WW', 'SP', 'AM', 'EU', 'ME', 'AF', 'AS', 'PA'
], "All regions found" ); ], 'All regions found' );
// autonyms: gn: avañe'ẽ, de: deutsch, hu: magyar, fi: suomi // autonyms: gn: avañe'ẽ, de: deutsch, hu: magyar, fi: suomi
assert.deepEqual( ['de', 'fi', 'gn', 'hu'].sort( $.uls.data.sortByAutonym ), [ assert.deepEqual( ['de', 'fi', 'gn', 'hu'].sort( $.uls.data.sortByAutonym ), [
@@ -219,6 +246,10 @@
assert.ok( $.inArray( "sah", $.uls.data.getLanguagesInTerritory( "RU" ) ) assert.ok( $.inArray( "sah", $.uls.data.getLanguagesInTerritory( "RU" ) )
> -1, "Sakha language is spoken in Russia" ); > -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 ) ); }( jQuery ) );