I18N.DotNet v1.3.1
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Properties | List of all members
AutoLoadLocalizer Class Reference

Implementation of a localizer which configuration is automatically loaded from an embedded resource. More...

Inheritance diagram for AutoLoadLocalizer:
ILoadableLocalizer ILocalizer

Public Member Functions

 AutoLoadLocalizer (string resourceName=DEFAULT_RESOURCE_NAME, Assembly? assembly=null)
 Constructor. More...
 
string Localize (PlainString text)
 Localizes a string. Converts the base-language string text to its corresponding language-specific localized value. More...
 
string Localize (FormattableString frmtText)
 Localizes an interpolated string. Converts the composite format string of the base-language formattable string frmtText (e.g. an interpolated string) to its corresponding language-specific localized composite format value, and then generates the result by formatting the localized composite format value along with the frmtText arguments by using the formatting conventions of the localizer culture. More...
 
IEnumerable< string > Localize (IEnumerable< string > texts)
 Localizes multiple strings. Converts the base-language strings in texts to their corresponding language-specific localized values. More...
 
string LocalizeFormat (string format, params object[] args)
 Localizes and then formats a string. Converts the base-language format string format to its corresponding language-specific localized format value, and then generates the result by formatting the localized format value along with the args arguments by using the formatting conventions of the localizer culture. More...
 
ILocalizer Context (string contextId)
 Gets the localizer for a context in the current localizer. Contexts are used to disambiguate the conversion of the same base-language string to different language-specific strings depending on the context where the conversion is performed. More...
 
ILocalizer Context (IEnumerable< string > splitContextIds)
 Gets the localizer for a context in the current localizer. Contexts are used to disambiguate the conversion of the same base-language string to different language-specific strings depending on the context where the conversion is performed. More...
 
void LoadXML (string filepath, CultureInfo? culture=null)
 Loads translations for the given culture from a localization configuration file in XML format. All the translations loaded previously in the localizer are discarded and replaced with the new ones. More...
 
void LoadXML (string filepath, string language)
 Loads translations for the given language from a localization configuration file in XML format. All the translations loaded previously in the localizer are discarded and replaced with the new ones. More...
 
void LoadXML (string filepath, bool merge)
 Loads translations for the current localizer language from a localization configuration file in XML format.
Parameters
filepathPath to the localization configuration file.
mergeReplaces the current translations with the loaded ones when<c>false, otherwise merges both (existing translations are overridden with loaded ones).
Exceptions
ParseExceptionThrown when the input file cannot be parsed properly.
More...
 
void LoadXML (Stream stream, CultureInfo? culture=null)
 Loads translations for the given culture from a localization configuration file in XML format obtained from a stream. All the translations loaded previously in the localizer are discarded and replaced with the new ones. More...
 
void LoadXML (Stream stream, string language)
 Loads translations for the given language from a localization configuration file obtained in XML format from a stream. All the translations loaded previously in the localizer are discarded and replaced with the new ones. More...
 
void LoadXML (Stream stream, bool merge)
 Loads translations for the current localizer language from a localization configuration file in XML format obtained from a stream.
Parameters
streamStream with the localization configuration.
mergeReplaces the current translations with the loaded ones when<c>false, otherwise merges both (existing translations are overridden with loaded ones).
Exceptions
ParseExceptionThrown when the stream contents cannot be parsed properly.
More...
 
void LoadXML (XDocument doc, CultureInfo? culture=null)
 Loads translations for the given culture from a localization configuration in an XML document. All the translations loaded previously in the localizer are discarded and replaced with the new ones. More...
 
void LoadXML (XDocument doc, string language)
 Loads translations for the given language from a localization configuration in an XML document. All the translations loaded previously in the localizer are discarded and replaced with the new ones. More...
 
void LoadXML (XDocument doc, bool merge)
 Loads translations for the current localizer language from a localization configuration in an XML document.
Parameters
docXML document with the localization configuration.
mergeReplaces the current translations with the loaded ones when<c>false, otherwise merges both (existing translations are overridden with loaded ones).
Exceptions
ParseExceptionThrown when the stream contents cannot be parsed properly.
More...
 
void LoadXML (Assembly assembly, string resourceName, CultureInfo? culture=null)
 Loads translations for the given culture from a localization configuration file in XML format obtained from an embedded resource in the given assembly. All the translations loaded previously in the localizer are discarded and replaced with the new ones. More...
 
void LoadXML (Assembly assembly, string resourceName, string language)
 Loads translations for the given language from a localization configuration file in XML format obtained from an embedded resource in the given assembly. All the translations loaded previously in the localizer are discarded and replaced with the new ones. More...
 
