00001 /******************************************************************************* 00002 00003 @file ULocale.d 00004 00005 Copyright (c) 2004 Kris Bell 00006 00007 This software is provided 'as-is', without any express or implied 00008 warranty. In no event will the authors be held liable for damages 00009 of any kind arising from the use of this software. 00010 00011 Permission is hereby granted to anyone to use this software for any 00012 purpose, including commercial applications, and to alter it and/or 00013 redistribute it freely, subject to the following restrictions: 00014 00015 1. The origin of this software must not be misrepresented; you must 00016 not claim that you wrote the original software. If you use this 00017 software in a product, an acknowledgment within documentation of 00018 said product would be appreciated but is not required. 00019 00020 2. Altered source versions must be plainly marked as such, and must 00021 not be misrepresented as being the original software. 00022 00023 3. This notice may not be removed or altered from any distribution 00024 of the source. 00025 00026 4. Derivative works are permitted, but they must carry this notice 00027 in full and credit the original source. 00028 00029 00030 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00031 00032 00033 @version Initial version, October 2004 00034 @author Kris 00035 00036 Note that this package and documentation is built around the ICU 00037 project (http://oss.software.ibm.com/icu/). Below is the license 00038 statement as specified by that software: 00039 00040 00041 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00042 00043 00044 ICU License - ICU 1.8.1 and later 00045 00046 COPYRIGHT AND PERMISSION NOTICE 00047 00048 Copyright (c) 1995-2003 International Business Machines Corporation and 00049 others. 00050 00051 All rights reserved. 00052 00053 Permission is hereby granted, free of charge, to any person obtaining a 00054 copy of this software and associated documentation files (the 00055 "Software"), to deal in the Software without restriction, including 00056 without limitation the rights to use, copy, modify, merge, publish, 00057 distribute, and/or sell copies of the Software, and to permit persons 00058 to whom the Software is furnished to do so, provided that the above 00059 copyright notice(s) and this permission notice appear in all copies of 00060 the Software and that both the above copyright notice(s) and this 00061 permission notice appear in supporting documentation. 00062 00063 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00064 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00065 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 00066 OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00067 HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL 00068 INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING 00069 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00070 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00071 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00072 00073 Except as contained in this notice, the name of a copyright holder 00074 shall not be used in advertising or otherwise to promote the sale, use 00075 or other dealings in this Software without prior written authorization 00076 of the copyright holder. 00077 00078 ---------------------------------------------------------------------- 00079 00080 All trademarks and registered trademarks mentioned herein are the 00081 property of their respective owners. 00082 00083 *******************************************************************************/ 00084 00085 module mango.icu.ULocale; 00086 00087 private import mango.icu.ICU; 00088 00089 /******************************************************************************* 00090 00091 Note that this is a struct rather than a class. This is so 00092 that one can easily construct these on the stack, plus the 00093 'convenience' instances can be created statically. 00094 00095 *******************************************************************************/ 00096 00097 struct ULocale 00098 { 00099 public char[] name; 00100 00101 /*********************************************************************** 00102 00103 ***********************************************************************/ 00104 00105 public static ULocale Root = {""}; 00106 public static ULocale Default = {null}; 00107 public static ULocale English = {"en"}; 00108 public static ULocale Chinese = {"zh"}; 00109 public static ULocale French = {"fr"}; 00110 public static ULocale German = {"de"}; 00111 public static ULocale Italian = {"it"}; 00112 public static ULocale Japanese = {"ja"}; 00113 public static ULocale Korean = {"ko"}; 00114 public static ULocale SimplifiedChinese = {"zh_CN"}; 00115 public static ULocale TraditionalChinese = {"zh_TW"}; 00116 public static ULocale Canada = {"en_CA"}; 00117 public static ULocale CanadaFrench = {"fr_CA"}; 00118 public static ULocale China = {"zh_CN"}; 00119 public static ULocale PRC = {"zh_CN"}; 00120 public static ULocale France = {"fr_FR"}; 00121 public static ULocale Germany = {"de_DE"}; 00122 public static ULocale Italy = {"it_IT"}; 00123 public static ULocale Japan = {"jp_JP"}; 00124 public static ULocale Korea = {"ko_KR"}; 00125 public static ULocale Taiwan = {"zh_TW"}; 00126 public static ULocale UK = {"en_GB"}; 00127 public static ULocale US = {"en_US"}; 00128 00129 /*********************************************************************** 00130 00131 ***********************************************************************/ 00132 00133 public enum Type 00134 { 00135 Actual = 0, 00136 Valid = 1, 00137 Requested = 2, 00138 } 00139 00140 /*********************************************************************** 00141 00142 ***********************************************************************/ 00143 00144 public const uint LanguageCapacity = 12; 00145 public const uint CountryCapacity = 4; 00146 public const uint FullNameCapacity = 56; 00147 public const uint ScriptCapacity = 6; 00148 public const uint KeywordsCapacity = 50; 00149 public const uint KeywordAndValuesCapacity = 100; 00150 public const char KeywordItemSeperator = ':'; 00151 public const char KeywordSeperator = '@'; 00152 public const char KeywordAssign = '='; 00153 00154 00155 /*********************************************************************** 00156 00157 ***********************************************************************/ 00158 00159 static void getDefault (inout ULocale locale) 00160 { 00161 locale.name = ICU.toArray (uloc_getDefault()); 00162 if (! locale.name) 00163 ICU.exception ("failed to get default locale"); 00164 } 00165 00166 /*********************************************************************** 00167 00168 ***********************************************************************/ 00169 00170 static void setDefault (inout ULocale locale) 00171 { 00172 ICU.Error e; 00173 00174 uloc_setDefault (ICU.toString(locale.name), e); 00175 00176 if (ICU.isError (e)) 00177 ICU.exception ("invalid locale '"~locale.name~"'"); 00178 } 00179 00180 00181 00182 /*********************************************************************** 00183 00184 Bind the ICU functions from a shared library. This is 00185 complicated by the issues regarding D and DLLs on the 00186 Windows platform 00187 00188 ***********************************************************************/ 00189 00190 private static void* library; 00191 00192 /*********************************************************************** 00193 00194 ***********************************************************************/ 00195 00196 private static extern (C) 00197 { 00198 char* function () uloc_getDefault; 00199 void function (char*, inout ICU.Error) uloc_setDefault; 00200 } 00201 00202 /********************************************************************** 00203 00204 ***********************************************************************/ 00205 00206 static FunctionLoader.Bind[] targets = 00207 [ 00208 {cast(void**) &uloc_getDefault, "uloc_getDefault"}, 00209 {cast(void**) &uloc_setDefault, "uloc_setDefault"}, 00210 ]; 00211 00212 /*********************************************************************** 00213 00214 ***********************************************************************/ 00215 00216 static this () 00217 { 00218 library = FunctionLoader.bind (ICU.icuuc, targets); 00219 } 00220 00221 /*********************************************************************** 00222 00223 ***********************************************************************/ 00224 00225 static ~this () 00226 { 00227 FunctionLoader.unbind (library); 00228 } 00229 }