1 | /*
|
---|
2 | Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
---|
3 | For licensing, see LICENSE.html or http://ckeditor.com/license
|
---|
4 | */
|
---|
5 |
|
---|
6 | (function()
|
---|
7 | {
|
---|
8 | var loadedLangs = {};
|
---|
9 |
|
---|
10 | CKEDITOR.lang =
|
---|
11 | {
|
---|
12 | /**
|
---|
13 | * The list of languages available in the editor core.
|
---|
14 | * @type Object
|
---|
15 | * @example
|
---|
16 | * alert( CKEDITOR.lang.en ); // "true"
|
---|
17 | */
|
---|
18 | languages :
|
---|
19 | {
|
---|
20 | 'af' : 1,
|
---|
21 | 'ar' : 1,
|
---|
22 | 'bg' : 1,
|
---|
23 | 'bn' : 1,
|
---|
24 | 'bs' : 1,
|
---|
25 | 'ca' : 1,
|
---|
26 | 'cs' : 1,
|
---|
27 | 'da' : 1,
|
---|
28 | 'de' : 1,
|
---|
29 | 'el' : 1,
|
---|
30 | 'en-au' : 1,
|
---|
31 | 'en-ca' : 1,
|
---|
32 | 'en-uk' : 1,
|
---|
33 | 'en' : 1,
|
---|
34 | 'eo' : 1,
|
---|
35 | 'es' : 1,
|
---|
36 | 'et' : 1,
|
---|
37 | 'eu' : 1,
|
---|
38 | 'fa' : 1,
|
---|
39 | 'fi' : 1,
|
---|
40 | 'fo' : 1,
|
---|
41 | 'fr-ca' : 1,
|
---|
42 | 'fr' : 1,
|
---|
43 | 'gl' : 1,
|
---|
44 | 'gu' : 1,
|
---|
45 | 'he' : 1,
|
---|
46 | 'hi' : 1,
|
---|
47 | 'hr' : 1,
|
---|
48 | 'hu' : 1,
|
---|
49 | 'is' : 1,
|
---|
50 | 'it' : 1,
|
---|
51 | 'ja' : 1,
|
---|
52 | 'km' : 1,
|
---|
53 | 'ko' : 1,
|
---|
54 | 'lt' : 1,
|
---|
55 | 'lv' : 1,
|
---|
56 | 'mn' : 1,
|
---|
57 | 'ms' : 1,
|
---|
58 | 'nb' : 1,
|
---|
59 | 'nl' : 1,
|
---|
60 | 'no' : 1,
|
---|
61 | 'pl' : 1,
|
---|
62 | 'pt-br' : 1,
|
---|
63 | 'pt' : 1,
|
---|
64 | 'ro' : 1,
|
---|
65 | 'ru' : 1,
|
---|
66 | 'sk' : 1,
|
---|
67 | 'sl' : 1,
|
---|
68 | 'sr-latn' : 1,
|
---|
69 | 'sr' : 1,
|
---|
70 | 'sv' : 1,
|
---|
71 | 'th' : 1,
|
---|
72 | 'tr' : 1,
|
---|
73 | 'uk' : 1,
|
---|
74 | 'vi' : 1,
|
---|
75 | 'zh-cn' : 1,
|
---|
76 | 'zh' : 1
|
---|
77 | },
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Loads a specific language file, or auto detect it. A callback is
|
---|
81 | * then called when the file gets loaded.
|
---|
82 | * @param {String} languageCode The code of the language file to be
|
---|
83 | * loaded. If "autoDetect" is set to true, this language will be
|
---|
84 | * used as the default one, if the detect language is not
|
---|
85 | * available in the core.
|
---|
86 | * @param {Boolean} autoDetect Indicates that the function must try to
|
---|
87 | * detect the user language and load it instead.
|
---|
88 | * @param {Function} callback The function to be called once the
|
---|
89 | * language file is loaded. Two parameters are passed to this
|
---|
90 | * function: the language code and the loaded language entries.
|
---|
91 | * @example
|
---|
92 | */
|
---|
93 | load : function( languageCode, defaultLanguage, callback )
|
---|
94 | {
|
---|
95 | // If no languageCode - fallback to browser or default.
|
---|
96 | // If languageCode - fallback to no-localized version or default.
|
---|
97 | if ( !languageCode || !CKEDITOR.lang.languages[ languageCode ] )
|
---|
98 | languageCode = this.detect( defaultLanguage, languageCode );
|
---|
99 |
|
---|
100 | if ( !this[ languageCode ] )
|
---|
101 | {
|
---|
102 | CKEDITOR.scriptLoader.load( CKEDITOR.getUrl(
|
---|
103 | '_source/' + // @Packager.RemoveLine
|
---|
104 | 'lang/' + languageCode + '.js' ),
|
---|
105 | function()
|
---|
106 | {
|
---|
107 | callback( languageCode, this[ languageCode ] );
|
---|
108 | }
|
---|
109 | , this );
|
---|
110 | }
|
---|
111 | else
|
---|
112 | callback( languageCode, this[ languageCode ] );
|
---|
113 | },
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Returns the language that best fit the user language. For example,
|
---|
117 | * suppose that the user language is "pt-br". If this language is
|
---|
118 | * supported by the editor, it is returned. Otherwise, if only "pt" is
|
---|
119 | * supported, it is returned instead. If none of the previous are
|
---|
120 | * supported, a default language is then returned.
|
---|
121 | * @param {String} defaultLanguage The default language to be returned
|
---|
122 | * if the user language is not supported.
|
---|
123 | * @returns {String} The detected language code.
|
---|
124 | * @example
|
---|
125 | * alert( CKEDITOR.lang.detect( 'en' ) ); // e.g., in a German browser: "de"
|
---|
126 | */
|
---|
127 | detect : function( defaultLanguage, probeLanguage )
|
---|
128 | {
|
---|
129 | var languages = this.languages;
|
---|
130 | probeLanguage = probeLanguage || navigator.userLanguage || navigator.language;
|
---|
131 |
|
---|
132 | var parts = probeLanguage
|
---|
133 | .toLowerCase()
|
---|
134 | .match( /([a-z]+)(?:-([a-z]+))?/ ),
|
---|
135 | lang = parts[1],
|
---|
136 | locale = parts[2];
|
---|
137 |
|
---|
138 | if ( languages[ lang + '-' + locale ] )
|
---|
139 | lang = lang + '-' + locale;
|
---|
140 | else if ( !languages[ lang ] )
|
---|
141 | lang = null;
|
---|
142 |
|
---|
143 | CKEDITOR.lang.detect = lang ?
|
---|
144 | function() { return lang; } :
|
---|
145 | function( defaultLanguage ) { return defaultLanguage; };
|
---|
146 |
|
---|
147 | return lang || defaultLanguage;
|
---|
148 | }
|
---|
149 | };
|
---|
150 |
|
---|
151 | })();
|
---|