Skip to content

localizationshared Translator

Denis Akopyan edited this page Jul 10, 2025 · 1 revision

Translator Public class

Description

Translation service

Diagram

  flowchart LR
  classDef interfaceStyle stroke-dasharray: 5 5;
  classDef abstractStyle stroke-width:4px
  subgraph Localization.Shared
  Localization.Shared.Translator[[Translator]]
  end
  subgraph Localization.Shared.Interfaces
  Localization.Shared.Interfaces.ITranslator[[ITranslator]]
  class Localization.Shared.Interfaces.ITranslator interfaceStyle;
  end
  subgraph System
System.IDisposable[[IDisposable]]
  end
Localization.Shared.Interfaces.ITranslator --> Localization.Shared.Translator
System.IDisposable --> Localization.Shared.Translator
Loading

Members

Properties

Public properties

Type Name Methods
ISet<string> AllowedLanguages
Language keys that are allowed to be provided for selection
get, init
string CurrentCulture
Currently active culture
get, private set
string FallbackCulture
Default fallback culture key
get, init
IReadOnlyCollection<Language> LoadedLanguages
Languages that have been loaded
get

Methods

Public methods

Returns Name
void ChangeCulture(Language language)
Changes the current culture to the specified language
void Dispose()
IEnumerable<LString> GetAllTranslations()
Retrieves all translations available in the translator
LEnum GetEnum(object enumField)
Retrieves a caches or provides a new LEnum for the given enumField
bool IsLocalizationKnown(string key, string namespace)
Determines whether the given key is known in the given namespace .
void RegisterTranslations(...)
Registers a translations
string Translate(...)
Translates a string with the given key , namespace to the specified culture culture .
string TranslateArgs(...)
Translates a parametrized string with the given key and namespace
bool TryGetString(string key, string namespace, out LString result)

Details

Summary

Translation service

Inheritance

Constructors

Translator

public Translator(ILogger<Translator> logger)
Arguments
Type Name Description
ILogger<Translator> logger

Methods

GetEnum

public virtual LEnum GetEnum(object enumField)
Arguments
Type Name Description
object enumField Enum field
Summary

Retrieves a caches or provides a new LEnum for the given enumField

Returns

Localized enum field

RegisterTranslations [1/2]

public virtual void RegisterTranslations(TranslationSet translations)
Arguments
Type Name Description
TranslationSet translations Translation set to register
Summary

Registers a translations

Remarks

If the translations is already registered, it will be overwritten

RegisterTranslations [2/2]

public virtual void RegisterTranslations(IEnumerable<TranslationSet> translationSets)
Arguments
Type Name Description
IEnumerable<TranslationSet> translationSets

IsLocalizationKnown

public virtual bool IsLocalizationKnown(string key, string namespace)
Arguments
Type Name Description
string key Translation set key
string namespace Translation set namespace
Summary

Determines whether the given key is known in the given namespace .

Returns

True if the translation set is known

Translate [1/2]

public virtual string Translate(string key, string namespace, string culture)
Arguments
Type Name Description
string key Translation set key
string namespace Translation set namespace
string culture Target culture key in the RFC 4646 format
Summary

Translates a string with the given key , namespace to the specified culture culture .

Returns

Localized string

TryGetString

public virtual bool TryGetString(string key, string namespace, out LString result)
Arguments
Type Name Description
string key
string namespace
out LString result

Translate [2/2]

public virtual string Translate(string key, string namespace)
Arguments
Type Name Description
string key Translation set key
string namespace Translation set namespace
Summary

Translates a string with the given key and namespace .

Returns

Localized string

TranslateArgs [1/4]

public virtual string TranslateArgs(string key, string namespace, object arg)
Arguments
Type Name Description
string key Translation set key
string namespace Translation set namespace
object arg Argument to supply to the parametrized string
Summary

Translates a parametrized string with the given key and namespace

Returns

Localized string

TranslateArgs [2/4]

public virtual string TranslateArgs(string key, string namespace, object[] args)
Arguments
Type Name Description
string key Translation set key
string namespace Translation set namespace
object``[] args Arguments to supply to the parametrized string
Summary

Translates a parametrized string with the given key and namespace

Returns

Localized string

TranslateArgs [3/4]

public virtual string TranslateArgs(string key, string namespace, string culture, object arg)
Arguments
Type Name Description
string key Translation set key
string namespace Translation set namespace
string culture Target culture
object arg Argument to supply to the parametrized string
Summary

Translates a parametrized string with the given key and namespace to the specified culture .

Returns

Localized string

TranslateArgs [4/4]

public virtual string TranslateArgs(string key, string namespace, string culture, object[] args)
Arguments
Type Name Description
string key Translation set key
string namespace Translation set namespace
string culture Target culture
object``[] args Arguments to supply to the parametrized string
Summary

Translates a parametrized string with the given key and namespace to the specified culture .

Returns

Localized string

GetAllTranslations

public virtual IEnumerable<LString> GetAllTranslations()
Summary

Retrieves all translations available in the translator

Returns

Enumeration of translations

ChangeCulture

public virtual void ChangeCulture(Language language)
Arguments
Type Name Description
Language language Target culture
Summary

Changes the current culture to the specified language

Dispose

public virtual void Dispose()

Properties

CurrentCulture

public virtual string CurrentCulture { get; private set; }
Summary

Currently active culture

FallbackCulture

public virtual string FallbackCulture { get; init; }
Summary

Default fallback culture key

LoadedLanguages

public virtual IReadOnlyCollection<Language> LoadedLanguages { get; }
Summary

Languages that have been loaded

AllowedLanguages

public virtual ISet<string> AllowedLanguages { get; init; }
Summary

Language keys that are allowed to be provided for selection

Remarks

Leaving this empty means that all loaded languages are allowed

Generated with ModularDoc

Clone this wiki locally