PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lib/i18n/i18n.e

http://github.com/tybor/Liberty
Specman e | 189 lines | 134 code | 29 blank | 26 comment | 2 complexity | bfa04a97677ea5b83095b044e45d7b83 MD5 | raw file
  1-- This file is part of a Liberty Eiffel library.
  2-- See the full copyright at the end.
  3--
  4expanded class I18N
  5
  6feature {ANY}
  7   locale: LOCALE
  8         -- The currently set locale
  9      do
 10         Result := locale_memory.item
 11      end
 12
 13   set_locale (a_locale: like locale)
 14         -- Set the current locale
 15      do
 16         locale_memory.set_item(a_locale)
 17         fix_locale(a_locale)
 18      ensure
 19         locale = a_locale
 20      end
 21
 22feature {ANY} -- Useful constants
 23   canada: LOCALE
 24      once
 25         create Result.make_country("en", "CA")
 26      end
 27
 28   canada_french, quebec: LOCALE
 29      once
 30         create Result.make_country("fr", "CA")
 31      end
 32
 33   china: LOCALE
 34      once
 35         create Result.make_country("zh", "CN")
 36      end
 37
 38   chinese: LOCALE
 39      once
 40         create Result.make_language("zh")
 41      end
 42
 43   english: LOCALE
 44      once
 45         create Result.make_language("en")
 46      end
 47
 48   france: LOCALE
 49      once
 50         create Result.make_country("fr", "FR")
 51      end
 52
 53   french: LOCALE
 54      once
 55         create Result.make_language("fr")
 56      end
 57
 58   german: LOCALE
 59      once
 60         create Result.make_language("de")
 61      end
 62
 63   germany: LOCALE
 64      once
 65         create Result.make_country("de", "DE")
 66      end
 67
 68   dutch: LOCALE
 69      once
 70         create Result.make_language("nl")
 71      end
 72
 73   netherlands: LOCALE
 74      once
 75         create Result.make_country("nl", "NL")
 76      end
 77
 78   italian: LOCALE
 79      once
 80         create Result.make_language("it")
 81      end
 82
 83   italy: LOCALE
 84      once
 85         create Result.make_country("it", "IT")
 86      end
 87
 88   japan: LOCALE
 89      once
 90         create Result.make_country("jp", "JP")
 91      end
 92
 93   japanese: LOCALE
 94      once
 95         create Result.make_language("jp")
 96      end
 97
 98   korea: LOCALE
 99      once
100         create Result.make_country("ko", "KR")
101      end
102
103   korean: LOCALE
104      once
105         create Result.make_language("ko")
106      end
107
108   prc: LOCALE
109      once
110         create Result.make_country("zh", "CN")
111      end
112
113   simplified_chinese: LOCALE
114      once
115         create Result.make_country("zh", "CN")
116      end
117
118   taiwan: LOCALE
119      once
120         create Result.make_country("zh", "TW")
121      end
122
123   traditional_chinese: LOCALE
124      once
125         create Result.make_country("zh", "TW")
126      end
127
128   uk: LOCALE
129      once
130         create Result.make_country("en", "GB")
131      end
132
133   us: LOCALE
134      once
135         create Result.make_country("en", "US")
136      end
137
138feature {}
139   locale_memory: REFERENCE[LOCALE]
140      once
141         create Result
142         fix_locale(Result.item)
143      end
144
145   fix_locale (a_locale: like locale)
146         -- low-level access to the native localization
147      local
148         language, country, encoding: POINTER
149      do
150         language := a_locale.language.to_external
151         if a_locale.country /= Void then
152            country := a_locale.country.to_external
153            if a_locale.encoding /= Void then
154               encoding := a_locale.encoding.to_external
155            end
156         end
157         i18n_set_system_locale(language, country, encoding)
158      end
159
160   i18n_set_system_locale (language, country, encoding: POINTER)
161      external "plug_in"
162      alias "{
163         location: "externals"
164         module_name: "plugin"
165         feature_name: "i18n_set_system_locale"
166      }"
167      end
168
169end -- class I18N
170--
171-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
172--
173-- Permission is hereby granted, free of charge, to any person obtaining a copy
174-- of this software and associated documentation files (the "Software"), to deal
175-- in the Software without restriction, including without limitation the rights
176-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
177-- copies of the Software, and to permit persons to whom the Software is
178-- furnished to do so, subject to the following conditions:
179--
180-- The above copyright notice and this permission notice shall be included in
181-- all copies or substantial portions of the Software.
182--
183-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
184-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
185-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
186-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
187-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
188-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
189-- THE SOFTWARE.