Problem using API with plural translations

More
4 years 4 months ago #4012 by cygnusprojects
Hi there,

I found the following code on this forum to translate my plural term through API calls:
var dict = new Dictionary<string, int>();
dict["MATCHES_LEFT"] = 5;
string translation = LocalizationManager.GetTranslation( "TERM_FIGHTS" )
LocalizationManager.ApplyParameters(ref translation, dict);
and this
string translation = LocalizationManager.GetTranslation( "TERM_FIGHTS" )
LocalizationManager.ApplyParameters(ref translation, (p)=>{ return p=="MATCHES_LEFT" ? 5 : null; });
I applied this to my code like this:
string translation = LocalizationManager.GetTranslation(".STARS. needed to unlock");
        LocalizationManager.ApplyLocalizationParams(ref translation, (p) => { return p == "NR" ? 5 : 0; });
or even this:
var dict = new Dictionary<string, object>();
        dict["NR"] = Contract.StarsNeed2Unlock;
        string translation = LocalizationManager.GetTranslation(".STARS. needed to unlock");
        LocalizationManager.ApplyLocalizationParams(ref translation, parameters:dict);
but all do end in the same error message:
InvalidCastException: Specified cast is not valid.
I2.Loc.LocalizationManager.ApplyLocalizationParams (System.String& translation, I2.Loc.LocalizationManager+_GetParam getParam, System.Boolean allowLocalizedParameters) (at Assets/I2/Localization/Scripts/Manager/LocalizationManager_Parameters.cs:84)
I2.Loc.LocalizationManager.ApplyLocalizationParams (System.String& translation, System.Collections.Generic.Dictionary`2[TKey,TValue] parameters, System.Boolean allowLocalizedParameters) (at Assets/I2/Localization/Scripts/Manager/LocalizationManager_Parameters.cs:46)
ContractUI.OnLocalize () (at Assets/Scripts/UI/ContractUI.cs:67)
Looking at the code using that stacktrace this seems to be the issue:
var result = (string)getParam(param); where param has the value NR

Any tip/hints on how to get this working?
I'm on Unity 2019.2.13 and I2 localization 2.8.13 f2 according to the readme.

Please Log in or Create an account to join the conversation.

Time to create page: 0.135 seconds
Template by JoomlaShine