1/* 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 * 21 * Defines the FCKLanguageManager object that is used for language 22 * operations. 23 */ 24 25var FCKLanguageManager = FCK.Language = 26{ 27 AvailableLanguages : 28 { 29 af : 'Afrikaans', 30 ar : 'Arabic', 31 bg : 'Bulgarian', 32 bn : 'Bengali/Bangla', 33 bs : 'Bosnian', 34 ca : 'Catalan', 35 cs : 'Czech', 36 da : 'Danish', 37 de : 'German', 38 el : 'Greek', 39 en : 'English', 40 'en-au' : 'English (Australia)', 41 'en-ca' : 'English (Canadian)', 42 'en-uk' : 'English (United Kingdom)', 43 eo : 'Esperanto', 44 es : 'Spanish', 45 et : 'Estonian', 46 eu : 'Basque', 47 fa : 'Persian', 48 fi : 'Finnish', 49 fo : 'Faroese', 50 fr : 'French', 51 gl : 'Galician', 52 he : 'Hebrew', 53 hi : 'Hindi', 54 hr : 'Croatian', 55 hu : 'Hungarian', 56 it : 'Italian', 57 ja : 'Japanese', 58 km : 'Khmer', 59 ko : 'Korean', 60 lt : 'Lithuanian', 61 lv : 'Latvian', 62 mn : 'Mongolian', 63 ms : 'Malay', 64 nb : 'Norwegian Bokmal', 65 nl : 'Dutch', 66 no : 'Norwegian', 67 pl : 'Polish', 68 pt : 'Portuguese (Portugal)', 69 'pt-br' : 'Portuguese (Brazil)', 70 ro : 'Romanian', 71 ru : 'Russian', 72 sk : 'Slovak', 73 sl : 'Slovenian', 74 sr : 'Serbian (Cyrillic)', 75 'sr-latn' : 'Serbian (Latin)', 76 sv : 'Swedish', 77 th : 'Thai', 78 tr : 'Turkish', 79 uk : 'Ukrainian', 80 vi : 'Vietnamese', 81 zh : 'Chinese Traditional', 82 'zh-cn' : 'Chinese Simplified' 83 }, 84 85 GetActiveLanguage : function() 86 { 87 if ( FCKConfig.AutoDetectLanguage ) 88 { 89 var sUserLang ; 90 91 // IE accepts "navigator.userLanguage" while Gecko "navigator.language". 92 if ( navigator.userLanguage ) 93 sUserLang = navigator.userLanguage.toLowerCase() ; 94 else if ( navigator.language ) 95 sUserLang = navigator.language.toLowerCase() ; 96 else 97 { 98 // Firefox 1.0 PR has a bug: it doens't support the "language" property. 99 return FCKConfig.DefaultLanguage ; 100 } 101 102 // Some language codes are set in 5 characters, 103 // like "pt-br" for Brazilian Portuguese. 104 if ( sUserLang.length >= 5 ) 105 { 106 sUserLang = sUserLang.substr(0,5) ; 107 if ( this.AvailableLanguages[sUserLang] ) return sUserLang ; 108 } 109 110 // If the user's browser is set to, for example, "pt-br" but only the 111 // "pt" language file is available then get that file. 112 if ( sUserLang.length >= 2 ) 113 { 114 sUserLang = sUserLang.substr(0,2) ; 115 if ( this.AvailableLanguages[sUserLang] ) return sUserLang ; 116 } 117 } 118 119 return this.DefaultLanguage ; 120 }, 121 122 TranslateElements : function( targetDocument, tag, propertyToSet, encode ) 123 { 124 var e = targetDocument.getElementsByTagName(tag) ; 125 var sKey, s ; 126 for ( var i = 0 ; i < e.length ; i++ ) 127 { 128 // The extra () is to avoid a warning with strict error checking. This is ok. 129 if ( (sKey = e[i].getAttribute( 'fckLang' )) ) 130 { 131 // The extra () is to avoid a warning with strict error checking. This is ok. 132 if ( (s = FCKLang[ sKey ]) ) 133 { 134 if ( encode ) 135 s = FCKTools.HTMLEncode( s ) ; 136 e[i][ propertyToSet ] = s ; 137 } 138 } 139 } 140 }, 141 142 TranslatePage : function( targetDocument ) 143 { 144 this.TranslateElements( targetDocument, 'INPUT', 'value' ) ; 145 this.TranslateElements( targetDocument, 'SPAN', 'innerHTML' ) ; 146 this.TranslateElements( targetDocument, 'LABEL', 'innerHTML' ) ; 147 this.TranslateElements( targetDocument, 'OPTION', 'innerHTML', true ) ; 148 this.TranslateElements( targetDocument, 'LEGEND', 'innerHTML' ) ; 149 }, 150 151 Initialize : function() 152 { 153 if ( this.AvailableLanguages[ FCKConfig.DefaultLanguage ] ) 154 this.DefaultLanguage = FCKConfig.DefaultLanguage ; 155 else 156 this.DefaultLanguage = 'en' ; 157 158 this.ActiveLanguage = new Object() ; 159 this.ActiveLanguage.Code = this.GetActiveLanguage() ; 160 this.ActiveLanguage.Name = this.AvailableLanguages[ this.ActiveLanguage.Code ] ; 161 } 162} ; 163