BogaNet 1.4.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Properties | Events | List of all members
BogaNet.i18n.Localizer Class Reference

i18n localizer for the application. More...

Inheritance diagram for BogaNet.i18n.Localizer:
BogaNet.Util.Singleton< Localizer > BogaNet.i18n.ILocalizer

Public Member Functions

virtual string GetText (string key, TextType textType=TextType.LABEL)
 Gets the text for a key and the current culture.
 
virtual bool TryGetText (string key, out string result, TextType textType=TextType.LABEL)
 Tries to get the text for a key and the current culture.
 
virtual string GetText (string key, CultureInfo culture, TextType textType=TextType.LABEL)
 Gets the text for a key and a given culture.
 
virtual bool TryGetText (string key, out string result, CultureInfo culture, TextType textType=TextType.LABEL)
 Tries to get the text for a key and a given culture.
 
virtual string GetTextWithReplacements (string key, TextType textType=TextType.LABEL, params string[] replacements)
 Gets the text for a key with replacements (for placeholders like '{0}') and the current culture.
 
virtual bool TryGetTextWithReplacements (string key, out string result, TextType textType=TextType.LABEL, params string[] replacements)
 Tries to get the text for a key with replacements (for placeholders like '{0}') and the current culture.
 
virtual string GetTextWithReplacements (string key, CultureInfo culture, TextType textType=TextType.LABEL, params string[] replacements)
 Gets the text for a key with replacements (for placeholders like '{0}') and a given culture.
 
virtual bool TryGetTextWithReplacements (string key, out string result, CultureInfo culture, TextType textType=TextType.LABEL, params string[] replacements)
 Tries to get the text for a key with replacements (for placeholders like '{0}') and a given culture.
 
virtual bool ContainsKey (string key, CultureInfo? culture=null)
 Checks if a given key exists in the localizer.
 
virtual void Add (string key, CultureInfo culture, string value)
 Adds a translated text.
 
virtual bool Remove (string key, CultureInfo? culture=null)
 Removes a key and assigned translated texts.
 
virtual void Clear ()
 Clears all translations.
 
virtual void Load (Dictionary< string, string[]> dataDict)
 Loads translations from a given Dictionary.
 
virtual bool LoadFiles (params string[] files)
 Load translation files (CSV) from a given path.
 
virtual async Task< bool > LoadFilesAsync (params string[] files)
 Load translation files (CSV) from a given path asynchronously.
 
virtual bool LoadFilesFromUrl (params string[] urls)
 Load translation files (CSV) from given URLs.
 
virtual async Task< bool > LoadFilesFromUrlAsync (params string[] urls)
 Load translation files (CSV) from given URLs asynchronously.
 
virtual bool SaveFile (string filename)
 Saves all translations to a given file (CSV).
 
virtual async Task< bool > SaveFileAsync (string filename)
 Saves all translations to a given file (CSV) asynchronously.
 
override string ToString ()
 
- Public Member Functions inherited from BogaNet.i18n.ILocalizer
delegate void CultureChanged (CultureInfo lang)
 Delegate for culture changes.
 
delegate void FilesLoaded (params string[] files)
 Delegate for the load status of the files.
 
delegate void FileSaved (string file)
 Delegate for the save status of the file.
 

Protected Member Functions

 Localizer ()
 
string getText (string key, string culture, TextType textType, bool returnDefault=true)
 
string getEntries ()
 
void hasChanged ()
 

Protected Attributes

CultureInfo _culture = Constants.CurrentCulture
 
readonly List< CultureInfo > _cultures = []
 
readonly Dictionary< string, Dictionary< string, string > > _messages = new()
 

Properties

virtual CultureInfo Culture [get, set]
 Current culture.
 
virtual List< CultureInfo > SupportedCultures [get]
 Supported cultures.
 
virtual List< string > MissingTranslations = [] [get]
 List of missing translations.
 
virtual List< string > MissingCountries = [] [get]
 List of missing country codes.
 
