2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
8 var loadedLangs = {};
\r
11 * @namespace Holds language related functions.
\r
16 * The list of languages available in the editor core.
\r
19 * alert( CKEDITOR.lang.en ); // "true"
\r
84 * Loads a specific language file, or auto detect it. A callback is
\r
85 * then called when the file gets loaded.
\r
86 * @param {String} languageCode The code of the language file to be
\r
87 * loaded. If null or empty, autodetection will be performed. The
\r
88 * same happens if the language is not supported.
\r
89 * @param {String} defaultLanguage The language to be used if
\r
90 * languageCode is not supported or if the autodetection fails.
\r
91 * @param {Function} callback A function to be called once the
\r
92 * language file is loaded. Two parameters are passed to this
\r
93 * function: the language code and the loaded language entries.
\r
96 load : function( languageCode, defaultLanguage, callback )
\r
98 // If no languageCode - fallback to browser or default.
\r
99 // If languageCode - fallback to no-localized version or default.
\r
100 if ( !languageCode || !CKEDITOR.lang.languages[ languageCode ] )
\r
101 languageCode = this.detect( defaultLanguage, languageCode );
\r
103 if ( !this[ languageCode ] )
\r
105 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl(
\r
106 '_source/' + // @Packager.RemoveLine
\r
107 'lang/' + languageCode + '.js' ),
\r
110 callback( languageCode, this[ languageCode ] );
\r
115 callback( languageCode, this[ languageCode ] );
\r
119 * Returns the language that best fit the user language. For example,
\r
120 * suppose that the user language is "pt-br". If this language is
\r
121 * supported by the editor, it is returned. Otherwise, if only "pt" is
\r
122 * supported, it is returned instead. If none of the previous are
\r
123 * supported, a default language is then returned.
\r
124 * @param {String} defaultLanguage The default language to be returned
\r
125 * if the user language is not supported.
\r
126 * @param {String} [probeLanguage] A language code to try to use,
\r
127 * instead of the browser based autodetection.
\r
128 * @returns {String} The detected language code.
\r
130 * alert( CKEDITOR.lang.detect( 'en' ) ); // e.g., in a German browser: "de"
\r
132 detect : function( defaultLanguage, probeLanguage )
\r
134 var languages = this.languages;
\r
135 probeLanguage = probeLanguage || navigator.userLanguage || navigator.language;
\r
137 var parts = probeLanguage
\r
139 .match( /([a-z]+)(?:-([a-z]+))?/ ),
\r
143 if ( languages[ lang + '-' + locale ] )
\r
144 lang = lang + '-' + locale;
\r
145 else if ( !languages[ lang ] )
\r
148 CKEDITOR.lang.detect = lang ?
\r
149 function() { return lang; } :
\r
150 function( defaultLanguage ) { return defaultLanguage; };
\r
152 return lang || defaultLanguage;
\r