
1 // 2 // Copyright (c) 2007, Brian Frank and Andy Frank 3 // Licensed under the Academic Free License version 3.0 4 // 5 // History: 6 // 03 Nov 07 Brian Frank Creation 7 // 8 9 ** 10 ** Locale models a cultural language and region/country. 11 ** See `docLang::Localization` for details. 12 ** 13 @simple 14 const class Locale 15 { 16 17 ////////////////////////////////////////////////////////////////////////// 18 // Construction 19 ////////////////////////////////////////////////////////////////////////// 20 21 ** 22 ** Parse a locale according to the `toStr` format. 23 ** 24 static Locale fromStr(Str s) 25 26 ** 27 ** Private constructor 28 ** 29 private new privateMake() 30 31 ////////////////////////////////////////////////////////////////////////// 32 // Thread 33 ////////////////////////////////////////////////////////////////////////// 34 35 ** 36 ** Get the current thread's locale. 37 ** 38 static Locale current() 39 40 ** 41 ** Set the current thread's locale. 42 ** Throw NullErr if null is passed. 43 ** 44 static Void setCurrent(Locale locale) 45 46 ** 47 ** Run the specified function using this locale as the 48 ** the thread's current locale. This method guarantees 49 ** that upon return the thread current's locale remains 50 ** unchanged. 51 ** 52 Void with(|,| func) 53 54 ////////////////////////////////////////////////////////////////////////// 55 // Identity 56 ////////////////////////////////////////////////////////////////////////// 57 58 ** 59 ** Get the language as a lowercase ISO 639 two letter code. 60 ** 61 Str lang() 62 63 ** 64 ** Get the country/region as an uppercase ISO 3166 two 65 ** letter code. Return null if the country is unspecified. 66 ** 67 Str country() 68 69 ** 70 ** Compute hash code base on normalized toStr format. 71 ** 72 override Int hash() 73 74 ** 75 ** Equality is based on the normalized toStr format. 76 ** 77 override Bool equals(Obj obj) 78 79 ** 80 ** Return string representation: 81 ** <locale> := <lang> ["-" <country>] 82 ** <lang> := lowercase ISO 636 two letter code 83 ** <country> := uppercase ISO 3166 two letter code 84 ** 85 override Str toStr() 86 87 ////////////////////////////////////////////////////////////////////////// 88 // Properties 89 ////////////////////////////////////////////////////////////////////////// 90 91 ** 92 ** Resolve a localized property for the specified pod/key pair. 93 ** The following rules are used for resolution: 94 ** 1. Find the pod and use its resource files 95 ** 2. Lookup via '/locale/{Locale.toStr}.props' 96 ** 3. Lookup via '/locale/{Locale.lang}.props' 97 ** 4. Lookup via '/locale/en.props' 98 ** 5. If all else fails return 'pod::key' 99 ** 100 Str prop(Str pod, Str key) 101 102 }