virtual List< string > RemovedTranslations = [] [get]
 List of removed translations.
 
virtual List< string > AddedTranslations = [] [get]
 List of added translations.
 
virtual bool IsLoaded [get, protected set]
 Is the localizer loaded?
 
virtual List< string > Keys [get]
 Current keys of the localizer.
 
virtual int Count [get]
 Current count of keys from the localizer.
 
- Properties inherited from BogaNet.Util.Singleton< Localizer >
static T Instance [get]
 
- Properties inherited from BogaNet.i18n.ILocalizer

Events

ILocalizer.? CultureChanged OnCultureChanged
 
ILocalizer.? FilesLoaded OnFilesLoaded
 
ILocalizer.? FileSaved OnFileSaved
 
- Events inherited from BogaNet.i18n.ILocalizer
CultureChanged OnCultureChanged
 Event triggered whenever the culture changes.
 
FilesLoaded OnFilesLoaded
 Event triggered whenever the files are loaded.
 
FileSaved OnFileSaved
 Event triggered whenever the file is saved.
 

Detailed Description

i18n localizer for the application.

Constructor & Destructor Documentation

◆ Localizer()

BogaNet.i18n.Localizer.Localizer ( )
protected

Member Function Documentation

◆ Add()

virtual void BogaNet.i18n.Localizer.Add ( string key,
CultureInfo culture,
string value )
virtual

Adds a translated text.

Parameters
keyKey for the text
cultureCulture for the text
valueValue of the text
Exceptions
ArgumentNullException

Implements BogaNet.i18n.ILocalizer.

◆ Clear()

virtual void BogaNet.i18n.Localizer.Clear ( )
virtual

Clears all translations.

Implements BogaNet.i18n.ILocalizer.

◆ ContainsKey()

virtual bool BogaNet.i18n.Localizer.ContainsKey ( string key,
CultureInfo? culture = null )
virtual

Checks if a given key exists in the localizer.

Parameters
keyKey to check
cultureCulture of the key (optional, default: any)
Returns
True if the key exists in the localizer
Exceptions
ArgumentNullException

Implements BogaNet.i18n.ILocalizer.

◆ getEntries()

string BogaNet.i18n.Localizer.getEntries ( )
protected

◆ GetText() [1/2]

virtual string BogaNet.i18n.Localizer.GetText ( string key,
CultureInfo culture,
TextType textType = TextType.LABEL )
virtual

Gets the text for a key and a given culture.

Parameters
keyKey for the text
cultureCulture for the text
textTypeType of the text (optional, default: LABEL)
Returns
Text for the key
Exceptions
ArgumentNullException

Implements BogaNet.i18n.ILocalizer.

◆ getText()

string BogaNet.i18n.Localizer.getText ( string key,
string culture,
TextType textType,
bool returnDefault = true )
protected

◆ GetText() [2/2]

virtual string BogaNet.i18n.Localizer.GetText ( string key,
TextType textType = TextType.LABEL )
virtual

Gets the text for a key and the current culture.

Parameters
keyKey for the text
textTypeType of the text (optional, default: LABEL)
Returns
Text for the key
Exceptions
ArgumentNullException

Implements BogaNet.i18n.ILocalizer.

◆ GetTextWithReplacements() [1/2]

virtual string BogaNet.i18n.Localizer.GetTextWithReplacements ( string key,
CultureInfo culture,
TextType textType = TextType.LABEL,
params string[] replacements )
virtual

Gets the text for a key with replacements (for placeholders like '{0}') and a given culture.

Parameters
keyKey for the text
cultureCulture for the text
textTypeType of the text (optional, default: LABEL)
replacementsReplacements for the text
Returns
Text with replacements for the key
Exceptions
ArgumentNullException

Implements BogaNet.i18n.ILocalizer.

◆ GetTextWithReplacements() [2/2]

virtual string BogaNet.i18n.Localizer.GetTextWithReplacements ( string key,
TextType textType = TextType.LABEL,
params string[] replacements )
virtual

