1 # This file is part of NIT (http://www.nitlanguage.org).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Internationalization of Strings using `gettext` library
27 "".to_cstring
.set_locale
33 # Sets the locale of the program running
35 # This can be set at different times in the program,
36 # if used with an empty string, the locale will
37 # be set to the user's environment locale.
39 # For more info, SEE setlocale manual
41 setlocale(LC_ALL, self);
46 # Gets the translation of `self` via gettext from `dir` using `domain`
48 # `domain`: Gettext domain, i.e. file/module name
49 # `dir`: Where the locale/LC_MESSAGES folder for this domain is located
50 fun get_translation
(domain
, dir
: String): String do
51 bindtextdomain
(domain
, dir
)
52 return dgettext
(domain
)
55 # Gettext `gettext`, SEE gettext manual for further info
57 import String.to_cstring
, CString.to_s
`{
58 return CString_to_s(gettext(String_to_cstring(self)));
61 # Gettext `dgettext`, SEE gettext manual for further info
62 fun dgettext
(domain
: String): String
63 import String.to_cstring
, CString.to_s
`{
64 return CString_to_s(dgettext(String_to_cstring(domain), String_to_cstring(self)));
68 # Gettext `bindtextdomain`, SEE gettext manual for further info
69 fun bindtextdomain
(domain
, dir
: String) import String.to_cstring
`{
70 bindtextdomain(String_to_cstring(domain), String_to_cstring(dir));
73 # Gettext `textdomain`, SEE gettext manual for further info
74 fun textdomain
(domain
: String) import String.to_cstring
`{
75 textdomain(String_to_cstring(domain));