struct Gettext::Catalogue
- Gettext::Catalogue
- Struct
- Value
- Object
Overview
Gettext message catalogue. Contains methods for handling translations
You should not be manually creating an instance of this class! Instead let the Gettext backends
do it for you! See Gettext::MOBackend
and Gettext::POBackend
Defined in:
backend/gettext/gettext.crConstructors
-
.new(contents : Hash(String, Hash(Int8, String)))
Creates a message catalogue from parsed Gettext data
Instance Method Summary
-
#contents : Hash(String, Hash(Int8, String))
Returns all messages within the catalogue
-
#gettext(id : String)
Fetches the translated message for the specific ID.
-
#headers : Hash(String, String)
Returns a hash of the headers
-
#ngettext(id : String, plural_id, n)
Fetches the translated message for the specific ID with the correct plural form.
-
#npgettext(context, id, plural_id, n)
Fetches the translated message for the specific ID that is bound by context with the correct plural form.
-
#pgettext(context, id)
Fetches the translated message for the specific ID that is bound by context.
Constructor Detail
Creates a message catalogue from parsed Gettext data
Instance Method Detail
Returns all messages within the catalogue
You should never have to deal with this method under normal circumstances.
Please use the #gettext
family of methods to translate your application instead.
catalogue = Gettext::MOBackend.new("examples").create["en-US"]
catalogue.contents # => {...}
Fetches the translated message for the specific ID. If none can be found the given ID is returned.
catalogue = Gettext::MOBackend.new("examples").create["en_US"]
catalogue.gettext("A message") # => "Translated message"
catalogue.gettext("I don't exist") # => "I don't exist"
Returns a hash of the headers
catalogue = Gettext::MOBackend.new("examples").create["en_US"]
catalogue.headers["Plural-Forms"] # => "nplurals=2; plural=(n != 1);"
Fetches the translated message for the specific ID with the correct plural form. Returns either the singular or plural id if none can be found.
catalogue = Gettext::MOBackend.new("examples").create["en_US"]
catalogue.ngettext("I have %d apple", "I have %d apples", 0) # => "Translated message with plural-form 1"
catalogue.ngettext("I have %d apple", "I have %d apples", 1) # => "Translated message with plural-form 0"
# Not found:
catalogue.ngettext("I have %d pear", "I have %d pears", 0) # => "I have %d pears"
catalogue.ngettext("I have %d pear", "I have %d pears", 1) # => "I have %d pear"
Fetches the translated message for the specific ID that is bound by context with the correct plural form.
catalogue = Gettext::MOBackend.new("examples").create["en_US"]
catalogue.npgettext("CopyPasteMenu", "Export %d file", "Export %d files", 0) # => "Translated message with plural-form 1"
catalogue.npgettext("CopyPasteMenu", "Export %d file", "Export %d files", 1) # => "Translated message with plural-form 0"
# Not found:
catalogue.npgettext("CopyPasteMenu", "None", "NonePlural", 0) # => "NonePlural"
catalogue.npgettext("CopyPasteMenu", "None", "NonePlural", 1) # => "None"
Fetches the translated message for the specific ID that is bound by context. If none can be found the given ID is returned.
catalogue = Gettext::MOBackend.new("examples").create["en_US"]
catalogue.pgettext("CopyPasteMenu", "copy") # => "Translated copy"
catalogue.pgettext("CopyPasteMenu", "I don't exist") # => "I don't exist"