module

Gettext

Bindings for the GNU & Musl gettext library.

NOTE: Documentation is meant to be viewed alongside the C one. WARNING: It goes without saying that both the locales and the text domains you input need to be available for the bindings to work.

Instance methods

bind_textdomain_codeset(domainname : String, codeset : String = "UTF-8") : String

Sets the current text domain's codeset. If no parameters are provided, it sets it to UTF-8.

Returns the new codeset.

Example:

Gettext.bind_textdomain_codeset("my-domain", "UTF-8") # => "UTF-8"
Source
bindtextdomain(domainname : String, dirname : String | Path) : String

Sets the current text domain to a local one.

Returns the new text domain.

Example:

Gettext.bindtextdomain("my-domain", ".")              # => "."
Gettext.bindtextdomain("my-domain", Path[ENV["PWD"]]) # => "(pwd)"
Source
dcgettext(domainname : String, msgid : String, category : LC) : String

Returns the translated msgid from the desired text domain and category.

Example:

Gettext.setlocale(Gettext::LC::ALL, "el_GR.UTF-8")
Gettext.dcgettext("gedit", "Text Editor", Gettext::LC::ALL) # => "Επεξεργαστής κειμένου"
Source
dcngettext(domainname : String, msgid1 : String, msgid2 : String, n : UInt32, category : LC) : String

Same as dcgettext but supports plural forms.

Example:

Gettext.dcngettext("gedit", "Crystal", "Crystals", 2, Gettext::LC::ALL) # => "Crystals"
Source
dgettext(domainname : String, msgid : String) : String

Returns the translated msgid from the desired text domain.

Example:

Gettext.setlocale(Gettext::LC::ALL, "el_GR.UTF-8")
Gettext.dgettext("gedit", "Text Editor") # => "Επεξεργαστής κειμένου"
Source
dngettext(domainname : String, msgid1 : String, msgid2 : String, n : UInt32) : String

Same as dgettext but supports plural forms.

Example:

Gettext.dngettext("gedit", "Crystal", "Crystals", 2) # => "Crystals"
Source
gettext(msgid : String) : String

Returns the translated msgid from the current text domain.

Example:

Gettext.setlocale(Gettext::LC::ALL, "el_GR.UTF-8")
Gettext.textdomain("gedit")
Gettext.gettext("Text Editor") # => "Επεξεργαστής κειμένου"
Source
ngettext(msgid1 : String, msgid2 : String, n : UInt32) : String

Same as gettext but supports plural forms.

Example:

Gettext.ngettext("Crystal", "Crystals", 2) # => "Crystals"
Source
setlocale(category : LC = LC::ALL, locale : String = "") : String

Sets the current locale, overriding the one set by the env var / category. If no parameters are provided, it sets LC:ALL to "".

Returns the new locale or all categories.

Example:

Gettext.setlocale(Gettext::LC::ALL, "el_GR.UTF-8") # => "el_GR.UTF-8"
Source
textdomain(domainname : String | Nil = nil) : String

Sets the current text domain to one that is already available. If no parameters are provided, it returns the current one.

Returns the new (or current) text domain.

Example:

Gettext.textdomain("gedit") # => "gedit"
Gettext.textdomain          # => "gedit"
Source

Nested types