Universal Language Selector/Technical Design

This is the technical design document of Universal Language Selector

Core component
jQuery Plugin: $.fn.uls

$.fn.uls - jQuery extension function $.fn.uls is used for adding ULS to a trigger. A trigger is an html element- it can be a link, button, image or theoretically anything. On click of that element ULS will be show.

On binding ULS with a trigger, an instance of ULS will be associated to that trigger using data-uls attribute.

$.fn.uls is defined jquery.uls.core.js

Language category display component
jQuery Plugin: $.fn.lcd

Used for showing the search results, grouped by regions, scripts

Options

 * menu: This should the html template for the ULS popup. ULS has a default template html, but can be customized with this option.
 * onSelect: Callback function to be called when a language is selected. This get called when enter is pressed in language selector or user click on a language name. Use this to do anything with the language selection. By default this is null.
 * searchAPI: Language search API. This should be an API url that takes a parameter search with string value. And it should return a json with key as language code and value as language names. All the key value pairs should be in an object with key languagesearch. A sample API: http://translatewiki.net/w/api.php?action=languagesearch&search=finish. By default this option has null value.
 * languages: Languages to be used for ULS, default is all languages($.uls.data.autonyms). If you want to work with a subset of languages that is supported by ULS, pass that list here. The value should be an object with key as language code, value as language name.
 * quickList: Array of language codes of function that returns such an array. This option is exposed in case you need to provide a quick list of languages as suggestions - may be based on geo IP suggestions or previously used languages etc. Default value is null.

Typo correction
The language name comparison is based on Levenshtein distance. Basically it tells how many typos has a word compared to the other word. We allow one typo in the search criteria. That make 'finnish' match with a search with a typo 'finish'.

PHP's native Levenshtein distance implementation does not support multi byte characters, but in our case we need to do this search in all possible languages of the world defined in Unicode. So we wrote a custom function for Levenshtein algorithm that support multi byte unicode characters.

Naming convention
All jquery plugin components that are not dependent on mediaWiki is named with a prefix jquery.uls. For example jquery.uls.core.js jquery.uls.css etc.

Mediawiki specific customization and extension of jquery.uls is in the files with prefix ext.uls.

Coding Guidelines
Mediawiki coding guidelines for mediawiki customization part(ext.uls.*) and for jquery extension, jQuery core coding guidelines