Table of Contents

Class TranslationServer

Namespace
Godot
Assembly
GodotSharp.dll

The translation server is the API backend that manages all language translations.

Translations are stored in TranslationDomains, which can be accessed by name. The most commonly used translation domain is the main translation domain. It always exists and can be accessed using an empty StringName. The translation server provides wrapper methods for accessing the main translation domain directly, without having to fetch the translation domain first. Custom translation domains are mainly for advanced usages like editor plugins. Names starting with godot. are reserved for engine internals.

public static class TranslationServer
Inheritance
TranslationServer
Inherited Members

Properties

PseudolocalizationEnabled

If true, enables the use of pseudolocalization on the main translation domain. See ProjectSettings.internationalization/pseudolocalization/use_pseudolocalization for details.

public static bool PseudolocalizationEnabled { get; set; }

Property Value

bool

Singleton

public static TranslationServerInstance Singleton { get; }

Property Value

TranslationServerInstance

Methods

AddTranslation(Translation)

Adds a translation to the main translation domain.

public static void AddTranslation(Translation translation)

Parameters

translation Translation

Clear()

Removes all translations from the main translation domain.

public static void Clear()

CompareLocales(string, string)

Compares two locales and returns a similarity score between 0 (no match) and 10 (full match).

public static int CompareLocales(string localeA, string localeB)

Parameters

localeA string
localeB string

Returns

int

GetAllCountries()

Returns an array of known country codes.

public static string[] GetAllCountries()

Returns

string[]

GetAllLanguages()

Returns array of known language codes.

public static string[] GetAllLanguages()

Returns

string[]

GetAllScripts()

Returns an array of known script codes.

public static string[] GetAllScripts()

Returns

string[]

GetCountryName(string)

Returns a readable country name for the country code.

public static string GetCountryName(string country)

Parameters

country string

Returns

string

GetLanguageName(string)

Returns a readable language name for the language code.

public static string GetLanguageName(string language)

Parameters

language string

Returns

string

GetLoadedLocales()

Returns an array of all loaded locales of the project.

public static string[] GetLoadedLocales()

Returns

string[]

GetLocale()

Returns the current locale of the project.

See also GetLocale() and GetLocaleLanguage() to query the locale of the user system.

public static string GetLocale()

Returns

string

GetLocaleName(string)

Returns a locale's language and its variant (e.g. "en_US" would return "English (United States)").

public static string GetLocaleName(string locale)

Parameters

locale string

Returns

string

GetOrAddDomain(StringName)

Returns the translation domain with the specified name. An empty translation domain will be created and added if it does not exist.

public static TranslationDomain GetOrAddDomain(StringName domain)

Parameters

domain StringName

Returns

TranslationDomain

GetScriptName(string)

Returns a readable script name for the script code.

public static string GetScriptName(string script)

Parameters

script string

Returns

string

GetToolLocale()

Returns the current locale of the editor.

Note: When called from an exported project returns the same value as GetLocale().

public static string GetToolLocale()

Returns

string

GetTranslationObject(string)

Returns the Translation instance that best matches locale in the main translation domain. Returns null if there are no matches.

public static Translation GetTranslationObject(string locale)

Parameters

locale string

Returns

Translation

HasDomain(StringName)

Returns true if a translation domain with the specified name exists.

public static bool HasDomain(StringName domain)

Parameters

domain StringName

Returns

bool

Pseudolocalize(StringName)

Returns the pseudolocalized string based on the message passed in.

Note: This method always uses the main translation domain.

public static StringName Pseudolocalize(StringName message)

Parameters

message StringName

Returns

StringName

ReloadPseudolocalization()

Reparses the pseudolocalization options and reloads the translation for the main translation domain.

public static void ReloadPseudolocalization()

RemoveDomain(StringName)

Removes the translation domain with the specified name.

Note: Trying to remove the main translation domain is an error.

public static void RemoveDomain(StringName domain)

Parameters

domain StringName

RemoveTranslation(Translation)

Removes the given translation from the main translation domain.

public static void RemoveTranslation(Translation translation)

Parameters

translation Translation

SetLocale(string)

Sets the locale of the project. The locale string will be standardized to match known locales (e.g. en-US would be matched to en_US).

If translations have been loaded beforehand for the new locale, they will be applied.

public static void SetLocale(string locale)

Parameters

locale string

StandardizeLocale(string, bool)

Returns a locale string standardized to match known locales (e.g. en-US would be matched to en_US). If addDefaults is true, the locale may have a default script or country added.

public static string StandardizeLocale(string locale, bool addDefaults = false)

Parameters

locale string
addDefaults bool

Returns

string

Translate(StringName, StringName)

Returns the current locale's translation for the given message and context.

Note: This method always uses the main translation domain.

public static StringName Translate(StringName message, StringName context = null)

Parameters

message StringName
context StringName

Returns

StringName

TranslatePlural(StringName, StringName, int, StringName)

Returns the current locale's translation for the given message, plural message and context.

The number n is the number or quantity of the plural object. It will be used to guide the translation system to fetch the correct plural form for the selected language.

Note: This method always uses the main translation domain.

public static StringName TranslatePlural(StringName message, StringName pluralMessage, int n, StringName context = null)

Parameters

message StringName
pluralMessage StringName
n int
context StringName

Returns

StringName