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 ( !languageCode ) 96 languageCode = this.detect( defaultLanguage ); 97 98 if ( !this[ languageCode ] ) 99 { 100 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( 102 'lang/' + languageCode + '.js' ), 103 function() 104 { 105 callback( languageCode, this[ languageCode ] ); 106 } 107 , this ); 108 } 109 else 110 callback( languageCode, this[ languageCode ] ); 111 }, 112 113 /** 114 * Returns the language that best fit the user language. For example, 115 * suppose that the user language is "pt-br". If this language is 116 * supported by the editor, it is returned. Otherwise, if only "pt" is 117 * supported, it is returned instead. If none of the previous are 118 * supported, a default language is then returned. 119 * @param {String} defaultLanguage The default language to be returned 120 * if the user language is not supported. 121 * @returns {String} The detected language code. 122 * @example 123 * alert( CKEDITOR.lang.detect( 'en' ) ); // e.g., in a German browser: "de" 124 */ 125 detect : function( defaultLanguage ) 126 { 127 var languages = this.languages; 128 129 var parts = ( navigator.userLanguage || navigator.language ) 130 .toLowerCase() 131 .match( /([a-z]+)(?:-([a-z]+))?/ ), 132 lang = parts[1], 133 locale = parts[2]; 134 135 if ( languages[ lang + '-' + locale ] ) 136 lang = lang + '-' + locale; 137 else if ( !languages[ lang ] ) 138 lang = null; 139 140 CKEDITOR.lang.detect = lang ? 141 function() { return lang; } : 142 function( defaultLanguage ) { return defaultLanguage; }; 143 144 return lang || defaultLanguage; 145 } 146 }; 147 148 })(); 149