Expand description
Localisation of eov and its plugins.
eov’s interface is available in the LANGUAGES listed here. Every text
is written in English, the source language, and translated through
gettext catalogs (.po files) that sit beside the code that uses them:
translations/
├── <domain>.pot the template: every text, untranslated
├── de/LC_MESSAGES/<domain>.po German
├── pt-BR/LC_MESSAGES/<domain>.po Portuguese (Brazil)
└── zh-Hant/LC_MESSAGES/<domain>.po Chinese (Traditional)Folders are named by the language’s BCP 47 tag (Language::tag); the
spellings other gettext tools use (pt_BR, zh_TW, nb_NO) are found
too (Language::catalog_folders). A text that a
catalog lacks, or that is marked fuzzy, is shown in English: a missing
translation never shows as an empty or raw text.
§Texts in .slint files
Mark them with Slint’s @tr("…"). eov compiles a plugin’s surfaces with
the plugin’s catalogs (see the manifest’s [i18n] table), so they follow
the language of the interface and change with it.
§Texts made in Rust
Use tr! for every text a user reads: notifications,
status texts, menu items, tooltips, errors. It has the syntax of the
tr crate’s macro, so its xtr tool extracts the
texts, and the placeholders of @tr ({}, {0}, {name}, {n} for
the count of a plural text; {{ and }} for braces):
use eov_plugin_api::i18n::tr;
let file = "case-12.svs";
let count = 3;
assert_eq!(tr!("Opened {}", file), "Opened case-12.svs");
let _ = tr!("Toolbar" => "Open"); // with a context
assert_eq!(tr!("One region" | "{n} regions" % count), "3 regions");
let _ = tr!("Saved {count} regions to {file}", count = count, file = file);
// Translators: a comment for translators, extracted with the text.
let _ = tr!("Measure");eov loads a plugin’s catalog for the language of the interface before
it calls Plugin::create, and again before
it delivers HostEvent::LanguageChanged,
so tr! always answers in the current language. Texts a plugin handed
to eov earlier (toolbar tooltips, tool names) keep their language until
the plugin hands them over again: do that when the language changes.
Do not translate what is read by programs or other people’s tools: file formats, JSON, CSV, log messages, identifiers, or data such as file names and slide properties.
§The same text for the user and for the log
A problem is often both shown to the user and written to eov’s log,
which stays English. Write it once, with tr!, and get it in both
languages from shown_and_english; in_english runs any code with
this thread’s texts written in English:
use eov_plugin_api::i18n::{self, tr};
let name = "case-12.svs";
let (shown, english) = i18n::shown_and_english(|| tr!("{} could not be read", i18n::isolate(name)));
assert_eq!(english, "case-12.svs could not be read");
// host.info(english); host.notify(NotifyLevel::Warning, shown);§Writing direction and numbers
Arabic, Persian and Hebrew are written from right to left. Wrap values
that are inserted into a translated text, and that are written from left
to right whatever the language (file names, paths, numbers with units),
with isolate, so the text around them keeps its order. Show
decimal numbers with format_decimal and read numbers that users type
with parse_decimal; both follow the language’s decimal separator, as
Slint does in the interface.
Macros§
- tr
- Translates a text written in English: see the module documentation. Translates a text written in English, in the current language of this library (see the module documentation):
Structs§
- Catalog
- The translations of one domain (eov, or a plugin) into one language,
read from a gettext
.pofile. - Catalog
Error - Why a catalog could not be read.
- Catalog
Report - What
check_catalogfound in a catalog. - Language
- A language of eov’s interface: one of
LANGUAGES. Minor releases may add fields, so code outside this crate reads them and does not build or destructure aLanguagein full. - Plural
Rule - A gettext plural rule: the C expression of a
Plural-Formsheader (n%10==1 && n%100!=11 ? 0 : …) that gives the form a number takes.
Enums§
- Direction
- The writing direction of a language.
Constants§
- SOURCE_
TAG - The tag of the source language. Catalogs translate from it; it has none.
Statics§
- LANGUAGES
- Every language of the interface: English (the source) first, then the translations by tag. Plural forms follow the Unicode CLDR as gettext writes them; decimal separators are the CLDR’s.
Functions§
- by_tag
- The language with exactly this tag (letter case and
_for-do not matter:pt_brispt-BR). Usenegotiatefor locale names such aspt_BR.UTF-8orzh-TW. - catalog_
path - Where the catalog of
domainforlanguagebelongs:<dir>/<tag>/LC_MESSAGES/<domain>.po. - check_
catalog - Checks a catalog of
language(the text of its.pofile) against what eov needs to show it, and, when given, its template (.pot): - current
- The language of the interface (English until eov says otherwise), and
English while this thread runs
in_english. - empty_
catalog - A catalog without translations for
language: just the header, with the language’s plural forms. eov puts one in for each language a plugin has no catalog for, so that every bundle lists the same languages. - find_
catalog - The catalog of
domainforlanguageindir: in the tag’s folder (pt-BR), else under another spelling gettext tools use (Language::catalog_folders:pt_BR,zh_TW). English has none. - format
- Fills the placeholders of a translated text, as Slint’s
@trdoes:{}takes the next argument,{0}the first,{name}the one with that name;{{and}}are braces. A placeholder without its argument stays as it is. - format_
decimal valuewithdecimalsdigits after the decimal separator of the current language (1,50in German,1.50in English).- format_
decimal_ for format_decimalfor a given language.- in_
english - Runs
writewith this thread’s texts written as in English:tr!gives the English text (filled in, and with the English plural form), and everything that followscurrentdoes as for English:isolateadds no marks,format_decimalwrites andparse_decimalreads numbers as in English,is_rtlis false;join_sentencesjoins as it does in every language. For the English line of eov’s log or of a file, from the code that writes the shown text; seeshown_and_englishfor both at once. - is_rtl
- Whether the interface is written from right to left.
- isolate
textfor insertion into a translated text: in a right-to-left language it is isolated (U+2068 … U+2069), so that a file name, a path or a number with its unit keeps its own order and does not reorder the text around it. In left-to-right languages it is returned as it is.- isolate_
for isolatefor a given language.- join_
sentences - Separately translated sentences as one message, one after the other:
with a space between them, except after a sentence that ends in
full-width punctuation (
。,!,?, a full-width closing bracket), which Chinese and Japanese follow without a space. Empty sentences are left out. - negotiate
- The language of the interface for a locale name of the system or the
user: a BCP 47 tag (
pt-BR,zh-Hant-TW,es-419) or a POSIX locale (de_AT.UTF-8).Nonewhen none of theLANGUAGESfits, and forCandPOSIX. - negotiate_
first - The first of
locales(in order of preference) thatnegotiatefits. - ntranslate
- The form of a text with a number
nin the current language (in English insidein_english). - parse_
decimal - Reads a number a user typed: with the current language’s decimal
separator, or with
.,,or the Arabic decimal sign (people type what they are used to), in Western, Arabic-Indic or Persian digits. - parse_
decimal_ for parse_decimalfor a given language.- placeholders
- The placeholders of a text (
{},{0},{name}; not{{or}}). - reading_
catalog - Whether this thread is reading a
.pofile. rspolib, the reader Slint uses too, panics on some malformed files; eov catches those panics and reports a bad catalog, and its panic hook asks this so that it does not record them as crashes. - set_
catalog - Makes
catalogthe onetr!translates with, and its language thecurrentone;Noneshows the English texts. eov and the plugin SDK call this when the language changes. - set_
current - Makes
languagethis library’s current language forcurrent,isolate,format_decimalandparse_decimal, without changing the catalog (seeset_catalog). - shown_
and_ english - The text
writemakes in the interface’s language (to show) and in English (for eov’s log, files, batch output), written by the same code: - source
- English, the source language.
- translate
- The translation of
msgid(with the contextmsgctxt), ormsgid(always insidein_english). - translations
- The translations: every language but English.