Table of Contents

Class LocalizationBootstrap

Namespace
BSGameLib.Game.Localization
Assembly
BSGameLib.Game.dll

Finds the language files, loads them, and sets the language that is shown.

public class LocalizationBootstrap
Inheritance
LocalizationBootstrap
Inherited Members

Constructors

LocalizationBootstrap(IServiceProvider, ILogger<LocalizationBootstrap>, IFileSystem)

Created by dependency injection.

public LocalizationBootstrap(IServiceProvider serviceProvider, ILogger<LocalizationBootstrap> logger, IFileSystem fileSystem)

Parameters

serviceProvider IServiceProvider
logger ILogger<LocalizationBootstrap>
fileSystem IFileSystem

Properties

AdditionalFolders

More folders to find languages in, after FilePath: a player's own, say, for a translation they are trying. A language found in more than one is loaded from the last, so a file here replaces a shipped language of the same code.

public IList<string> AdditionalFolders { get; }

Property Value

IList<string>

CurrentLanguage

The LanguageInfo of the language being shown. Null until InitializeLanguages() has run, and when the language shown is not one of SupportedLanguages.

public LanguageInfo? CurrentLanguage { get; }

Property Value

LanguageInfo?

CurrentLanguageCode

The language being shown, once InitializeLanguages() has run.

public string CurrentLanguageCode { get; }

Property Value

string

DefaultLanguageCode

The language to show, usually the player's choice. If it cannot be loaded the fallback language is shown instead.

public string DefaultLanguageCode { get; set; }

Property Value

string

FallbackLanguageCode

The language every other one is translated from. A key missing from the current language is looked up here before it is shown as itself, so a partial translation shows the untranslated strings in this language rather than as keys.

public string FallbackLanguageCode { get; set; }

Property Value

string

FilePath

The folder the language files are read from, as a path. The default is Localization.

public string FilePath { get; set; }

Property Value

string

Problems

What was wrong with the language files at the last InitializeLanguages(): a file that would not load, or keys the fallback language does not have.

public IReadOnlyList<LanguageProblem> Problems { get; }

Property Value

IReadOnlyList<LanguageProblem>

SupportedLanguages

The languages that loaded in the last InitializeLanguages(). A language that failed to load is not listed.

public IReadOnlyCollection<LanguageInfo> SupportedLanguages { get; }

Property Value

IReadOnlyCollection<LanguageInfo>

Methods

AddLanguage(string)

Adds a language code to load on the next InitializeLanguages(). Empty codes and codes already added are ignored.

public void AddLanguage(string languageCode)

Parameters

languageCode string

DiscoverLanguages()

Adds every <code>.json in FilePath as a supported language, so that shipping a language is adding its file.

public void DiscoverLanguages()

InitializeLanguages()

Loads every supported language and makes DefaultLanguageCode current. Calling it again starts over, reloading every file.

public void InitializeLanguages()

SetAddedTexts(string, IReadOnlyDictionary<string, string>)

Adds sentences beside the language files while the game runs, such as those a server sends for what it adds to the game, under name; a second call with the same name replaces them, and none removes them. They are the game's to give in the current language: a key is looked up in the current language, then in these, then in the fallback. InitializeLanguages() removes every set.

public void SetAddedTexts(string name, IReadOnlyDictionary<string, string> texts)

Parameters

name string
texts IReadOnlyDictionary<string, string>

SetOverrideTexts(string, string, IReadOnlyDictionary<string, string>)

Sets sentences that win over one language's file while the game runs, such as an editor's unsaved changes, under name; a second call with the same language and name replaces them, and none removes them. They apply only to languageCode, whether it is shown or is the fallback, so editing a language that isn't showing changes nothing on screen. A key only an override has is found without being reported missing. Text already resolved stays as it was. InitializeLanguages() removes every set.

public void SetOverrideTexts(string languageCode, string name, IReadOnlyDictionary<string, string> texts)

Parameters

languageCode string
name string
texts IReadOnlyDictionary<string, string>

TrySetLanguage(string)

Makes a loaded language current. Text already resolved stays as it was; only text resolved from here on is in the new language.

public bool TrySetLanguage(string languageCode)

Parameters

languageCode string

Returns

bool