Skip to main content

Module lang

Module lang 

Source
Expand description

Languages: the source language’s screen text by key (en/ui.ron), and the packs that overlay it (<tag>/): their screen text (ui.ron), the game’s data text (data.ron: names, and whatever else the game hands over by key) and the dialogue’s lines and captions (dialogue/*.ron).

The source is the language the game is written in (SourceLang): English unless the game declares another (Lang::with_source_lang), its folder holding its screen text only. A pack entry carries the source text it was made from; when that is no longer today’s the entry is stale, and a key with no entry is missing. Neither fails anything.

Tags. A language is named by its BCP 47 tag (LangCode: ja, pt-BR, zh-Hans), and its folder by that tag as BCP 47 writes it, so pt-br never quietly becomes a second language on a file system that ignores case. The engine reads the subset of tags it takes itself rather than with icu_locale_core: checking a tag is a short function, and the engine wants none of CLDR’s data.

The fallback chain. A key a pack lacks, or has stale, falls back along Lang::chain: the pack of each shorter tag the game has (pt-BR, then pt), then the source. So a small pt-BR pack can sit over a full pt one. Which language a game starts in is best_match of the system’s languages among the source and the packs: a tag, its shorter tags, Chinese’s script from its region, then the one pack of the same language.

The game names its folder and says what else its text must keep to (PackRules); the source text of its data is the SourceText it builds. As a format (ADR-0007), one pack is read from its lang.ron (LangPackRon). Lang::texts lists every text of every language, each with its part, key and file (TextAt). The source’s screen text can say where each key’s text is drawn (Place: its width in cells and a note for translators), and Lang::overflow lists a pack’s entries too wide for it.

Structs§

English
A game’s English screen text by key, as one file (en.ron) holds it: a kind (AssetKind) read with Ron::<English>::new() (Ron). Lang::new takes its map.
Entry
One piece of a pack’s text.
Lang
The source language’s text and every pack.
LangCode
A language’s tag, the name of its folder among the languages: BCP 47 (RFC 5646) in this subset, its subtags joined by -:
LangFile
One file of the languages’ directory.
LangInfo
A pack’s lang.ron.
LangPack
One language other than the source.
LangPackRon
A language pack (lang-pack, .ron), read from its lang.ron in its folder (lang/pt-BR/lang.ron), which is named by its tag as BCP 47 writes it: its ui.ron beside it, checked against the source’s (lang/en/ui.ron, or the folder of the source the game declares, LangPackRon::source_lang), and its data.ron and dialogue/*.ron, checked against the game’s data text when it gives it (LangPackRon::with_data; left out otherwise). Any other file in the folder is an error, and the source’s folder is no pack. Checked as pack_from_files says, with the game’s rules, its limits counting a character of the font atlas’s wide glyphs as two cells when the game gives the atlas (LangPackRon::widths_of), as the pack has them (LangInfo::widths); with the atlas, the wide set its wide_font names must be one the atlas has.
LangStatus
What a pack lacks (Lang::status): each list has the screen text’s keys, then the data’s, then the dialogue’s, each in key order.
LineEntry
One dialogue line or caption of a pack.
Orphan
A pack entry for a dialogue line that English no longer has.
Overflow
A pack’s entry wider than its key’s place (Lang::overflow).
PackRules
What a game’s packs keep to besides matching English: the rules of its data text, its tokens, its dialogue’s limits and the variants a line may have.
PackSources
The files of one pack.
Place
What English’s screen text says about where a key’s text is drawn.
SourceLang
The language the game is written in: its screen text is in its folder (<code>/ui.ron), and its data and dialogue in the game’s own files. Every pack is checked against it, and every lookup ends with it.
SourceLine
One dialogue line or caption in English.
SourceText
Today’s English for everything data.ron and dialogue/*.ron can translate, by key.
TextAt
Where a text of Lang::texts is from.

Enums§

LineKind
What kind of dialogue text a key is for: its length limit depends on it.
LineText
A line in a pack’s language.
MadeBy
Who made a pack’s text.
TagError
Why a text isn’t a language tag (LangCode::parse).
TextPart
Which part of a language a text is from.

Constants§

ENGLISHDeprecated
English’s tag, the source language when a game declares none.

Functions§

best_match
The offered language that fits the system’s: preferred is the system’s languages, most preferred first, and offered the source’s tag and the packs’. For each preferred tag in order:
english_and_places_from_source
The source’s screen text and where it is drawn, by key: what english_from_source reads, with each key’s Place where its value is written as (text: …, max_cells: …, note: …) rather than as text (both optional). A max_cells is at least 1, and a note isn’t empty.
english_from_source
Parses and validates the source language’s screen text source (a map of key to text), whatever the language, attributing errors to file. Reports every problem found. A key’s places (english_and_places_from_source) are read and left out.
from_files
from_files_in for a game written in English.
from_files_in
Validates the languages made of files, for a game written in source: the source’s screen text, <code>/ui.ron (with its keys’ places, english_and_places_from_source), and a pack for every other folder, named by its tag, which needs its lang.ron and ui.ron and may have a data.ron and dialogue/<file>.ron files (checked against data; left out without it). Import settings files are skipped (ADR-0057); any other file is an error, a lang.ron in the source’s folder too. display gives the name a path is reported under. Reports every problem found; with the source’s screen text broken the packs are not checked (each entry would be an unknown key).
names_key
The key of the name id of the names table: names.<id>.
pack_from_files
Parses and validates the pack made of sources, its screen text checked against english (the source’s screen text, whatever the language) and its data and dialogue text against data (left out without it: the data files failed to load). Reports every problem found; the messages call the source en.
pack_from_sources
Parses and validates a pack with screen text only: its lang.ron (info) and its ui.ron (ui), checked against english. See pack_from_files.
text_width
How many cells of the screen text takes: one per character, two for a character widths has wide (a Japanese or Chinese one, from the font atlas’s wide glyphs). Every length limit on text and every layout that measures it counts with this.

Type Aliases§

Places
Where English’s screen text is drawn, by key.
Source
A file of a pack: the name it is reported under, and its text.