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
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"
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)"
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) # => "Επεξεργαστής κειμένου"
Same as dcgettext but supports plural forms.
Example:
Gettext.dcngettext("gedit", "Crystal", "Crystals", 2, Gettext::LC::ALL) # => "Crystals"
Returns the translated msgid from the desired text domain.
Example:
Gettext.setlocale(Gettext::LC::ALL, "el_GR.UTF-8")
Gettext.dgettext("gedit", "Text Editor") # => "Επεξεργαστής κειμένου"
Same as dgettext but supports plural forms.
Example:
Gettext.dngettext("gedit", "Crystal", "Crystals", 2) # => "Crystals"
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") # => "Επεξεργαστής κειμένου"
Same as gettext but supports plural forms.
Example:
Gettext.ngettext("Crystal", "Crystals", 2) # => "Crystals"
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"
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"