void LoadXML (Assembly assembly, string resourceName, bool merge)
 Loads translations for the current localizer language from a localization configuration file in XML format obtained from an embedded resource in the given assembly.
Parameters
assemblyAssembly that contains the embedded XML file.
resourceNameName of the embedded resource for the XML file.
mergeReplaces the current translations with the loaded ones when<c>false, otherwise merges both (existing translations are overridden with loaded ones).
Exceptions
ParseExceptionThrown when the stream contents cannot be parsed properly.
InvalidOperationExceptionThrown when the embedded resource could not be found in the given assembly.
More...
 
void Load (CultureInfo? culture)
 Loads translations for the given culture from the embedded resource specified when creating the instance. More...
 
void Load (string language)
 Loads translations for the given language from the embedded resource specified when creating the instance. More...
 

Static Public Attributes

const string DEFAULT_RESOURCE_NAME = "Resources.I18N.xml"
 Default identifier for the embedded resource containing the translations. More...
 

Properties

string TargetLanguage [get]
 Target language of the localizer. More...
 
CultureInfo TargetCulture [get]
 Target culture of the localizer. More...
 

Detailed Description

Implementation of a localizer which configuration is automatically loaded from an embedded resource.

Constructor & Destructor Documentation

◆ AutoLoadLocalizer()

AutoLoadLocalizer ( string  resourceName = DEFAULT_RESOURCE_NAME,
Assembly?  assembly = null 
)

Constructor.

When the localization methods are called for the first time, the translations are automatically loaded from the embedded resource identified by resourceName inside the given assembly (if translations have not been previously loaded explicitly).

Parameters
resourceNameName of the embedded resource for the XML file.
assemblyAssembly that contains the embedded XML file (the calling assembly will be used if null).

Member Function Documentation

◆ Context() [1/2]

ILocalizer Context ( IEnumerable< string >  splitContextIds)

Gets the localizer for a context in the current localizer. Contexts are used to disambiguate the conversion of the same base-language string to different language-specific strings depending on the context where the conversion is performed.

Implements ILocalizer.

◆ Context() [2/2]

ILocalizer Context ( string  contextId)

Gets the localizer for a context in the current localizer. Contexts are used to disambiguate the conversion of the same base-language string to different language-specific strings depending on the context where the conversion is performed.

Implements ILocalizer.

◆ Load() [1/2]

void Load ( CultureInfo?  culture)

Loads translations for the given culture from the embedded resource specified when creating the instance.

Parameters
cultureCulture for the target language of translations, or null to use the current UI culture (obtained from System.Globalization.CultureInfo.CurrentUICulture).
Exceptions
ILoadableLocalizer.ParseExceptionThrown when the embedded resource contents cannot be parsed properly.
InvalidOperationExceptionThrown when the embedded resource could not be found.

◆ Load() [2/2]

void Load ( string  language)

Loads translations for the given language from the embedded resource specified when creating the instance.

Parameters
languageName, code or identifier for the target language of translations.
Exceptions
ILoadableLocalizer.ParseExceptionThrown when the embedded resource contents cannot be parsed properly.
InvalidOperationExceptionThrown when the embedded resource could not be found.

◆ LoadXML() [1/12]

void LoadXML ( Assembly  assembly,
string  resourceName,
bool  merge 
)

Loads translations for the current localizer language from a localization configuration file in XML format obtained from an embedded resource in the given assembly.

Parameters
assemblyAssembly that contains the embedded XML file.
resourceNameName of the embedded resource for the XML file.
mergeReplaces the current translations with the loaded ones when<c>false, otherwise merges both (existing translations are overridden with loaded ones).
Exceptions
ParseExceptionThrown when the stream contents cannot be parsed properly.
InvalidOperationExceptionThrown when the embedded resource could not be found in the given assembly.

Implements ILoadableLocalizer.

◆ LoadXML() [2/12]

void LoadXML ( Assembly  assembly,
string  resourceName,
CultureInfo?  culture = null 
)

Loads translations for the given culture from a localization configuration file in XML format obtained from an embedded resource in the given assembly. All the translations loaded previously in the localizer are discarded and replaced with the new ones.

Implements ILoadableLocalizer.

◆ LoadXML() [3/12]

void LoadXML ( Assembly  assembly,
string  resourceName,
string  language 
)

Loads translations for the given language from a localization configuration file in XML format obtained from an embedded resource in the given assembly. All the translations loaded previously in the localizer are discarded and replaced with the new ones.

Implements ILoadableLocalizer.

