Created script groups, introduce $.uls.data
Gave script groups clear names and sorted them. Documentation in comments. Add tests to check that no script has been left behind. Corrected Lath to Latn (thanks to testing). Rename langdb.js to ext.uls.data.js Add ResourceLoader module ext.uls.data Change-Id: I91fafa94ffd1eaf2d12c954fe3a71064276533f9
This commit is contained in:
committed by
Santhosh Thottingal
parent
b9ee6595d3
commit
03df48a609
@@ -28,7 +28,7 @@ class UniversalLanguageSelectorHooks {
|
|||||||
$testModules['qunit']['ext.uls.tests'] = array(
|
$testModules['qunit']['ext.uls.tests'] = array(
|
||||||
'scripts' => array( 'tests/qunit/ext.uls.tests.js' ),
|
'scripts' => array( 'tests/qunit/ext.uls.tests.js' ),
|
||||||
'dependencies' => array( 'ext.uls.init' ),
|
'dependencies' => array( 'ext.uls.init' ),
|
||||||
'localBasePath' => dirname( __FILE__ ),
|
'localBasePath' => __DIR__,
|
||||||
'remoteExtPath' => 'UniversalLanguageSelector',
|
'remoteExtPath' => 'UniversalLanguageSelector',
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -45,15 +45,25 @@ $wgResourceModules['ext.uls.init'] = array(
|
|||||||
'position' => 'top',
|
'position' => 'top',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$wgResourceModules['ext.uls.data'] = array(
|
||||||
|
'scripts' => 'data/ext.uls.data.js',
|
||||||
|
'localBasePath' => $dir,
|
||||||
|
'remoteExtPath' => 'UniversalLanguageSelector',
|
||||||
|
);
|
||||||
|
|
||||||
$wgResourceModules['ext.uls.core'] = array(
|
$wgResourceModules['ext.uls.core'] = array(
|
||||||
'scripts' => array( 'resources/ext.uls.core.js', 'resources/ext.uls.languagefilter.js', 'data/langdb.js' ),
|
'scripts' => array(
|
||||||
|
'resources/ext.uls.core.js',
|
||||||
|
'resources/ext.uls.languagefilter.js',
|
||||||
|
'resources/ext.uls.data.utils.js',
|
||||||
|
),
|
||||||
'styles' => 'resources/css/ext.uls.css',
|
'styles' => 'resources/css/ext.uls.css',
|
||||||
'localBasePath' => $dir,
|
'localBasePath' => $dir,
|
||||||
'remoteExtPath' => 'UniversalLanguageSelector',
|
'remoteExtPath' => 'UniversalLanguageSelector',
|
||||||
'dependencies' => array(
|
'dependencies' => array(
|
||||||
'mediawiki.util',
|
|
||||||
'mediawiki.Uri',
|
'mediawiki.Uri',
|
||||||
'jquery.ui.autocomplete'
|
'jquery.ui.autocomplete',
|
||||||
|
'ext.uls.data',
|
||||||
),
|
),
|
||||||
'position' => 'top',
|
'position' => 'top',
|
||||||
);
|
);
|
||||||
|
|||||||
4
data/ext.uls.data.js
Normal file
4
data/ext.uls.data.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -196,7 +196,9 @@ languages:
|
|||||||
kw: [Latn, [EU]]
|
kw: [Latn, [EU]]
|
||||||
ky: [Cyrl, [AS]]
|
ky: [Cyrl, [AS]]
|
||||||
la: [Latn, [EU]]
|
la: [Latn, [EU]]
|
||||||
# Most identified with Turkey, Bulgaria, Greece, Spain and Israel, but also spoken in Latin America and elsewhere. Wikipedia is mostly in Latn, but also in Hebr. (comparable to az.)
|
# Most identified with Turkey, Bulgaria, Greece, Spain and Israel,
|
||||||
|
# but also spoken in Latin America and elsewhere.
|
||||||
|
# Wikipedia is mostly in Latn, but also in Hebr. (Comparable to az.)
|
||||||
lad: [Latn, [ME, EU, LA]]
|
lad: [Latn, [ME, EU, LA]]
|
||||||
lb: [Latn, [EU]]
|
lb: [Latn, [EU]]
|
||||||
lbe: [Cyrl, [EU]]
|
lbe: [Cyrl, [EU]]
|
||||||
@@ -207,7 +209,7 @@ languages:
|
|||||||
lij: [Latn, [EU]]
|
lij: [Latn, [EU]]
|
||||||
liv: [Latn, [EU]]
|
liv: [Latn, [EU]]
|
||||||
lmo: [Latn, [EU]]
|
lmo: [Latn, [EU]]
|
||||||
ln: [Lath, [AF]]
|
ln: [Latn, [AF]]
|
||||||
lo: [Laoo, [AS]]
|
lo: [Laoo, [AS]]
|
||||||
loz: [Latn, [AF]]
|
loz: [Latn, [AF]]
|
||||||
lt: [Latn, [EU]]
|
lt: [Latn, [EU]]
|
||||||
@@ -406,11 +408,39 @@ languages:
|
|||||||
zh-yue: [Hans, [AS]]
|
zh-yue: [Hans, [AS]]
|
||||||
zu: [Latn, [AF]]
|
zu: [Latn, [AF]]
|
||||||
|
|
||||||
# http://unicode.org/iso15924/iso15924-codes.html
|
# The codes are taken from http://unicode.org/iso15924/iso15924-codes.html .
|
||||||
|
#
|
||||||
|
# The classification is roughly based on http://www.unicode.org/charts/
|
||||||
|
# with some practical corrections.
|
||||||
scriptgroups:
|
scriptgroups:
|
||||||
Latn: 1
|
# Other is reserved
|
||||||
Cyrl: 2
|
# Large groups, one script in each
|
||||||
Arab: 3
|
Cyrillic: [Cyrl]
|
||||||
|
Arabic: [Arab]
|
||||||
|
# It's probalby different enough from Latin and Cyrillic, but user testing
|
||||||
|
# may prove otherwise.
|
||||||
|
Greek: [Grek]
|
||||||
|
# Couldn't find a better place for Goth.
|
||||||
|
Latin: [Latn, Goth]
|
||||||
|
WestCaucasian: [Armn, Geor]
|
||||||
|
# Maybe it can be unified with Arabic.
|
||||||
|
# Maybe Thaana can be moved here from SouthAsian.
|
||||||
|
# Maybe it can be unified with African.
|
||||||
|
MiddleEastern: [Hebr, Syrc]
|
||||||
|
African: [Ethi, Tfng]
|
||||||
|
# India, Nepal, Bangladesh, Sri-Lanka, Bhutan, Maldives.
|
||||||
|
#
|
||||||
|
# Thaana (Thaa, the script of Maldives) is here, even though it's RTL,
|
||||||
|
# because it's closer geographically to India. Maybe it should be moved
|
||||||
|
# to MiddleEastern or to Arabic, if that would be easier to users.
|
||||||
|
#
|
||||||
|
# Tibetan (Tibt) is here, even though it's classified as "Central Asian" by
|
||||||
|
# Unicode, because linguistically and geographically it's closely related to
|
||||||
|
# the Brahmic family.
|
||||||
|
SouthAsian: [Beng, Deva, Gujr, Guru, Knda, Mlym, Orya, Sinh, Taml, Telu, Tibt, Thaa]
|
||||||
|
SouthEastAsian: [Bugi, Java, Khmr, Laoo, Mymr, Thai]
|
||||||
|
CJK: [Hans, Hant, Kore, Jpan, Yiii]
|
||||||
|
NativeAmerican: [Cher, Cans]
|
||||||
|
|
||||||
regiongroups:
|
regiongroups:
|
||||||
# north-america
|
# north-america
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/**
|
||||||
|
* Script to create the language data in json format for ULS
|
||||||
|
*/
|
||||||
include __DIR__ . '/spyc.php';
|
include __DIR__ . '/spyc.php';
|
||||||
$data = file_get_contents( 'langdb.yaml' );
|
$data = file_get_contents( 'langdb.yaml' );
|
||||||
$parsed = spyc_load( $data );
|
$parsed = spyc_load( $data );
|
||||||
$json = json_encode( $parsed );
|
$json = json_encode( $parsed );
|
||||||
$js = "window.langdb = $json;";
|
$js = "( function ( $ ) {\n"
|
||||||
file_put_contents( 'langdb.js', $js );
|
."\t$.uls = {};\n"
|
||||||
|
."\t$.uls.data = $json;\n"
|
||||||
|
."} )( jQuery );\n";
|
||||||
|
file_put_contents( 'ext.uls.data.js', $js );
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
},
|
},
|
||||||
//FIXME This is confusing: languages and source are acturally data for ULS.
|
//FIXME This is confusing: languages and source are acturally data for ULS.
|
||||||
languages: that.languages,
|
languages: that.languages,
|
||||||
source: langdb,
|
source: $.uls.data,
|
||||||
callback: function () {
|
callback: function () {
|
||||||
// clear the search field.
|
// clear the search field.
|
||||||
$( "#languagefilter" ).val( "" );
|
$( "#languagefilter" ).val( "" );
|
||||||
|
|||||||
26
resources/ext.uls.data.utils.js
Normal file
26
resources/ext.uls.data.utils.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* @author Amir E. Aharoni
|
||||||
|
* Utilities for querying the language db.
|
||||||
|
*/
|
||||||
|
(function ( $ ) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
var scriptIndex = 0,
|
||||||
|
regionsIndex = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the script group of a script or 'Other' if it doesn't
|
||||||
|
* belong to any group.
|
||||||
|
*/
|
||||||
|
$.uls.data.groupOfScript = function( script ) {
|
||||||
|
for ( var group in $.uls.data.scriptgroups ) {
|
||||||
|
if ( $.inArray( script, $.uls.data.scriptgroups[group] ) != -1 ) {
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'Other';
|
||||||
|
}
|
||||||
|
|
||||||
|
} )( jQuery );
|
||||||
@@ -10,9 +10,31 @@
|
|||||||
|
|
||||||
module( "ext.uls", QUnit.newMwEnvironment() );
|
module( "ext.uls", QUnit.newMwEnvironment() );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Runs over all script codes mentioned in langdb and checks whether
|
||||||
|
* they belong to the 'Other' group.
|
||||||
|
*/
|
||||||
|
var orphanScript = function () {
|
||||||
|
for ( var language in $.uls.data.languages ) {
|
||||||
|
var script = $.uls.data.languages[language][0];
|
||||||
|
if ( $.uls.data.groupOfScript( script ) === 'Other' ) {
|
||||||
|
return script;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
test( "-- Initial check", function() {
|
test( "-- Initial check", function() {
|
||||||
expect( 1 );
|
expect( 1 );
|
||||||
ok( $.fn.uls, "$.fn.uls is defined" );
|
ok( $.fn.uls, "$.fn.uls is defined" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
test( "-- $.uls.data testing", function() {
|
||||||
|
expect( 1 );
|
||||||
|
|
||||||
|
// Unless we actually want some scripts to be in the 'Other' group.
|
||||||
|
strictEqual( orphanScript(), '', 'No orphan scripts found.' );
|
||||||
|
} );
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user