Module Bogue.I18n

module I18n: sig .. end

Internationalization.

This module provide ways to automatically translate strings into the user's language. The translations are grouped by contexts (predefined contexts correspond to Bogue's modules); this allows different translations for the same English word, depending on the context. If a translation is not found in the current context, all contexts will be examined.

Example for a one-time translation of the string "save as" in the File context:

module I = I18n.File
print_endline (I.gettext "save as")

Example for declaring a cached translated variable s to be re-used several times:

module I = I18n.File
let s = I.tt "save as" in
print_endline (I.tf s)
...


A file dialog with Chinese localization. We used the configuration variables
LANGUAGE=zh BOGUE_LABEL_FONT="/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc"


type locale = {
   language : string;
   country : string option;
}
val get_locales : unit -> locale list

Return the list of preferred locales as detected from the user's OS.

module type ContextInit = sig .. end

Functions available in every context.

val make_context : string -> (module Bogue.I18n.ContextInit)

Create a new module for using the given context. New translations aliases can be added by extending the module, as follows:

module My_context = struct
  include (val (make_context "my_context") : ContextInit)
  let hello = tt "Hello"
end

Translation files

Translation files are located in the locales directory of Bogue's share directory. See Where are the config files?. They are called "locale_ll_CC.conf" where ll is the language code and CC the country code, for instance "locale_fr_FR.conf". They can also be called simply "locale_ll.conf" for translations which follow the language's main dialect.

We don't use the traditional ".po" syntax: for simplicity, the syntax of the translation files is the one of Bogue's configuration files: each translation is written on a new line of the form

English text = Translated text

for instance

Save as = Enregistrer sous

The strings (English and translated) should not contain any equal ('=') char. There is a special syntax for contexts: the line

__CONTEXT = Context name

indicates that the following translations should apply to the context called "Context name", up until a new __CONTEXT line.

val save_locale : ?domain:string -> locale -> unit

Save the translation file for the given locale (including all contexts, and all user additions made with add_translation). The file is saved in the domain (= application) directory, which must be found under a "share" directory, as given by the function Theme.find_share domain ".". If this dir is not found, the locale is saved in the current directory.

List of predefined contexts

module File: sig .. end
module Menu: sig .. end
module Popup: sig .. end
module Text_input: sig .. end