2 Copyright (c) 2003-2012, 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
85 * Loads a specific language file, or auto detect it. A callback is
\r
86 * then called when the file gets loaded.
\r
87 * @param {String} languageCode The code of the language file to be
\r
88 * loaded. If null or empty, autodetection will be performed. The
\r
89 * same happens if the language is not supported.
\r
90 * @param {String} defaultLanguage The language to be used if
\r
91 * languageCode is not supported or if the autodetection fails.
\r
92 * @param {Function} callback A function to be called once the
\r
93 * language file is loaded. Two parameters are passed to this
\r
94 * function: the language code and the loaded language entries.
\r
97 load : function( languageCode, defaultLanguage, callback )
\r
99 // If no languageCode - fallback to browser or default.
\r
100 // If languageCode - fallback to no-localized version or default.
\r
101 if ( !languageCode || !CKEDITOR.lang.languages[ languageCode ] )
\r
102 languageCode = this.detect( defaultLanguage, languageCode );
\r
104 if ( !this[ languageCode ] )
\r
106 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl(
\r
107 '_source/' + // @Packager.RemoveLine
\r
108 'lang/' + languageCode + '.js' ),
\r
111 callback( languageCode, this[ languageCode ] );
\r
116 callback( languageCode, this[ languageCode ] );
\r
120 * Returns the language that best fit the user language. For example,
\r
121 * suppose that the user language is "pt-br". If this language is
\r
122 * supported by the editor, it is returned. Otherwise, if only "pt" is
\r
123 * supported, it is returned instead. If none of the previous are
\r
124 * supported, a default language is then returned.
\r
125 * @param {String} defaultLanguage The default language to be returned
\r
126 * if the user language is not supported.
\r
127 * @param {String} [probeLanguage] A language code to try to use,
\r
128 * instead of the browser based autodetection.
\r
129 * @returns {String} The detected language code.
\r
131 * alert( CKEDITOR.lang.detect( 'en' ) ); // e.g., in a German browser: "de"
\r
133 detect : function( defaultLanguage, probeLanguage )
\r
135 var languages = this.languages;
\r
136 probeLanguage = probeLanguage || navigator.userLanguage || navigator.language || defaultLanguage;
\r
138 var parts = probeLanguage
\r
140 .match( /([a-z]+)(?:-([a-z]+))?/ ),
\r
144 if ( languages[ lang + '-' + locale ] )
\r
145 lang = lang + '-' + locale;
\r
146 else if ( !languages[ lang ] )
\r
149 CKEDITOR.lang.detect = lang ?
\r
150 function() { return lang; } :
\r
151 function( defaultLanguage ) { return defaultLanguage; };
\r
153 return lang || defaultLanguage;
\r