package core:text/i18n

Types

Error ¶

Error :: enum int {
	// 		General return values.
	None                           = 0, 
	Empty_Translation_Catalog, 
	Duplicate_Key, 
	// 		Couldn't find, open or read file.
	File_Error, 
	// 		File too short.
	Premature_EOF, 
	// 		GNU Gettext *.MO file errors.
	MO_File_Invalid_Signature, 
	MO_File_Unsupported_Version, 
	MO_File_Invalid, 
	MO_File_Incorrect_Plural_Count, 
	// 		Qt Linguist *.TS file errors.
	TS_File_Parse_Error, 
	TS_File_Expected_Context, 
	TS_File_Expected_Context_Name, 
	TS_File_Expected_Source, 
	TS_File_Expected_Translation, 
	TS_File_Expected_NumerusForm, 
}

Parse_Options ¶

Parse_Options :: struct {
	merge_sections: bool,
}

Section ¶

Section :: map[string][]string

Translation ¶

Translation :: struct {
	k_v:       map[string]map[string][]string,
	// k_v[section][key][plural_form] = ...
	intern:    strings.Intern,
	pluralize: proc "odin" (bit_size: int) -> (number_of_trials: int),
}

Constants

DEFAULT_PARSE_OPTIONS ¶

DEFAULT_PARSE_OPTIONS :: Parse_Options{merge_sections = false}

MAX_PLURALS ¶

MAX_PLURALS :: min(max(#config(ODIN_i18N_MAX_PLURAL_FORMS, 10), 1), 255)
 

Allow between 1 and 255 plural forms. Default: 10.

Variables

ACTIVE ¶

ACTIVE: ^Translation
 

Currently active catalog.

TS_XML_Options ¶

TS_XML_Options: xml.Options = …

Procedures

destroy ¶

destroy :: proc "odin" (catalog: ^Translation = ACTIVE, allocator := context.allocator) {…}
 

Same for destroy:

- destroy(), to clean up the currently active catalog catalog i18n.ACTIVE
- destroy(catalog), to clean up a specific catalog.

get_by_section ¶

get_by_section :: proc "odin" (section, key: string, number: int = 0, catalog: ^Translation = ACTIVE) -> (value: string) {…}
 

Several ways to use:

- get(section, key), which defaults to the singular form and i18n.ACTIVE catalog, or
- get(section, key, number), which returns the appropriate plural from the active catalog, or
- get(section, key, number, catalog) to grab text from a specific one.

get_by_slot_by_section ¶

get_by_slot_by_section :: proc "odin" (section, key: string, number: int = 0, catalog: ^Translation = ACTIVE) -> (value: string) {…}
 

Several ways to use:

- get_by_slot(key), which defaults to the singular form and i18n.ACTIVE catalog, or
- get_by_slot(key, slot), which returns the requested plural from the active catalog, or
- get_by_slot(key, slot, catalog) to grab text from a specific one.

If a file format parser doesn't (yet) support plural slots, each of the slots will point at the same string.

get_by_slot_single_section ¶

get_by_slot_single_section :: proc "odin" (key: string, number: int = 0, catalog: ^Translation = ACTIVE) -> (value: string) {…}
 

Several ways to use:

- get_by_slot(key), which defaults to the singular form and i18n.ACTIVE catalog, or
- get_by_slot(key, slot), which returns the requested plural from the active catalog, or
- get_by_slot(key, slot, catalog) to grab text from a specific one.

If a file format parser doesn't (yet) support plural slots, each of the slots will point at the same string.

get_single_section ¶

get_single_section :: proc "odin" (key: string, number: int = 0, catalog: ^Translation = ACTIVE) -> (value: string) {…}
 

Several ways to use:

- get(key), which defaults to the singular form and i18n.ACTIVE catalog, or
- get(key, number), which returns the appropriate plural from the active catalog, or
- get(key, number, catalog) to grab text from a specific one.

parse_mo_file ¶

parse_mo_file :: proc "odin" (filename: string, options: Parse_Options = DEFAULT_PARSE_OPTIONS, pluralizer: proc "odin" (bit_size: int) -> (number_of_trials: int) = nil, allocator := context.allocator) -> (translation: ^Translation, err: Error) {…}

parse_mo_from_bytes ¶

parse_mo_from_bytes :: proc "odin" (data: []u8, options: Parse_Options = DEFAULT_PARSE_OPTIONS, pluralizer: proc "odin" (bit_size: int) -> (number_of_trials: int) = nil, allocator := context.allocator) -> (translation: ^Translation, err: Error) {…}

parse_qt_linguist_file ¶

parse_qt_linguist_file :: proc "odin" (filename: string, options: Parse_Options = DEFAULT_PARSE_OPTIONS, pluralizer: proc "odin" (bit_size: int) -> (number_of_trials: int) = nil, allocator := context.allocator) -> (translation: ^Translation, err: Error) {…}

parse_qt_linguist_from_bytes ¶

parse_qt_linguist_from_bytes :: proc "odin" (data: []u8, options: Parse_Options = DEFAULT_PARSE_OPTIONS, pluralizer: proc "odin" (bit_size: int) -> (number_of_trials: int) = nil, allocator := context.allocator) -> (translation: ^Translation, err: Error) {…}

read_u16 ¶

read_u16 :: proc "odin" (data: []u8, native_endian: bool = true) -> (res: u16, err: Error) {…}

read_u32 ¶

read_u32 :: proc "odin" (data: []u8, native_endian: bool = true) -> (res: u32, err: Error) {…}
 

Helpers.

Procedure Groups

Source Files

Generation Information

Generated with odin version dev-2022-10 (vendor "odin") Windows_amd64 @ 2022-10-05 21:11:47.336171000 +0000 UTC