◆ LoadXML() [4/12]

void LoadXML ( Stream  stream,
bool  merge 
)

Loads translations for the current localizer language from a localization configuration file in XML format obtained from a stream.

Parameters
streamStream with the localization configuration.
mergeReplaces the current translations with the loaded ones when<c>false, otherwise merges both (existing translations are overridden with loaded ones).
Exceptions
ParseExceptionThrown when the stream contents cannot be parsed properly.

Implements ILoadableLocalizer.

◆ LoadXML() [5/12]

void LoadXML ( Stream  stream,
CultureInfo?  culture = null 
)

Loads translations for the given culture from a localization configuration file in XML format obtained from a stream. All the translations loaded previously in the localizer are discarded and replaced with the new ones.

Implements ILoadableLocalizer.

◆ LoadXML() [6/12]

void LoadXML ( Stream  stream,
string  language 
)

Loads translations for the given language from a localization configuration file obtained in XML format from a stream. All the translations loaded previously in the localizer are discarded and replaced with the new ones.

Implements ILoadableLocalizer.

◆ LoadXML() [7/12]

void LoadXML ( string  filepath,
bool  merge 
)

Loads translations for the current localizer language from a localization configuration file in XML format.

Parameters
filepathPath to the localization configuration file.
mergeReplaces the current translations with the loaded ones when<c>false, otherwise merges both (existing translations are overridden with loaded ones).
Exceptions
ParseExceptionThrown when the input file cannot be parsed properly.

Implements ILoadableLocalizer.

◆ LoadXML() [8/12]

void LoadXML ( string  filepath,
CultureInfo?  culture = null 
)

Loads translations for the given culture from a localization configuration file in XML format. All the translations loaded previously in the localizer are discarded and replaced with the new ones.

Implements ILoadableLocalizer.

◆ LoadXML() [9/12]

void LoadXML ( string  filepath,
string  language 
)

Loads translations for the given language from a localization configuration file in XML format. All the translations loaded previously in the localizer are discarded and replaced with the new ones.

Implements ILoadableLocalizer.

◆ LoadXML() [10/12]

void LoadXML ( XDocument  doc,
bool  merge 
)

Loads translations for the current localizer language from a localization configuration in an XML document.

Parameters
docXML document with the localization configuration.
mergeReplaces the current translations with the loaded ones when<c>false, otherwise merges both (existing translations are overridden with loaded ones).
Exceptions
ParseExceptionThrown when the stream contents cannot be parsed properly.

Implements ILoadableLocalizer.

◆ LoadXML() [11/12]

void LoadXML ( XDocument  doc,
CultureInfo?  culture = null 
)

Loads translations for the given culture from a localization configuration in an XML document. All the translations loaded previously in the localizer are discarded and replaced with the new ones.

Implements ILoadableLocalizer.

◆ LoadXML() [12/12]

void LoadXML ( XDocument  doc,
string  language 
)

Loads translations for the given language from a localization configuration in an XML document. All the translations loaded previously in the localizer are discarded and replaced with the new ones.

Implements ILoadableLocalizer.

◆ Localize() [1/3]

string Localize ( FormattableString  frmtText)

Localizes an interpolated string. Converts the composite format string of the base-language formattable string frmtText (e.g. an interpolated string) to its corresponding language-specific localized composite format value, and then generates the result by formatting the localized composite format value along with the frmtText arguments by using the formatting conventions of the localizer culture.

Implements ILocalizer.

◆ Localize() [2/3]

IEnumerable< string > Localize ( IEnumerable< string >  texts)

Localizes multiple strings. Converts the base-language strings in texts to their corresponding language-specific localized values.

Implements ILocalizer.

◆ Localize() [3/3]

string Localize ( PlainString  text)

Localizes a string. Converts the base-language string text to its corresponding language-specific localized value.

Implements ILocalizer.

◆ LocalizeFormat()

string LocalizeFormat ( string  format,
params object[]  args 
)

Localizes and then formats a string. Converts the base-language format string format to its corresponding language-specific localized format value, and then generates the result by formatting the localized format value along with the args arguments by using the formatting conventions of the localizer culture.

Implements ILocalizer.

Member Data Documentation

◆ DEFAULT_RESOURCE_NAME

const string DEFAULT_RESOURCE_NAME = "Resources.I18N.xml"
static

Default identifier for the embedded resource containing the translations.

Property Documentation

◆ TargetCulture

CultureInfo TargetCulture
get

Target culture of the localizer.

Implements ILocalizer.

◆ TargetLanguage

string TargetLanguage
get

Target language of the localizer.

Implements ILocalizer.