X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Flang.js;h=55aaf5db0210d5a7e6653230810fae91881b664c;hb=fb481ba0a7d298e3e7b9034fcb9f2afdc6e8e796;hp=6ada788b7ae27fb018d0420003c2c07d524f4782;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/core/lang.js b/_source/core/lang.js index 6ada788..55aaf5d 100644 --- a/_source/core/lang.js +++ b/_source/core/lang.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -7,6 +7,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { var loadedLangs = {}; + /** + * @namespace Holds language related functions. + */ CKEDITOR.lang = { /** @@ -24,12 +27,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license 'bs' : 1, 'ca' : 1, 'cs' : 1, + 'cy' : 1, 'da' : 1, 'de' : 1, 'el' : 1, 'en-au' : 1, 'en-ca' : 1, - 'en-uk' : 1, + 'en-gb' : 1, 'en' : 1, 'eo' : 1, 'es' : 1, @@ -49,8 +53,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license 'is' : 1, 'it' : 1, 'ja' : 1, + 'ka' : 1, 'km' : 1, 'ko' : 1, + 'ku' : 1, 'lt' : 1, 'lv' : 1, 'mn' : 1, @@ -70,6 +76,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license 'sv' : 1, 'th' : 1, 'tr' : 1, + 'ug' : 1, 'uk' : 1, 'vi' : 1, 'zh-cn' : 1, @@ -80,24 +87,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * Loads a specific language file, or auto detect it. A callback is * then called when the file gets loaded. * @param {String} languageCode The code of the language file to be - * loaded. If "autoDetect" is set to true, this language will be - * used as the default one, if the detect language is not - * available in the core. - * @param {Boolean} autoDetect Indicates that the function must try to - * detect the user language and load it instead. - * @param {Function} callback The function to be called once the + * loaded. If null or empty, autodetection will be performed. The + * same happens if the language is not supported. + * @param {String} defaultLanguage The language to be used if + * languageCode is not supported or if the autodetection fails. + * @param {Function} callback A function to be called once the * language file is loaded. Two parameters are passed to this * function: the language code and the loaded language entries. * @example */ load : function( languageCode, defaultLanguage, callback ) { - if ( !languageCode ) - languageCode = this.detect( defaultLanguage ); + // If no languageCode - fallback to browser or default. + // If languageCode - fallback to no-localized version or default. + if ( !languageCode || !CKEDITOR.lang.languages[ languageCode ] ) + languageCode = this.detect( defaultLanguage, languageCode ); if ( !this[ languageCode ] ) { CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( + '_source/' + // @Packager.RemoveLine 'lang/' + languageCode + '.js' ), function() { @@ -117,15 +126,18 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * supported, a default language is then returned. * @param {String} defaultLanguage The default language to be returned * if the user language is not supported. + * @param {String} [probeLanguage] A language code to try to use, + * instead of the browser based autodetection. * @returns {String} The detected language code. * @example * alert( CKEDITOR.lang.detect( 'en' ) ); // e.g., in a German browser: "de" */ - detect : function( defaultLanguage ) + detect : function( defaultLanguage, probeLanguage ) { var languages = this.languages; + probeLanguage = probeLanguage || navigator.userLanguage || navigator.language || defaultLanguage; - var parts = ( navigator.userLanguage || navigator.language ) + var parts = probeLanguage .toLowerCase() .match( /([a-z]+)(?:-([a-z]+))?/ ), lang = parts[1],