1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_comphelper.hxx" 30*cdf0e10cSrcweir #include <comphelper/locale.hxx> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir //_______________________________________________ 33*cdf0e10cSrcweir // includes 34*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir //_______________________________________________ 37*cdf0e10cSrcweir // namespace 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir namespace comphelper{ 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir //----------------------------------------------- 42*cdf0e10cSrcweir const sal_Unicode Locale::SEPERATOR_LC = (sal_Unicode)'-'; 43*cdf0e10cSrcweir const sal_Unicode Locale::SEPERATOR_CV = (sal_Unicode)'_'; 44*cdf0e10cSrcweir const sal_Unicode Locale::SEPERATOR_CV_LINUX = (sal_Unicode)'.'; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir //----------------------------------------------- 47*cdf0e10cSrcweir const Locale Locale::X_DEFAULT() 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir static Locale aLocale( 50*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("x"), 51*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("default")); 52*cdf0e10cSrcweir return aLocale; 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir //----------------------------------------------- 56*cdf0e10cSrcweir const Locale Locale::EN() 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir static Locale aLocale( 59*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("en"), 60*cdf0e10cSrcweir ::rtl::OUString()); 61*cdf0e10cSrcweir return aLocale; 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //----------------------------------------------- 65*cdf0e10cSrcweir const Locale Locale::EN_US() 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir static Locale aLocale( 68*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("en"), 69*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("US")); 70*cdf0e10cSrcweir return aLocale; 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir //----------------------------------------------- 74*cdf0e10cSrcweir const Locale Locale::DE_DE() 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir static Locale aLocale( 77*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("de"), 78*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("DE")); 79*cdf0e10cSrcweir return aLocale; 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir //----------------------------------------------- 83*cdf0e10cSrcweir const Locale Locale::DE_CH() 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir static Locale aLocale( 86*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("de"), 87*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("CH")); 88*cdf0e10cSrcweir return aLocale; 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir //----------------------------------------------- 92*cdf0e10cSrcweir const Locale Locale::DE_AT() 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir static Locale aLocale( 95*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("de"), 96*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("AT")); 97*cdf0e10cSrcweir return aLocale; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir //----------------------------------------------- 101*cdf0e10cSrcweir const Locale Locale::AR() 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir static Locale aLocale( 104*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("ar"), 105*cdf0e10cSrcweir ::rtl::OUString()); 106*cdf0e10cSrcweir return aLocale; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir //----------------------------------------------- 110*cdf0e10cSrcweir const Locale Locale::CA() 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir static Locale aLocale( 113*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("ca"), 114*cdf0e10cSrcweir ::rtl::OUString()); 115*cdf0e10cSrcweir return aLocale; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir //----------------------------------------------- 119*cdf0e10cSrcweir const Locale Locale::CS() 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir static Locale aLocale( 122*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("cs"), 123*cdf0e10cSrcweir ::rtl::OUString()); 124*cdf0e10cSrcweir return aLocale; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir //----------------------------------------------- 128*cdf0e10cSrcweir const Locale Locale::DA() 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir static Locale aLocale( 131*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("da"), 132*cdf0e10cSrcweir ::rtl::OUString()); 133*cdf0e10cSrcweir return aLocale; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir //----------------------------------------------- 137*cdf0e10cSrcweir const Locale Locale::EL() 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir static Locale aLocale( 140*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("el"), 141*cdf0e10cSrcweir ::rtl::OUString()); 142*cdf0e10cSrcweir return aLocale; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir //----------------------------------------------- 146*cdf0e10cSrcweir const Locale Locale::ES() 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir static Locale aLocale( 149*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("es"), 150*cdf0e10cSrcweir ::rtl::OUString()); 151*cdf0e10cSrcweir return aLocale; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir //----------------------------------------------- 155*cdf0e10cSrcweir const Locale Locale::FI() 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir static Locale aLocale( 158*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("fi"), 159*cdf0e10cSrcweir ::rtl::OUString()); 160*cdf0e10cSrcweir return aLocale; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir //----------------------------------------------- 164*cdf0e10cSrcweir const Locale Locale::FR() 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir static Locale aLocale( 167*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("fr"), 168*cdf0e10cSrcweir ::rtl::OUString()); 169*cdf0e10cSrcweir return aLocale; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir //----------------------------------------------- 173*cdf0e10cSrcweir const Locale Locale::HE() 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir static Locale aLocale( 176*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("he"), 177*cdf0e10cSrcweir ::rtl::OUString()); 178*cdf0e10cSrcweir return aLocale; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir //----------------------------------------------- 182*cdf0e10cSrcweir const Locale Locale::HI_IN() 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir static Locale aLocale( 185*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("hi"), 186*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("IN")); 187*cdf0e10cSrcweir return aLocale; 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir //----------------------------------------------- 191*cdf0e10cSrcweir const Locale Locale::HU() 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir static Locale aLocale( 194*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("hu"), 195*cdf0e10cSrcweir ::rtl::OUString()); 196*cdf0e10cSrcweir return aLocale; 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir //----------------------------------------------- 200*cdf0e10cSrcweir const Locale Locale::IT() 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir static Locale aLocale( 203*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("it"), 204*cdf0e10cSrcweir ::rtl::OUString()); 205*cdf0e10cSrcweir return aLocale; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir //----------------------------------------------- 209*cdf0e10cSrcweir const Locale Locale::JA() 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir static Locale aLocale( 212*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("ja"), 213*cdf0e10cSrcweir ::rtl::OUString()); 214*cdf0e10cSrcweir return aLocale; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir //----------------------------------------------- 218*cdf0e10cSrcweir const Locale Locale::KO() 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir static Locale aLocale( 221*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("ko"), 222*cdf0e10cSrcweir ::rtl::OUString()); 223*cdf0e10cSrcweir return aLocale; 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir //----------------------------------------------- 227*cdf0e10cSrcweir const Locale Locale::NL() 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir static Locale aLocale( 230*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("nl"), 231*cdf0e10cSrcweir ::rtl::OUString()); 232*cdf0e10cSrcweir return aLocale; 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir //----------------------------------------------- 236*cdf0e10cSrcweir const Locale Locale::PL() 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir static Locale aLocale( 239*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("pl"), 240*cdf0e10cSrcweir ::rtl::OUString()); 241*cdf0e10cSrcweir return aLocale; 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir //----------------------------------------------- 245*cdf0e10cSrcweir const Locale Locale::PT() 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir static Locale aLocale( 248*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("pt"), 249*cdf0e10cSrcweir ::rtl::OUString()); 250*cdf0e10cSrcweir return aLocale; 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir //----------------------------------------------- 254*cdf0e10cSrcweir const Locale Locale::PT_BR() 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir static Locale aLocale( 257*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("pt"), 258*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("BR")); 259*cdf0e10cSrcweir return aLocale; 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir //----------------------------------------------- 263*cdf0e10cSrcweir const Locale Locale::RU() 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir static Locale aLocale( 266*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("ru"), 267*cdf0e10cSrcweir ::rtl::OUString()); 268*cdf0e10cSrcweir return aLocale; 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir //----------------------------------------------- 272*cdf0e10cSrcweir const Locale Locale::SK() 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir static Locale aLocale( 275*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("sk"), 276*cdf0e10cSrcweir ::rtl::OUString()); 277*cdf0e10cSrcweir return aLocale; 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir //----------------------------------------------- 281*cdf0e10cSrcweir const Locale Locale::SL() 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir static Locale aLocale( 284*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("sl"), 285*cdf0e10cSrcweir ::rtl::OUString()); 286*cdf0e10cSrcweir return aLocale; 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir //----------------------------------------------- 290*cdf0e10cSrcweir const Locale Locale::SV() 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir static Locale aLocale( 293*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("sv"), 294*cdf0e10cSrcweir ::rtl::OUString()); 295*cdf0e10cSrcweir return aLocale; 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir //----------------------------------------------- 299*cdf0e10cSrcweir const Locale Locale::TH() 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir static Locale aLocale( 302*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("th"), 303*cdf0e10cSrcweir ::rtl::OUString()); 304*cdf0e10cSrcweir return aLocale; 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir //----------------------------------------------- 308*cdf0e10cSrcweir const Locale Locale::TR() 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir static Locale aLocale( 311*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("tr"), 312*cdf0e10cSrcweir ::rtl::OUString()); 313*cdf0e10cSrcweir return aLocale; 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir //----------------------------------------------- 317*cdf0e10cSrcweir const Locale Locale::X_COMMENT() 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir static Locale aLocale( 320*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("x"), 321*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("comment")); 322*cdf0e10cSrcweir return aLocale; 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir //----------------------------------------------- 326*cdf0e10cSrcweir const Locale Locale::X_TRANSLATE() 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir static Locale aLocale( 329*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("x"), 330*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("translate")); 331*cdf0e10cSrcweir return aLocale; 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir //----------------------------------------------- 335*cdf0e10cSrcweir const Locale Locale::X_NOTRANSLATE() 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir static Locale aLocale( 338*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("x"), 339*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("notranslate")); 340*cdf0e10cSrcweir return aLocale; 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir //----------------------------------------------- 344*cdf0e10cSrcweir const Locale Locale::ZH_CN() 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir static Locale aLocale( 347*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("zh"), 348*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("CN")); 349*cdf0e10cSrcweir return aLocale; 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir //----------------------------------------------- 353*cdf0e10cSrcweir const Locale Locale::ZH_TW() 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir static Locale aLocale( 356*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("zh"), 357*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("TW")); 358*cdf0e10cSrcweir return aLocale; 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir //----------------------------------------------- 362*cdf0e10cSrcweir Locale::Locale(const ::rtl::OUString& sISO) 363*cdf0e10cSrcweir throw(Locale::MalFormedLocaleException) 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir fromISO(sISO); 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir //----------------------------------------------- 369*cdf0e10cSrcweir Locale::Locale(const ::rtl::OUString& sLanguage, 370*cdf0e10cSrcweir const ::rtl::OUString& sCountry , 371*cdf0e10cSrcweir const ::rtl::OUString& sVariant ) 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir // Use set methods to check values too! 374*cdf0e10cSrcweir setLanguage(sLanguage); 375*cdf0e10cSrcweir setCountry (sCountry ); 376*cdf0e10cSrcweir setVariant (sVariant ); 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir //----------------------------------------------- 380*cdf0e10cSrcweir Locale::Locale() 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir // Initialize instance ... otherwhise user will 383*cdf0e10cSrcweir // may be get exceptions if he e.g. copy this instance ... 384*cdf0e10cSrcweir (*this) = X_NOTRANSLATE(); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir //----------------------------------------------- 388*cdf0e10cSrcweir Locale::Locale(const Locale& aCopy) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir (*this) = aCopy; // recycle assign operator 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir //----------------------------------------------- 394*cdf0e10cSrcweir ::rtl::OUString Locale::getLanguage() const 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir return m_sLanguage; 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir //----------------------------------------------- 400*cdf0e10cSrcweir ::rtl::OUString Locale::getCountry() const 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir return m_sCountry; 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir //----------------------------------------------- 406*cdf0e10cSrcweir ::rtl::OUString Locale::getVariant() const 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir return m_sVariant; 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir //----------------------------------------------- 412*cdf0e10cSrcweir void Locale::setLanguage(const ::rtl::OUString& sLanguage) 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir m_sLanguage = sLanguage; 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir //----------------------------------------------- 418*cdf0e10cSrcweir void Locale::setCountry(const ::rtl::OUString& sCountry) 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir m_sCountry = sCountry; 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir //----------------------------------------------- 424*cdf0e10cSrcweir void Locale::setVariant(const ::rtl::OUString& sVariant) 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir m_sVariant = sVariant; 427*cdf0e10cSrcweir } 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir //----------------------------------------------- 430*cdf0e10cSrcweir /* Attention: Use own interface methods to set the 431*cdf0e10cSrcweir different parts of this locale. Because the 432*cdf0e10cSrcweir check the incoming value and throw an exception 433*cdf0e10cSrcweir automaticly ... 434*cdf0e10cSrcweir */ 435*cdf0e10cSrcweir void Locale::fromISO(const ::rtl::OUString& sISO) 436*cdf0e10cSrcweir throw(Locale::MalFormedLocaleException) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir m_sLanguage = ::rtl::OUString(); 439*cdf0e10cSrcweir m_sCountry = ::rtl::OUString(); 440*cdf0e10cSrcweir m_sVariant = ::rtl::OUString(); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir ::rtl::OUString sParser(sISO); 443*cdf0e10cSrcweir sParser.trim(); 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir sal_Int32 nStart = 0; 446*cdf0e10cSrcweir sal_Int32 nEnd = 0; 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir // extract language part 449*cdf0e10cSrcweir nEnd = sParser.indexOf(SEPERATOR_LC, nStart); 450*cdf0e10cSrcweir if (nEnd<0) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir setLanguage(sParser); 453*cdf0e10cSrcweir return; 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir setLanguage(sParser.copy(nStart, nEnd-nStart)); 456*cdf0e10cSrcweir nStart = nEnd+1; 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir // extract country 459*cdf0e10cSrcweir nEnd = sParser.indexOf(SEPERATOR_CV, nStart); 460*cdf0e10cSrcweir if (nEnd<0) 461*cdf0e10cSrcweir nEnd = sParser.indexOf(SEPERATOR_CV_LINUX, nStart); 462*cdf0e10cSrcweir if (nEnd<0) 463*cdf0e10cSrcweir { 464*cdf0e10cSrcweir setCountry(sParser.copy(nStart, sParser.getLength()-nStart)); 465*cdf0e10cSrcweir return; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir nStart = nEnd+1; 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir // extract variant 470*cdf0e10cSrcweir setVariant(sParser.copy(nStart, sParser.getLength()-nStart)); 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir //----------------------------------------------- 474*cdf0e10cSrcweir ::rtl::OUString Locale::toISO() const 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir ::rtl::OUStringBuffer sISO(64); 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir sISO.append(m_sLanguage); 479*cdf0e10cSrcweir if (m_sCountry.getLength()) 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir sISO.append(SEPERATOR_LC); 482*cdf0e10cSrcweir sISO.append(m_sCountry); 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir if (m_sVariant.getLength()) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir sISO.append(SEPERATOR_CV); 487*cdf0e10cSrcweir sISO.append(m_sVariant); 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir return sISO.makeStringAndClear(); 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir //----------------------------------------------- 495*cdf0e10cSrcweir sal_Bool Locale::equals(const Locale& aComparable) const 496*cdf0e10cSrcweir { 497*cdf0e10cSrcweir return ( 498*cdf0e10cSrcweir m_sLanguage.equals(aComparable.m_sLanguage) && 499*cdf0e10cSrcweir m_sCountry.equals (aComparable.m_sCountry ) && 500*cdf0e10cSrcweir m_sVariant.equals (aComparable.m_sVariant ) 501*cdf0e10cSrcweir ); 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir //----------------------------------------------- 505*cdf0e10cSrcweir sal_Bool Locale::similar(const Locale& aComparable) const 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir return (m_sLanguage.equals(aComparable.m_sLanguage)); 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir //----------------------------------------------- 511*cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator Locale::getFallback(const ::std::vector< ::rtl::OUString >& lISOList , 512*cdf0e10cSrcweir const ::rtl::OUString& sReferenceISO) 513*cdf0e10cSrcweir throw(Locale::MalFormedLocaleException) 514*cdf0e10cSrcweir { 515*cdf0e10cSrcweir Locale aReference(sReferenceISO); 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir // Note: The same language or "en"/"en-US" should be preferred as fallback. 518*cdf0e10cSrcweir // On the other side some localized variables doesnt use localzation in real. 519*cdf0e10cSrcweir // May be the use a "fix" value only ... marked as X-DEFAULT or X-NOTRANSLATE. 520*cdf0e10cSrcweir // At least it can be discussed, if any language is a valid fallback ... 521*cdf0e10cSrcweir // But in case some office functionality depends on that (that means real functionality instead 522*cdf0e10cSrcweir // of pure UI descriptions) we should do anything, so it can work. 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pSimilar = lISOList.end(); 525*cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pEN_US = lISOList.end(); 526*cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pEN = lISOList.end(); 527*cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pXDefault = lISOList.end(); 528*cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pXNoTranslate = lISOList.end(); 529*cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pAny = lISOList.end(); 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir ::std::vector< ::rtl::OUString >::const_iterator pIt; 532*cdf0e10cSrcweir for ( pIt = lISOList.begin(); 533*cdf0e10cSrcweir pIt != lISOList.end() ; 534*cdf0e10cSrcweir ++pIt ) 535*cdf0e10cSrcweir { 536*cdf0e10cSrcweir Locale aCheck(*pIt); 537*cdf0e10cSrcweir // found Locale, which match with 100% => return it 538*cdf0e10cSrcweir if (aCheck.equals(aReference)) 539*cdf0e10cSrcweir return pIt; 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir // found similar Locale => safe it as possible fallback 542*cdf0e10cSrcweir if ( 543*cdf0e10cSrcweir (pSimilar == lISOList.end()) && 544*cdf0e10cSrcweir (aCheck.similar(aReference)) 545*cdf0e10cSrcweir ) 546*cdf0e10cSrcweir { 547*cdf0e10cSrcweir pSimilar = pIt; 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir else 550*cdf0e10cSrcweir // found en-US => safe it as fallback 551*cdf0e10cSrcweir if ( 552*cdf0e10cSrcweir (pEN_US == lISOList.end()) && 553*cdf0e10cSrcweir (aCheck.equals(EN_US()) ) 554*cdf0e10cSrcweir ) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir pEN_US = pIt; 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir else 559*cdf0e10cSrcweir // found en[-XX] => safe it as fallback 560*cdf0e10cSrcweir if ( 561*cdf0e10cSrcweir (pEN == lISOList.end() ) && 562*cdf0e10cSrcweir (aCheck.similar(EN_US())) 563*cdf0e10cSrcweir ) 564*cdf0e10cSrcweir { 565*cdf0e10cSrcweir pEN = pIt; 566*cdf0e10cSrcweir } 567*cdf0e10cSrcweir else 568*cdf0e10cSrcweir // found an explicit default value(!) => safe it as fallback 569*cdf0e10cSrcweir if ( 570*cdf0e10cSrcweir (pXDefault == lISOList.end()) && 571*cdf0e10cSrcweir (aCheck.equals(X_DEFAULT()) ) 572*cdf0e10cSrcweir ) 573*cdf0e10cSrcweir { 574*cdf0e10cSrcweir pXDefault = pIt; 575*cdf0e10cSrcweir } 576*cdf0e10cSrcweir else 577*cdf0e10cSrcweir // found an implicit default value(!) => safe it as fallback 578*cdf0e10cSrcweir if ( 579*cdf0e10cSrcweir (pXNoTranslate == lISOList.end()) && 580*cdf0e10cSrcweir (aCheck.equals(X_NOTRANSLATE()) ) 581*cdf0e10cSrcweir ) 582*cdf0e10cSrcweir { 583*cdf0e10cSrcweir pXNoTranslate = pIt; 584*cdf0e10cSrcweir } 585*cdf0e10cSrcweir else 586*cdf0e10cSrcweir // safe the first locale, which isn't an explicit fallback 587*cdf0e10cSrcweir // as "last possible fallback" 588*cdf0e10cSrcweir if (pAny == lISOList.end()) 589*cdf0e10cSrcweir pAny = pIt; 590*cdf0e10cSrcweir } 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir if (pSimilar != lISOList.end()) 593*cdf0e10cSrcweir return pSimilar; 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir if (pEN_US != lISOList.end()) 596*cdf0e10cSrcweir return pEN_US; 597*cdf0e10cSrcweir 598*cdf0e10cSrcweir if (pEN != lISOList.end()) 599*cdf0e10cSrcweir return pEN; 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir if (pXDefault != lISOList.end()) 602*cdf0e10cSrcweir return pXDefault; 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir if (pXNoTranslate != lISOList.end()) 605*cdf0e10cSrcweir return pXNoTranslate; 606*cdf0e10cSrcweir 607*cdf0e10cSrcweir if (pAny != lISOList.end()) 608*cdf0e10cSrcweir return pAny; 609*cdf0e10cSrcweir 610*cdf0e10cSrcweir return lISOList.end(); 611*cdf0e10cSrcweir } 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir //----------------------------------------------- 614*cdf0e10cSrcweir sal_Bool Locale::getFallback(Locale& aLocale) 615*cdf0e10cSrcweir { 616*cdf0e10cSrcweir // a) 617*cdf0e10cSrcweir // this was our last fallback! 618*cdf0e10cSrcweir // break any further calls to this method ... 619*cdf0e10cSrcweir if (aLocale.equals(X_NOTRANSLATE())) 620*cdf0e10cSrcweir return sal_False; 621*cdf0e10cSrcweir 622*cdf0e10cSrcweir // b) 623*cdf0e10cSrcweir // switch from X_DEFAULT to X_NOTRANSLATE 624*cdf0e10cSrcweir // next time we will go to a) 625*cdf0e10cSrcweir if (aLocale.equals(X_DEFAULT())) 626*cdf0e10cSrcweir { 627*cdf0e10cSrcweir aLocale = X_NOTRANSLATE(); 628*cdf0e10cSrcweir return sal_True; 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir // c) 632*cdf0e10cSrcweir // switch from EN to X_DEFAULT 633*cdf0e10cSrcweir // next time we will go to b) 634*cdf0e10cSrcweir if (aLocale.equals(EN())) 635*cdf0e10cSrcweir { 636*cdf0e10cSrcweir aLocale = X_DEFAULT(); 637*cdf0e10cSrcweir return sal_True; 638*cdf0e10cSrcweir } 639*cdf0e10cSrcweir 640*cdf0e10cSrcweir // d) remove country from incoming locale 641*cdf0e10cSrcweir // e.g. "de-DE" => "de" or "en-US" => "en"! 642*cdf0e10cSrcweir if (aLocale.getCountry().getLength()) 643*cdf0e10cSrcweir { 644*cdf0e10cSrcweir aLocale.setCountry(::rtl::OUString()); 645*cdf0e10cSrcweir return sal_True; 646*cdf0e10cSrcweir } 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir // e) "en-US" possible? 649*cdf0e10cSrcweir if (!aLocale.equals(EN_US())) 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir aLocale = EN_US(); 652*cdf0e10cSrcweir return sal_True; 653*cdf0e10cSrcweir } 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir // f) no more fallbacks 656*cdf0e10cSrcweir return sal_False; 657*cdf0e10cSrcweir } 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir //----------------------------------------------- 660*cdf0e10cSrcweir void Locale::operator=(const Locale& rCopy) 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir // Take over these values without checking ... 663*cdf0e10cSrcweir // They was already checked if the copy was constructed 664*cdf0e10cSrcweir // and must be valid now! 665*cdf0e10cSrcweir m_sLanguage = rCopy.m_sLanguage; 666*cdf0e10cSrcweir m_sCountry = rCopy.m_sCountry; 667*cdf0e10cSrcweir m_sVariant = rCopy.m_sVariant; 668*cdf0e10cSrcweir } 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir //----------------------------------------------- 671*cdf0e10cSrcweir sal_Bool Locale::operator==(const Locale& aComparable) const 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir return equals(aComparable); 674*cdf0e10cSrcweir } 675*cdf0e10cSrcweir 676*cdf0e10cSrcweir //----------------------------------------------- 677*cdf0e10cSrcweir sal_Bool Locale::operator!=(const Locale& aComparable) const 678*cdf0e10cSrcweir { 679*cdf0e10cSrcweir return !equals(aComparable); 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir } // namespace comphelper 683*cdf0e10cSrcweir 684