How to handle plurals in script
- koalitygame
- Topic Author
- Offline
- New Member
Less
More
- Posts: 10
- Thank you received: 0
6 years 6 months ago - 6 years 6 months ago #3054
by koalitygame
How to handle plurals in script was created by koalitygame
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.
Example Code:
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.
Example Code:
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.
Last edit: 6 years 6 months ago by koalitygame.
Please Log in or Create an account to join the conversation.
6 years 6 months ago #3055
by Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
Replied by Frank on topic How to handle plurals in script
Hi,
For that, you need to use the same setup to define the plurals in a term, just add the term to the I2Languages.prefab and set its plural forms
inter-illusion.com/assets/I2LocalizationManual/Plurals.html
Then, you need to change the number in the translation by a Parameter.
inter-illusion.com/assets/I2LocalizationManual/Parameters.html
For example:
Plural: "FIGHT IN {[MATCHES_LEFT]} CAREERS OR ONLINE MATCHES"
One: "FIGHT IN {[MATCHES_LEFT]} CAREER OR ONLINE MATCH"
Zero: "NO CAREERS OR MATCHES LEFT"
Then, in your script, you ask for the translation of that term with the apply parameters enable:
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:
or even:
Hope that helps,
Frank
For that, you need to use the same setup to define the plurals in a term, just add the term to the I2Languages.prefab and set its plural forms
inter-illusion.com/assets/I2LocalizationManual/Plurals.html
Then, you need to change the number in the translation by a Parameter.
inter-illusion.com/assets/I2LocalizationManual/Parameters.html
For example:
Plural: "FIGHT IN {[MATCHES_LEFT]} CAREERS OR ONLINE MATCHES"
One: "FIGHT IN {[MATCHES_LEFT]} CAREER OR ONLINE MATCH"
Zero: "NO CAREERS OR MATCHES LEFT"
Then, in your script, you ask for the translation of that term with the apply parameters enable:
string translation = LocalizationManager.GetTranslation( "TERM_FIGHTS", applyParameters:true )
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);
or even:
string translation = LocalizationManager.GetTranslation( "TERM_FIGHTS" )
LocalizationManager.ApplyParameters(ref translation, (p)=>{ return p=="MATCHES_LEFT" ? 5 : null; });
Hope that helps,
Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
To get the betas as soon as they are ready,
check this out
Please Log in or Create an account to join the conversation.
- koalitygame
- Topic Author
- Offline
- New Member
Less
More
- Posts: 10
- Thank you received: 0
6 years 6 months ago #3073
by koalitygame
Replied by koalitygame on topic How to handle plurals in script
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:
LocalizationParamsManager_t2237076064::get__AutoRegister_3() const
The game works perfectly when building through Mono. I think it may have something to do with upgrading Unity from 2017 to 2018 but I'm not really sure. Any help is appreciated!
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:
LocalizationParamsManager_t2237076064::get__AutoRegister_3() const
The game works perfectly when building through Mono. I think it may have something to do with upgrading Unity from 2017 to 2018 but I'm not really sure. Any help is appreciated!
Please Log in or Create an account to join the conversation.
6 years 6 months ago #3074
by Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
Replied by Frank on topic How to handle plurals in script
Are you in the latest version of the plugin?
The AutoRegister was removed recently.
If you are in the latest version and still getting that error, please let me know.
Hope that helps,
Frank
The AutoRegister was removed recently.
If you are in the latest version and still getting that error, please let me know.
Hope that helps,
Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
To get the betas as soon as they are ready,
check this out
Please Log in or Create an account to join the conversation.
- koalitygame
- Topic Author
- Offline
- New Member
Less
More
- Posts: 10
- Thank you received: 0
6 years 6 months ago #3075
by koalitygame
Replied by koalitygame on topic How to handle plurals in script
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!
Please Log in or Create an account to join the conversation.
- koalitygame
- Topic Author
- Offline
- New Member
Less
More
- Posts: 10
- Thank you received: 0
6 years 6 months ago #3076
by koalitygame
Replied by koalitygame on topic How to handle plurals in script
Updating fixed the issue. Thanks for the help, Frank!
Please Log in or Create an account to join the conversation.
Time to create page: 0.160 seconds