Class Localizer
The 'Localizer' singleton class is a 'Unity Runtime Adapter' for the localization system while runtime. It provides a convenient interface for managing language localization and retrieving localized assets. This class is responsible for initializing localization, loading and unloading assets, and switching languages.
Inheritance
Implements
Namespace: GUPS.EasyLocalization
Assembly: cs.temp.dll.dll
Syntax
public class Localizer : PersistentSingleton<Localizer>
Properties
CurrentLanguage
Gets or sets the the current selected language used for localization. Note that changing this property does not automatically load the localized text and audio.
Declaration
public ELanguage CurrentLanguage { get; set; }
Property Value
Type | Description |
---|---|
ELanguage |
FallbackLanguage
Gets or sets the fallback language used when the current selected language is not available. Note that changing this property does not automatically load the localized text and audio.
Declaration
public ELanguage FallbackLanguage { get; set; }
Property Value
Type | Description |
---|---|
ELanguage |
IsInitialized
Returns if Initialize was at least called once.
Declaration
public bool IsInitialized { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsInitializing
Returns if the is currently initializing.
Declaration
public bool IsInitializing { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
Get(ELanguage, Type, String)
Retrieves a localized asset of the specified type and by a key. Does not load the asset if it is not loaded.
Declaration
public object Get(ELanguage _Language, Type _AssetType, String _Key)
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The language associated with the localized assets to retrieve. |
Type | _AssetType | The type of localized assets. |
String | _Key | The key associated with the localized assets to retrieve. |
Returns
Type | Description |
---|---|
System.Object | The localized asset based on the key. |
Get(Type, String)
Retrieves a localized asset of the specified type and by a key. First checks the current language, then the fallback language and at last returns the default, if the asset is localized in neiter. Does not load the asset if it is not loaded.
Declaration
public object Get(Type _AssetType, String _Key)
Parameters
Type | Name | Description |
---|---|---|
Type | _AssetType | |
String | _Key | The key associated with the localized data to retrieve. |
Returns
Type | Description |
---|---|
System.Object | The localized data item based on the key. |
Get<T>(ELanguage, String)
Retrieves a localized asset of the specified type and by a key. Does not load the asset if it is not loaded.
Declaration
public T Get<T>(ELanguage _Language, String _Key)
where T : class
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The language associated with the localized assets to retrieve. |
String | _Key | The key associated with the localized assets to retrieve. |
Returns
Type | Description |
---|---|
T | The localized asset based on the key. |
Type Parameters
Name | Description |
---|---|
T | The type of localized assets. |
Get<T>(String)
Retrieves a localized asset of the specified type and by a key. First checks the current language, then the fallback language and at last returns the default, if the asset is localized in neiter. Does not load the asset if it is not loaded.
Declaration
public T Get<T>(String _Key)
where T : class
Parameters
Type | Name | Description |
---|---|---|
String | _Key | The key associated with the localized data to retrieve. |
Returns
Type | Description |
---|---|
T | The localized data item based on the key. |
Type Parameters
Name | Description |
---|---|
T | The type of localized data. |
GetDefault(Type)
Retrieves the default asset for the passed asset type. If there is no default asset for this type, null is returned.
Declaration
public object GetDefault(Type _AssetType)
Parameters
Type | Name | Description |
---|---|---|
Type | _AssetType | The type of asset to retrieve. |
Returns
Type | Description |
---|---|
System.Object |
GetDefault<T>()
Retrieves the default asset for the passed asset type. If there is no default asset for this type, null is returned.
Declaration
public T GetDefault<T>()
where T : class
Returns
Type | Description |
---|---|
T | The default asset of type |
Type Parameters
Name | Description |
---|---|
T | The type of asset to retrieve. |
GetLocations(Type)
Retrieves a list of locations for loading localized data of the specified type. If there is no location for the specified type, an empty list is returned.
Declaration
public List<ILocation> GetLocations(Type _AssetType)
Parameters
Type | Name | Description |
---|---|---|
Type | _AssetType | The type of localized data |
Returns
Type | Description |
---|---|
List<ILocation> | A list of locations for loading the specified type of localized data. |
GetLocations<T>()
Retrieves a list of locations for loading localized data of the specified type. If there is no location for the specified type, an empty list is returned.
Declaration
public List<ILocation> GetLocations<T>()
where T : class
Returns
Type | Description |
---|---|
List<ILocation> | A list of locations for loading the specified type of localized data. |
Type Parameters
Name | Description |
---|---|
T | The type of localized data. |
GetOrLoadAsync(Type, String)
Retrieves or loads a localized asset for the specified type using a key.
Declaration
public async Task<object> GetOrLoadAsync(Type _AssetType, String _Key)
Parameters
Type | Name | Description |
---|---|---|
Type | _AssetType | The type of localized asset. |
String | _Key | The key associated with the localized asset to retrieve. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | The localized asset based on the key. |
GetOrLoadAsync<T>(String)
Retrieves or loads a localized asset for the specified type using a key.
Declaration
public async Task<T> GetOrLoadAsync<T>(String _Key)
where T : class
Parameters
Type | Name | Description |
---|---|---|
String | _Key | The key associated with the localized asset to retrieve. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | The localized asset based on the key. |
Type Parameters
Name | Description |
---|---|
T | The type of localized asset. |
GetSupportedKeys(ELanguage, Type)
Retrieves a list of supported keys for the specified language and type.
Declaration
public List<String> GetSupportedKeys(ELanguage _Language, Type _AssetType)
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The target language for loading localized data. |
Type | _AssetType | The type of localized data. |
Returns
Type | Description |
---|---|
List<String> | A list of supported keys for the specified language and type of localized data. |
GetSupportedKeys<T>(ELanguage)
Retrieves a list of supported keys for the specified language and type.
Declaration
public List<String> GetSupportedKeys<T>(ELanguage _Language)
where T : class
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The target language for loading localized data. |
Returns
Type | Description |
---|---|
List<String> | A list of supported keys for the specified language and type of localized data. |
Type Parameters
Name | Description |
---|---|
T | The type of localized data. |
GetSupportedLanguages(Type)
Retrieves a list of supported languages for the specified type.
Declaration
public List<ELanguage> GetSupportedLanguages(Type _AssetType)
Parameters
Type | Name | Description |
---|---|---|
Type | _AssetType | The type of localized data. |
Returns
Type | Description |
---|---|
List<ELanguage> | A list of supported languages for the specified type of localized data. |
GetSupportedLanguages<T>()
Retrieves a list of supported languages for the specified type.
Declaration
public List<ELanguage> GetSupportedLanguages<T>()
where T : class
Returns
Type | Description |
---|---|
List<ELanguage> | A list of supported languages for the specified type of localized data. |
Type Parameters
Name | Description |
---|---|
T | The type of localized data. |
Has(ELanguage, Type, String)
Returns if a localized asset of the specified type with the passed key is loaded in the passed language yet.
Declaration
public bool Has(ELanguage _Language, Type _AssetType, String _Key)
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The language associated with the localized asset to check. |
Type | _AssetType | The type of localized asset. |
String | _Key | The key associated with the localized asset to check. |
Returns
Type | Description |
---|---|
System.Boolean | If there is a localized asset based on the key. |
Has(Type, String)
Returns if a localized asset of the specified type with the passed key is loaded in the current or fallback language yet.
Declaration
public bool Has(Type _AssetType, String _Key)
Parameters
Type | Name | Description |
---|---|---|
Type | _AssetType | The type of localized asset. |
String | _Key | The key associated with the localized asset to check. |
Returns
Type | Description |
---|---|
System.Boolean | If there is a localized asset based on the key. |
Has<T>(ELanguage, String)
Returns if a localized asset of the specified type with the passed key is loaded in the passed language yet.
Declaration
public bool Has<T>(ELanguage _Language, String _Key)
where T : class
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The language associated with the localized asset to check. |
String | _Key | The key associated with the localized asset to check. |
Returns
Type | Description |
---|---|
System.Boolean | If there is a localized asset based on the key. |
Type Parameters
Name | Description |
---|---|
T | The type of localized asset. |
Has<T>(String)
Returns if a localized asset of the specified type with the passed key is either loaded in the current or fallback language yet.
Declaration
public bool Has<T>(String _Key)
where T : class
Parameters
Type | Name | Description |
---|---|---|
String | _Key | The key associated with the localized asset to check. |
Returns
Type | Description |
---|---|
System.Boolean | If there is a localized asset based on the key. |
Type Parameters
Name | Description |
---|---|
T | The type of localized asset. |
Initialize(ISetupSettings)
Initialize the language localization using the passed setup asset. This clears already loaded localized text/audio/texture. If the language localization is already initializing, it waits until the initialization is finished. If the language localization is already initialized, this method does nothing and just returns. If the language localization is forced to initialize, it will reinitialize even if it is already initializing or initialized.
Declaration
public void Initialize(ISetupSettings _SetupAsset)
Parameters
Type | Name | Description |
---|---|---|
ISetupSettings | _SetupAsset | Force a re/initialization with the passed localization setup asset. |
InitializeAsync(ISetupSettings)
Initialize the language localization using the passed setup asset. This clears already loaded localized text/audio/texture. If the language localization is already initializing, it waits until the initialization is finished. If the language localization is already initialized, this method does nothing and just returns. If the language localization is forced to initialize, it will reinitialize even if it is already initializing or initialized.
Declaration
public async Task InitializeAsync(ISetupSettings _SetupAsset)
Parameters
Type | Name | Description |
---|---|---|
ISetupSettings | _SetupAsset | Force a re/initialization with the passed localization setup asset. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
InitializeAsync(Boolean)
Initialize the language localization by loading the project settings assigned localization setup asset (Project Settings -> GuardingPearSoftware -> EasyLocalization). This clears already loaded localized text/audio/texture. If the language localization is already initializing, it waits until the initialization is finished. If the language localization is already initialized, this method does nothing and just returns. If the language localization is forced to initialize, it will reinitialize even if it is already initializing or initialized.
Declaration
public async Task InitializeAsync(bool _Force = false)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | _Force | Force a reinitialization, although is already initialized. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Load<T>()
Loads localized assets for the current selected language and stores them in the internal storage. If the language already got loaded, it will return the already loaded asset from the internal storage.
Declaration
public Dictionary<String, T> Load<T>()
where T : class
Returns
Type | Description |
---|---|
Dictionary<String, T> | A dictionary of localized data for the specified language and type. |
Type Parameters
Name | Description |
---|---|
T | The type of localized data. |
Load<T>(ELanguage)
Loads localized assets for the passed language and stores them in the internal storage. If the language already got loaded, it will return the already loaded asset from the internal storage.
Declaration
public Dictionary<String, T> Load<T>(ELanguage _Language)
where T : class
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The target language for loading localized data. |
Returns
Type | Description |
---|---|
Dictionary<String, T> | A dictionary of localized data for the specified language and type. |
Type Parameters
Name | Description |
---|---|
T | The type of localized data. |
Load<T>(ELanguage, String)
Loads a localized asset for the given language and key and stores it in the internal storage. If the language and key already got loaded, it will return the already loaded asset from the internal storage.
Declaration
public T Load<T>(ELanguage _Language, String _Key)
where T : class
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The target language for loading localized asset. |
String | _Key | The key associated with the localized asset to load. |
Returns
Type | Description |
---|---|
T | The localized asset item based on the language and key. |
Type Parameters
Name | Description |
---|---|
T | The type of localized asset. |
Load<T>(String)
Loads a localized asset for the given language and key and stores it in the internal storage. If the language and key already got loaded, it will return the already loaded asset from the internal storage.
Declaration
public T Load<T>(String _Key)
where T : class
Parameters
Type | Name | Description |
---|---|---|
String | _Key | The key associated with the localized asset to load. |
Returns
Type | Description |
---|---|
T | The localized asset item based on the language and key. |
Type Parameters
Name | Description |
---|---|
T | The type of localized asset. |
LoadAsync(ELanguage, String, Type)
Loads a localized asset asynchronously for the given language and key and stores it in the internal storage. If the language and key already got loaded, it will return the already loaded asset from the internal storage.
Declaration
public async Task<object> LoadAsync(ELanguage _Language, String _Key, Type _AssetType)
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The target language for loading localized data. |
String | _Key | The key associated with the localized data to load. |
Type | _AssetType |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | An asynchronous operation that loads the localized data based on the language and key. |
LoadAsync(ELanguage, Type)
Loads localized assets of the specified type for the given language and stores them in the internal storage. If the language already got loaded, it will return the already loaded asset from the internal storage.
Declaration
public async Task<Dictionary<String, object>> LoadAsync(ELanguage _Language, Type _AssetType)
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The target language for loading localized data. |
Type | _AssetType | The type of localized data. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<Dictionary<String, System.Object>> | A dictionary of localized data for the specified language and type. |
LoadAsync(String, ELanguage, Type)
Asynchronously loads localized assets from specific locations for a given language and asset type and adds them to the internal storage.
Declaration
public async Task<Dictionary<String, object>> LoadAsync(String _LocationName, ELanguage _Language, Type _AssetType)
Parameters
Type | Name | Description |
---|---|---|
String | _LocationName | The name of the location from which to load the assets. |
ELanguage | _Language | The target language for loading the localized assets. |
Type | _AssetType | The type of asset to load. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<Dictionary<String, System.Object>> | A dictionary of key-value pairs representing the loaded localized assets. |
LoadAsync<T>()
Loads localized assets asynchronously for the current selected language and stores them in the internal storage. If the language already got loaded, it will return the already loaded asset from the internal storage.
Declaration
public async Task<Dictionary<String, T>> LoadAsync<T>()
where T : class
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<Dictionary<String, T>> | An asynchronous operation that loads a dictionary of localized data. |
Type Parameters
Name | Description |
---|---|
T | The type of localized data. |
LoadAsync<T>(ELanguage)
Loads localized assets asynchronously for the given language and stores them in the internal storage. If the language already got loaded, it will return the already loaded asset from the internal storage.
Declaration
public async Task<Dictionary<String, T>> LoadAsync<T>(ELanguage _Language)
where T : class
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The target language for loading localized data. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<Dictionary<String, T>> | An asynchronous operation that loads a dictionary of localized data. |
Type Parameters
Name | Description |
---|---|
T | The type of localized data. |
LoadAsync<T>(ELanguage, String)
Loads a localized asset asynchronously for the given language and key and stores it in the internal storage. If the language and key already got loaded, it will return the already loaded asset from the internal storage.
Declaration
public async Task<T> LoadAsync<T>(ELanguage _Language, String _Key)
where T : class
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The target language for loading localized data. |
String | _Key | The key associated with the localized data to load. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | An asynchronous operation that loads the localized data based on the language and key. |
Type Parameters
Name | Description |
---|---|
T | The type of localized data. |
LoadAsync<T>(String)
Loads a localized asset asynchronously for the current selected language and passed key and stores it in the internal storage. If the language and key already got loaded, it will return the already loaded asset from the internal storage.
Declaration
public async Task<T> LoadAsync<T>(String _Key)
where T : class
Parameters
Type | Name | Description |
---|---|---|
String | _Key | The key associated with the localized data to load. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | An asynchronous operation that loads the localized data based on the language and key. |
Type Parameters
Name | Description |
---|---|
T | The type of localized data. |
LoadAsync<T>(String, ELanguage)
Asynchronously loads localized assets from specific locations for a given language and asset type and adds them to the internal storage.
Declaration
public async Task<Dictionary<String, T>> LoadAsync<T>(String _LocationName, ELanguage _Language)
where T : class
Parameters
Type | Name | Description |
---|---|---|
String | _LocationName | The name of the location from which to load the assets. |
ELanguage | _Language | The target language for loading the localized assets. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<Dictionary<String, T>> | A dictionary of key-value pairs representing the loaded localized assets. |
Type Parameters
Name | Description |
---|---|
T | The type of asset to load. |
RegisterLocation(ILocation)
Registers a location for loading localized data of the specified type.
Declaration
public void RegisterLocation(ILocation _Location)
Parameters
Type | Name | Description |
---|---|---|
ILocation | _Location | The location to register. |
RegisterLocationAsync(ILocation)
Registers a location asynchronously for loading localized data of the specified type.
Declaration
public async Task RegisterLocationAsync(ILocation _Location)
Parameters
Type | Name | Description |
---|---|---|
ILocation | _Location | The location to register. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | An asynchronous operation for registering the location. |
SwitchLanguage(ELanguage, Boolean, Boolean)
Switches the current language to the specified target language. Optionally loads the localized origin language assets in the target language and unloads the origin language.
Declaration
public void SwitchLanguage(ELanguage _TargetLanguage, bool _LoadOriginLoadedKey, bool _UnloadOriginLanguage)
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _TargetLanguage | The target language to switch to. |
System.Boolean | _LoadOriginLoadedKey | A boolean indicating whether to load missing keys for the target language. |
System.Boolean | _UnloadOriginLanguage | A boolean indicating whether to unload the origin language. |
SwitchLanguageAsync(ELanguage, Boolean, Boolean)
Asynchronously switches the current language to the specified target language. Optionally loads the localized origin language assets in the target language and unloads the origin language.
Declaration
public async Task SwitchLanguageAsync(ELanguage _TargetLanguage, bool _LoadOriginLoadedKey, bool _UnloadOriginLanguage)
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _TargetLanguage | The target language to switch to. |
System.Boolean | _LoadOriginLoadedKey | A boolean indicating whether to load missing keys for the target language. |
System.Boolean | _UnloadOriginLanguage | A boolean indicating whether to unload the origin language. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | An asynchronous task representing the language switching operation. |
Unload(ELanguage)
Unloads all localized assets for the given language.
Declaration
public void Unload(ELanguage _Language)
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The target language for unloading localized assets. |
Unload<T>(ELanguage)
Unloads all localized assets of the specified type for the given language.
Declaration
public void Unload<T>(ELanguage _Language)
where T : class
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The target language for unloading localized assets. |
Type Parameters
Name | Description |
---|---|
T | The type of localized assets. |
Unload<T>(ELanguage, String)
Unloads localized assets of the specified type for the given language and key.
Declaration
public void Unload<T>(ELanguage _Language, String _Key)
where T : class
Parameters
Type | Name | Description |
---|---|---|
ELanguage | _Language | The target language for unloading localized data. |
String | _Key | The key associated with the localized data to unload. |
Type Parameters
Name | Description |
---|---|
T | The type of localized data. |
UnloadAll()
Unloads all localized assets for all types.
Declaration
public void UnloadAll()
UnloadAll<T>()
Unloads all localized assets of the specified type.
Declaration
public void UnloadAll<T>()
where T : class
Type Parameters
Name | Description |
---|---|
T | The type of localized assets. |
UnregisterLocation(ILocation)
Unregisters a location for loading localized data of the specified type.
Declaration
public void UnregisterLocation(ILocation _Location)
Parameters
Type | Name | Description |
---|---|---|
ILocation | _Location | The location to unregister. |
Events
OnLanguageChanged
Event that gets called when the language changes.
Declaration
public event EventHandler<LanguageChangedEventArgs> OnLanguageChanged
Event Type
Type | Description |
---|---|
EventHandler<LanguageChangedEventArgs> |