Skip to content

I18n

Namespace: Shadop.Archmage.Sdk

Manages multilingual text with automatic fallback to a default language.

public class I18n

Inheritance ObjectI18n

Remarks:

I18n (internationalization) stores text for multiple languages and retrieves them on demand. When a text key is not available in the requested language, it automatically falls back to the configured fallback language.

Usage pattern:

  1. Create an I18n instance with a fallback language
  2. Load translations via MergeTexts, MergeL10nData, or MergeL10nFile
  3. Retrieve translations via GetText or Text

Creates I18n with fallback language (used when key not found in requested language).

public I18n(string fallbackLanguage)

fallbackLanguage String

ArgumentNullException
Thrown if fallbackLanguage is null.

Gets the fallback language code.

public string Fallback()

String

Returns the internal translation structure: language → (key → text). Modifications to the returned dictionary will affect future lookups.

public Dictionary<string, Dictionary<string, string>> AllTexts()

Dictionary<String, Dictionary<String, String>>

MergeTexts(Dictionary<String, String>, String)

Section titled “MergeTexts(Dictionary<String, String>, String)”

Merges translation key-value pairs for a specific language. Creates the language entry if it doesn’t exist; overwrites existing keys.

public void MergeTexts(Dictionary<string, string> texts, string language)

texts Dictionary<String, String>
Dictionary of translation key-value pairs.

language String
The language code to merge into.

Parses JSON bytes (flat object) and merges translations for the specified language.

public void MergeL10nData(Byte[] data, string language)

data Byte[]
UTF-8 encoded JSON bytes of a flat object.

language String
The language code to merge into.

T:Newtonsoft.Json.JsonException
Thrown if JSON parsing fails.

Loads a localization JSON file and merges translations for the specified language.

public void MergeL10nFile(string filePath, string language, IFS fs)

filePath String
Path to the JSON file (flat object with string keys/values).

language String
The language code to merge into.

fs IFS
Optional file system abstraction; defaults to File.ReadAllBytes(String) if null.

ArchmageException
Thrown if reading the file or parsing JSON fails.

MergeL10nFileAsync(String, String, IFS, CancellationToken)

Section titled “MergeL10nFileAsync(String, String, IFS, CancellationToken)”

Asynchronously loads a localization JSON file and merges translations for the specified language.

public Task MergeL10nFileAsync(string filePath, string language, IFS fs, CancellationToken cancellationToken)

filePath String
Path to the JSON file (flat object with string keys/values).

language String
The language code to merge into.

fs IFS
Optional file system abstraction; defaults to File.ReadAllBytesAsync(String, CancellationToken) if null.

cancellationToken CancellationToken
Token to cancel the operation.

Task

ArchmageException
Thrown if reading the file or parsing JSON fails.

Attempts to retrieve text with fallback. Tries the requested language first, then falls back to the default language.

public bool GetText(string key, string language, String& text)

key String
The translation key.

language String
The preferred language code.

text String&
The retrieved text, or null if not found.

Boolean
True if the key was found in either the requested or fallback language; otherwise, false.

Retrieves text with fallback, throwing an exception if not found. Tries the requested language first, then falls back to the default language.

public string Text(string key, string language)

key String
The translation key.

language String
The preferred language code.

String
The translation string.

ArchmageException
Thrown if the key is not found in either the requested or fallback language.