1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2007, 2009, 2010, 2011, 2013, 2014, 2016 Synacor, Inc. 5 * 6 * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: https://www.zimbra.com/license 9 * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 10 * have been added to cover use of software over a computer network and provide for limited attribution 11 * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. 12 * 13 * Software distributed under the License is distributed on an "AS IS" basis, 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. 15 * See the License for the specific language governing rights and limitations under the License. 16 * The Original Code is Zimbra Open Source Web Client. 17 * The Initial Developer of the Original Code is Zimbra, Inc. All rights to the Original Code were 18 * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015. 19 * 20 * All portions of the code are Copyright (C) 2007, 2009, 2010, 2011, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * Default constructor. 26 * @class 27 * This class represents a locale. 28 * 29 * @param {String} id the id 30 * @param {String} name the name 31 * @param {String} image the image 32 * @param {String} localName the name in user's locale 33 * 34 * @see ZmLocale.create 35 */ 36 ZmLocale = function(id, name, image, localName) { 37 this.id = id; 38 this.name = name; 39 this.localName = localName; 40 this._image = image; 41 }; 42 43 //List of RTL supporting languages 44 ZmLocale.RTLLANGUAGES = { 45 ar:"Arabic", 46 iw:"Hebrew" 47 }; 48 49 ZmLocale.localeMap = {}; 50 ZmLocale.languageMap = {}; 51 52 /** 53 * Creates the locale. 54 * 55 * @param {String} id the locale id (for example, <code>en_US</code>) 56 * @param {String} name the locale name 57 * @param {String} localName the name in user's locale 58 */ 59 ZmLocale.create = 60 function(id, name, localName) { 61 var index = id.indexOf("_"); 62 var languageId; 63 var country = null; 64 if (index == -1) { 65 languageId = id; 66 } 67 else { 68 languageId = id.substr(0, index); 69 country = id.substring(id.length - 2); 70 } 71 72 var languageObj = ZmLocale.languageMap[languageId]; 73 if (!languageObj) { 74 languageObj = new ZmLocale(languageId, name, null, localName); 75 ZmLocale.languageMap[languageId] = languageObj; 76 ZmLocale.localeMap[id] = languageObj; 77 } 78 if (country) { 79 var localeObj = new ZmLocale(id, name, null, localName); 80 languageObj._add(localeObj); 81 ZmLocale.localeMap[id] = localeObj; 82 return localeObj; 83 } 84 else { 85 languageObj.name = name; 86 return languageObj; 87 } 88 }; 89 90 /** 91 * Checks if there are more than one selectable locale. 92 * 93 * @return {Boolean} <code>true</code> if there are more than one selectable locale 94 */ 95 ZmLocale.hasChoices = 96 function() { 97 var count = 0; 98 for (var id in ZmLocale.localeMap) { 99 var locale = ZmLocale.localeMap[id]; 100 if (!locale.locales) { 101 count++; 102 } 103 if (count >= 2) { 104 return true; 105 } 106 } 107 return false; 108 }; 109 110 /** 111 * Gets the image. 112 * 113 * @return {String} the image 114 */ 115 ZmLocale.prototype.getImage = 116 function() { 117 return this._image; 118 }; 119 120 /** 121 * Gets the name in both the locale itself, and in the local (user) locale. 122 * 123 * @return {String} the name 124 */ 125 ZmLocale.prototype.getNativeAndLocalName = 126 function() { 127 if (this.name == this.localName) { 128 /* don't show both if they are the same - it looks extremely funny */ 129 return this.name; 130 } 131 return [this.localName, " - ", this.name].join(""); 132 }; 133 134 ZmLocale.prototype._add = 135 function(locale) { 136 (this.locales = this.locales || []).push(locale); 137 }; 138 139 ZmLocale.prototype._getLanguageImage = 140 function() { 141 switch (this.id) { 142 // Arabic was omitted from this list...not sure what country to use. 143 case "sq": return "FlagAL"; // Albanian -> Albania 144 case "be": return "FlagBY"; // Belarusian -> Belarus 145 case "bg": return "FlagBG"; // Bulgarian -> Bulgaria 146 case "ca": return "FlagES"; // Catalan -> Spain 147 case "zh": return "FlagCN"; // Chinese -> China 148 case "hr": return "FlagHR"; // Croatian -> Croatia 149 case "cs": return "FlagCZ"; // Czech -> Czech Republic 150 case "da": return "FlagDK"; // Danish -> Denmark 151 case "nl": return "FlagNL"; // Dutch -> Netherlands 152 case "en": return "FlagUS"; // English -> USA 153 case "et": return "FlagEE"; // Estonian -> Estonia 154 case "fi": return "FlagFI"; // Finnish -> Finland 155 case "fr": return "FlagFR"; // French -> France 156 case "de": return "FlagDE"; // German -> Germany 157 case "el": return "FlagGR"; // Greek -> Greece 158 case "iw": return "FlagIL"; // Hebrew -> Israel 159 case "hi": return "FlagIN"; // Hindi -> India 160 case "hu": return "FlagHU"; // Hungarian -> Hungary 161 case "id": return "FlagID"; // Indonesian -> Indonesia 162 case "is": return "FlagIS"; // Icelandic -> Iceland 163 case "it": return "FlagIT"; // Italian -> Italy 164 case "ja": return "FlagJP"; // Japanese -> Japan 165 case "ko": return "FlagKR"; // Korean -> South Korea 166 case "lv": return "FlagLV"; // Latvian -> Latvia 167 case "lt": return "FlagLT"; // Lithuanian -> Lithuania 168 case "mk": return "FlagMK"; // Macedonian -> Macedonia 169 case "no": return "FlagNO"; // Norwegian -> Norway 170 case "pl": return "FlagPL"; // Polish -> Poland 171 case "pt": return "FlagPT"; // Portugese -> Portugal 172 case "ro": return "FlagRO"; // Romanian -> Romania 173 case "ru": return "FlagRU"; // Russian -> Russia 174 case "sk": return "FlagSK"; // Slovak -> Slovakia 175 case "sl": return "FlagSI"; // Slovenian -> Slovenia 176 case "es": return "FlagES"; // Spanish -> Spain 177 case "sv": return "FlagSE"; // Swedish -> Sweden 178 case "th": return "FlagTH"; // Thai -> Thailand 179 case "tr": return "FlagTR"; // Turkish -> Turkey 180 case "uk": return "FlagUA"; // Ukrainian -> Ukraine 181 case "vi": return "FlagVN"; // Vietnamese -> Vietnam 182 default: return "FlagNone"; 183 } 184 }; 185