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