I'm aware of setting up translations with plurals through the Localize component, however, I need the translations to happen through scripting. I know how to use baked terms but I'm unsure how to do it with plurals. For example, I need to be able to translate the phrase "FIGHT IN 5 CAREER OR ONLINE MATCHES" where '5' is the variable.
int amount = 5;
example.text = "FIGHT IN " + amount + " CAREER OR ONLINE MATCHES";
How would I go about localizing this string of text into other languages where the amount can be any number? I've looked through the documentation but still not understanding it fully.
That will get the translation of the term TERM_FIGHTS into the current language, will get the value of MATCHES_LEFT and findout what plural form should be used, and then replace MATCHES_LEFT with its value.
That code will use the ParameterManager if you have any of those components in your scene.
If you want to pass the values directly, you can do it as well:
var dict = new Dictionary<string, int>();
dict["MATCHES_LEFT"] = 5;
string translation = LocalizationManager.GetTranslation( "TERM_FIGHTS" )
LocalizationManager.ApplyParameters(ref translation, dict);
Thanks for the help, Frank. I got it working although I couldn't find a method named ApplyParameters, instead it was ApplyLocalizationParams. I also couldn't get the method to work with a dictionary value, so I just passed in the translation and used a GlobalParameters script to change the variables.
I did run into a major issue, however, when building the game using IL2CPP. The game crashes right after the startup screen and looking through the logs it gives me a fatal error with this line:
I was pretty sure I updated it to the latest version a few days ago, but I just checked and I was still on an older version. It's now updated and I'm exporting a new build. I'll let you know if that fixes the issue, thanks!
The administrator has disabled public write access.
How to handle plurals in script
2 months 2 weeks ago #3076