Gets the text for a key with replacements (for placeholders like '{0}') and the current culture.

Parameters
keyKey for the text
textTypeType of the text (optional, default: LABEL)
replacementsReplacements for the text
Returns
Text with replacements for the key
Exceptions
ArgumentNullException

Implements BogaNet.i18n.ILocalizer.

◆ hasChanged()

void BogaNet.i18n.Localizer.hasChanged ( )
protected

◆ Load()

virtual void BogaNet.i18n.Localizer.Load ( Dictionary< string, string[]> dataDict)
virtual

Loads translations from a given Dictionary.

Parameters
dataDictDictionary to load

returns>True if the operation was successful

Exceptions
Exception

Implements BogaNet.i18n.ILocalizer.

◆ LoadFiles()

virtual bool BogaNet.i18n.Localizer.LoadFiles ( params string[] files)
virtual

Load translation files (CSV) from a given path.

Parameters
filesFiles to load

returns>True if the operation was successful

Exceptions
Exception

Implements BogaNet.i18n.ILocalizer.

◆ LoadFilesAsync()

virtual async Task< bool > BogaNet.i18n.Localizer.LoadFilesAsync ( params string[] files)
virtual

Load translation files (CSV) from a given path asynchronously.

Parameters
filesFiles to load

returns>True if the operation was successful

Exceptions
Exception

Implements BogaNet.i18n.ILocalizer.

◆ LoadFilesFromUrl()

virtual bool BogaNet.i18n.Localizer.LoadFilesFromUrl ( params string[] urls)
virtual

Load translation files (CSV) from given URLs.

Parameters
urlsURLs of files to load

returns>True if the operation was successful

Exceptions
Exception

Implements BogaNet.i18n.ILocalizer.

◆ LoadFilesFromUrlAsync()

virtual async Task< bool > BogaNet.i18n.Localizer.LoadFilesFromUrlAsync ( params string[] urls)
virtual

Load translation files (CSV) from given URLs asynchronously.

Parameters
urlsURLs of files to load

returns>True if the operation was successful

Exceptions
Exception

Implements BogaNet.i18n.ILocalizer.

◆ Remove()

virtual bool BogaNet.i18n.Localizer.Remove ( string key,
CultureInfo? culture = null )
virtual

Removes a key and assigned translated texts.

Parameters
keyKey to remove
cultureCulture of the key (optional, default: all)

returns>True if the operation was successful

Exceptions
ArgumentNullException

Implements BogaNet.i18n.ILocalizer.

◆ SaveFile()

virtual bool BogaNet.i18n.Localizer.SaveFile ( string filename)
virtual

Saves all translations to a given file (CSV).

Parameters
filenameFile for the translations

returns>True if the operation was successful

Exceptions
Exception

Implements BogaNet.i18n.ILocalizer.

◆ SaveFileAsync()

virtual async Task< bool > BogaNet.i18n.Localizer.SaveFileAsync ( string filename)
virtual

Saves all translations to a given file (CSV) asynchronously.

Parameters
filenameFile for the translations

returns>True if the operation was successful

Exceptions
Exception

Implements BogaNet.i18n.ILocalizer.

◆ ToString()

override string BogaNet.i18n.Localizer.ToString ( )

◆ TryGetText() [1/2]

virtual bool BogaNet.i18n.Localizer.TryGetText ( string key,
out string result,
CultureInfo culture,
TextType textType = TextType.LABEL )
virtual

Tries to get the text for a key and a given culture.

Parameters
keyKey for the text
resultout parameter for the result
cultureCulture for the text
textTypeType of the text (optional, default: LABEL)
Returns
True if the operation was successful
Exceptions
ArgumentNullException

Implements BogaNet.i18n.ILocalizer.

◆ TryGetText() [2/2]

virtual bool BogaNet.i18n.Localizer.TryGetText ( string key,
out string result,
TextType textType = TextType.LABEL )
virtual

