Skip to content

TranslationServer

Eduard Gushchin edited this page Jun 21, 2026 · 5 revisions

Home | API by Category | Complete API Index | API Compatibility

Field Value
Full name Electron2D.TranslationServer
Namespace Electron2D
Kind class
Category Display and Localization

Overview

Provides process-wide translation lookup and locale selection.

Syntax

public static class Electron2D.TranslationServer

Remarks

The translation server stores in-memory Electron2D.Translation resources and resolves messages for the current locale. It is the backing service for Electron2D.Object.Tr(System.String,System.String).

The 0.1.0 Preview lookup policy checks the exact locale, the base language, the en fallback locale and then returns the original message key.

Thread Safety

All methods synchronize access to the process-wide translation registry. Returned arrays are snapshots and may be read from any thread.

Since

This class is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Translation

Members

Member Kind Summary
AddTranslation(Electron2D.Translation) Method Registers a translation resource for lookup.
Clear() Method Removes all registered translation resources.
GetLoadedLocales() Method Gets the locales currently provided by registered translations.
GetLocale() Method Gets the current locale.
RemoveTranslation(Electron2D.Translation) Method Removes a translation resource from lookup.
SetLocale(System.String) Method Sets the current locale used for translation lookup.
Translate(System.String, System.String) Method Translates a message for the current locale.

Member Details

AddTranslation(Electron2D.Translation)

Kind: Method

public static System.Void AddTranslation(Electron2D.Translation)(Electron2D.Translation translation)

Summary

Registers a translation resource for lookup.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • translation: The translation resource to register.

Exceptions

  • System.ArgumentException: Thrown when translation has an empty Electron2D.Translation.Locale.
  • System.ArgumentNullException: Thrown when translation is null.

Thread Safety

This method is safe to call from any thread. Mutating the translation resource while it is registered is not synchronized by the server.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.TranslationServer.Clear
  • Electron2D.TranslationServer.RemoveTranslation(Electron2D.Translation)

Clear()

Kind: Method

public static System.Void Clear()()

Summary

Removes all registered translation resources.

Remarks

This method does not reset the current locale. It only clears the registered translations.

Thread Safety

This method is safe to call from any thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.TranslationServer

GetLoadedLocales()

Kind: Method

public static System.String[] GetLoadedLocales()()

Summary

Gets the locales currently provided by registered translations.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Returns

A stable, ordinally sorted array of unique locale names.

Thread Safety

This method is safe to call from any thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.TranslationServer

GetLocale()

Kind: Method

public static System.String GetLocale()()

Summary

Gets the current locale.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Returns

The normalized locale name used for translation lookup.

Thread Safety

This method is safe to call from any thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.TranslationServer.SetLocale(System.String)

RemoveTranslation(Electron2D.Translation)

Kind: Method

public static System.Void RemoveTranslation(Electron2D.Translation)(Electron2D.Translation translation)

Summary

Removes a translation resource from lookup.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • translation: The translation resource to remove.

Exceptions

  • System.ArgumentNullException: Thrown when translation is null.

Thread Safety

This method is safe to call from any thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.TranslationServer.AddTranslation(Electron2D.Translation)

SetLocale(System.String)

Kind: Method

public static System.Void SetLocale(System.String)(System.String locale)

Summary

Sets the current locale used for translation lookup.

Remarks

The locale is normalized by replacing hyphens with underscores and applying stable casing to the language and region parts.

Parameters

  • locale: The locale name to use, such as en or fr_CA.

Exceptions

  • System.ArgumentException: Thrown when locale is empty or whitespace.
  • System.ArgumentNullException: Thrown when locale is null.

Thread Safety

This method is safe to call from any thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.TranslationServer.GetLocale

Translate(System.String, System.String)

Kind: Method

public static System.String Translate(System.String, System.String)(System.String message, System.String context)

Summary

Translates a message for the current locale.

Remarks

Lookup checks the exact current locale, then its base language, then the en fallback locale. If all lookups miss, the original message is returned unchanged.

Parameters

  • message: The source message key to translate.
  • context: The optional message context.

Returns

The translated message, or message when no registered translation can resolve it.

Exceptions

  • System.ArgumentNullException: Thrown when message or context is null.

Thread Safety

This method is safe to call from any thread as long as registered translation resources are not mutated concurrently.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Object.Tr(System.String,System.String)

Clone this wiki locally