struct Gettext::MOBackend

Overview

The backend for Gettext's MO files. This class contains methods to parse and interact with them.

Similar to the Gettext module from Python, feel free to subclass and override the #parse method to create a backend for other .mo files. However, please consider opening a PR and adding it directly to lens instead!

Defined in:

backend/gettext/mo/backend.cr

Constant Summary

BE_MAGIC = 3725722773_i64
LE_MAGIC = 2500072158_i64

Constructors

Instance Method Summary

Constructor Detail

def self.new(locale_directory_path : String) #

Create a new MO backend instance that reads from the given locale directory path

Gettext::MOBackend.new("locales")

[View source]

Instance Method Detail

def create : Hash(String, Catalogue) #

Create message catalogue from the loaded locale files.

This is the equivalent to #parse and is only here for compatibility with Gettext::POBackend

This is returned as a mapping of the language code to the catalogue in which the language code is taken from the Language header. If none can be found then the mo file name is used as a fallback.

backend = Gettext::MOBackend.new("locales")
backend.create # => Hash(String, Catalogue)

[View source]
def parse : Hash(String, Catalogue) #

Parse gettext mo files into message catalogues.

This is returned as a mapping of the language code to the catalogue in which the language code is taken from the Language header. If none can be found then the mo file name is used as a fallback.

backend = Gettext::MOBackend.new("locales")
backend.parse # => Hash(String, Catalogue)

[View source]