Tries to get the text for a key and the current culture.

Parameters
keyKey for the text
resultout parameter for the result
textTypeType of the text (optional, default: LABEL)
Returns
True if the operation was successful
Exceptions
ArgumentNullException

Implements BogaNet.i18n.ILocalizer.

◆ TryGetTextWithReplacements() [1/2]

virtual bool BogaNet.i18n.Localizer.TryGetTextWithReplacements ( string key,
out string result,
CultureInfo culture,
TextType textType = TextType.LABEL,
params string[] replacements )
virtual

Tries to get the text for a key with replacements (for placeholders like '{0}') and a given culture.

Parameters
keyKey for the text
resultout parameter for the result
cultureCulture for the text
textTypeType of the text (optional, default: LABEL)
replacementsReplacements for the text
Returns
True if the operation was successful
Exceptions
ArgumentNullException

Implements BogaNet.i18n.ILocalizer.

◆ TryGetTextWithReplacements() [2/2]

virtual bool BogaNet.i18n.Localizer.TryGetTextWithReplacements ( string key,
out string result,
TextType textType = TextType.LABEL,
params string[] replacements )
virtual

Tries to get the text for a key with replacements (for placeholders like '{0}') and the current culture.

Parameters
keyKey for the text
resultout parameter for the result
textTypeType of the text (optional, default: LABEL)
replacementsReplacements for the text
Returns
True if the operation was successful
Exceptions
ArgumentNullException

Implements BogaNet.i18n.ILocalizer.

Member Data Documentation

◆ _culture

CultureInfo BogaNet.i18n.Localizer._culture = Constants.CurrentCulture
protected

◆ _cultures

readonly List<CultureInfo> BogaNet.i18n.Localizer._cultures = []
protected

◆ _messages

readonly Dictionary<string, Dictionary<string, string> > BogaNet.i18n.Localizer._messages = new()
protected

Property Documentation

◆ AddedTranslations

virtual List<string> BogaNet.i18n.Localizer.AddedTranslations = []
get

List of added translations.

Implements BogaNet.i18n.ILocalizer.

◆ Count

virtual int BogaNet.i18n.Localizer.Count
get

Current count of keys from the localizer.

Implements BogaNet.i18n.ILocalizer.

◆ Culture

virtual CultureInfo BogaNet.i18n.Localizer.Culture
getset

Current culture.

Implements BogaNet.i18n.ILocalizer.

◆ IsLoaded

virtual bool BogaNet.i18n.Localizer.IsLoaded
getprotected set

Is the localizer loaded?

Implements BogaNet.i18n.ILocalizer.

◆ Keys

virtual List<string> BogaNet.i18n.Localizer.Keys
get

Current keys of the localizer.

Implements BogaNet.i18n.ILocalizer.

◆ MissingCountries

virtual List<string> BogaNet.i18n.Localizer.MissingCountries = []
get

List of missing country codes.

Implements BogaNet.i18n.ILocalizer.

◆ MissingTranslations

virtual List<string> BogaNet.i18n.Localizer.MissingTranslations = []
get

List of missing translations.

Implements BogaNet.i18n.ILocalizer.

◆ RemovedTranslations

virtual List<string> BogaNet.i18n.Localizer.RemovedTranslations = []
get

List of removed translations.

Implements BogaNet.i18n.ILocalizer.

◆ SupportedCultures

virtual List<CultureInfo> BogaNet.i18n.Localizer.SupportedCultures
get

Supported cultures.

Implements BogaNet.i18n.ILocalizer.

Event Documentation

◆ OnCultureChanged

ILocalizer.? CultureChanged BogaNet.i18n.Localizer.OnCultureChanged

◆ OnFileSaved

ILocalizer.? FileSaved BogaNet.i18n.Localizer.OnFileSaved

◆ OnFilesLoaded

ILocalizer.? FilesLoaded BogaNet.i18n.Localizer.OnFilesLoaded

The documentation for this class was generated from the following file: