Skip to content

Translation

Eduard Gushchin edited this page Jul 1, 2026 · 5 revisions

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

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

Overview

Stores translated messages for one locale.

Syntax

public sealed class Electron2D.Translation : Electron2D.Resource

Godot 4.7 C# profile compatibility

Profile: Electron2D 0.1.0 2D
Status: Partial / Not verified
Out of profile: yes
Godot reference: Translation

Locale-bound resource with source message keys, optional contexts and deterministic message listing.

Remarks

A translation resource maps a source message key and optional context to a translated message for Electron2D.Translation.Locale. Register translation resources with Electron2D.TranslationServer.AddTranslation(Electron2D.Translation) so Electron2D.Object.Tr(System.String,System.String) and Electron2D.TranslationServer.Translate(System.String,System.String) can resolve them.

Electron2D 0.1.0 Preview keeps this resource in memory. Loading translation files from project resources is handled by later settings and import tasks.

Thread Safety

This type is not synchronized. Create and mutate translation resources before registering them, or coordinate access externally.

Since

This class is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.TranslationServer

Members

Member Kind Summary
Locale Property Gets or sets the locale represented by this translation.
Electron2D.Translation() Constructor Initializes a new instance of the Translation type.
AddMessage(System.String, System.String, System.String) Method Adds or replaces a translated message.
EraseMessage(System.String, System.String) Method Removes a translated message if it exists.
GetMessage(System.String, System.String) Method Gets a translated message by source key and context.
GetMessageList() Method Gets the source message keys stored by this translation.

Member Details

Locale

Kind: Property

public System.String Locale { get; set; }

Summary

Gets or sets the locale represented by this translation.

Remarks

The assigned value is normalized by replacing hyphens with underscores, trimming whitespace and normalizing the language part to lowercase and the region part to uppercase. For example, pt-BR is stored as pt_BR.

Value

The current locale value.

Exceptions

  • System.ArgumentNullException: Thrown when the assigned value is null.

Thread Safety

This property is not synchronized.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Translation

Electron2D.Translation()

Kind: Constructor

public Electron2D.Translation()

Summary

Initializes a new instance of the Translation type.

Remarks

The new instance follows the lifetime and validation rules of its declaring type.

Thread Safety

This member is not synchronized. Call it from the thread that owns the related object unless the declaring type states otherwise.

Since

This API is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Translation

AddMessage(System.String, System.String, System.String)

Kind: Method

public System.Void AddMessage(System.String, System.String, System.String)(System.String srcMessage, System.String xlatedMessage, System.String context)

Summary

Adds or replaces a translated message.

Remarks

Re-adding the same srcMessage and context replaces the previous translated text. Contexts let different UI locations use the same source key with different translations.

Parameters

  • srcMessage: The source message key.
  • xlatedMessage: The translated message text.
  • context: The optional message context.

Exceptions

  • System.ArgumentNullException: Thrown when srcMessage, xlatedMessage or context is null.

Thread Safety

This method is not synchronized.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Translation.EraseMessage(System.String,System.String)
  • Electron2D.Translation.GetMessage(System.String,System.String)

EraseMessage(System.String, System.String)

Kind: Method

public System.Void EraseMessage(System.String, System.String)(System.String srcMessage, System.String context)

Summary

Removes a translated message if it exists.

Remarks

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

Parameters

  • srcMessage: The source message key.
  • context: The optional message context.

Exceptions

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

Thread Safety

This method is not synchronized.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Translation.AddMessage(System.String,System.String,System.String)

GetMessage(System.String, System.String)

Kind: Method

public System.String GetMessage(System.String, System.String)(System.String srcMessage, System.String context)

Summary

Gets a translated message by source key and context.

Remarks

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

Parameters

  • srcMessage: The source message key.
  • context: The optional message context.

Returns

The translated message, or an empty string when no matching message exists in this resource.

Exceptions

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

Thread Safety

This method is not synchronized.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Translation.AddMessage(System.String,System.String,System.String)

GetMessageList()

Kind: Method

public System.String[] GetMessageList()()

Summary

Gets the source message keys stored by this translation.

Remarks

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

Returns

A stable, ordinally sorted array of unique source message keys.

Thread Safety

This method is not synchronized.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Translation

Clone this wiki locally