Skip to content

L10n

The value of an l10n field: an l10n key, whose text is looked up with the active Archmage.I18n.

Inherits: RefCounted

Set get_i18n and get_preferred_language once, such as in an autoload:

func _ready() -> void:
L10n.get_i18n = get_i18n
L10n.get_preferred_language = get_preferred_language

Set them to methods, as above, or to static functions. If a lambda is still set when the game exits, Godot 4.6.3 aborts; to use a lambda, set the variable back to Callable() before exit, such as in Node._exit_tree().

== compares two L10n objects, not their keys; compare key instead.

static var EMPTY: L10n

The L10n whose key is empty. A null or empty JSON value converts to it.

static var get_i18n: Callable

Returns the active Archmage.I18n. Set it before reading text or calling get_text().

static var get_preferred_language: Callable

Returns the player’s preferred language. Set it before reading text.

var key: String

The l10n key. Read-only.

var text: String

The text in the preferred language, or in the fallback language when the preferred language has none, or key itself when neither has it. An empty key gives an empty string. Read-only.

L10n.new(p_key: String = "")
static func from_json(v: Variant, _e: Archmage.ParseError = null) -> L10n

Converts v, the JSON value of an l10n field, to an L10n. A value that is not a string gives EMPTY, and the type mismatch is recorded in _e (see Archmage.ParseError.report_mismatch()).

func to_json() -> String

Returns the l10n key.

func get_text(lang: String) -> Variant

Returns the text in lang, or in the fallback language when lang has none, or null when neither has it. An empty key gives an empty string.