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