module Gettext

Overview

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.

Extended Modules

Defined in:

gettext.cr

Instance Method Summary

Instance Method Detail

def 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"

[View source]
def 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)"

[View source]
def 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) # => "Επεξεργαστής κειμένου"

[View source]
def 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"

[View source]
def 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") # => "Επεξεργαστής κειμένου"

[View source]
def 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"

[View source]
def 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") # => "Επεξεργαστής κειμένου"

[View source]
def ngettext(msgid1 : String, msgid2 : String, n : UInt32) : String #

Same as #gettext but supports plural forms.

Example:

Gettext.ngettext("Crystal", "Crystals", 2) # => "Crystals"

[View source]
def 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"

[View source]
def 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"

[View source]