Arabic languages and dynamic text

More
3 years 10 months ago #860 by vallcrist
Hello there, I have started using I2Localization for a new project I'm working on, liking it so far, but i've hit a roadblock atm.

Some places in the game require dynamic texts, things like "<Player> killed an enemy", where <Player> is the name of the player that did the action. What I do normally is create the localization string like this "{0} killed an enemy", and then use this string inside a string.Format in c#.

This works ok for english, portuguese and so on, however when i tried to add this behaviour to arabic text, all went to hell.

For example, this string "{دردشة {0" after it gets fixed by I2 Loc in game becomes something like this "}دردشة }0", seems like I have to make the string.format before the plugin fixes the text. Any idea how should I proceed in order to make this?

Thanks for your time,

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

More
3 years 10 months ago #863 by Frank
Hi,
Yes, I have a fix for that, that includes both cases: When you use Callbacks to handle the change and when you do the change directly by code.

But I don't have the code with me at the moment.
As soon as I get back I will send it to you.

Thanks,
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
The following user(s) said Thank You: vallcrist

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

More
3 years 10 months ago - 3 years 10 months ago #872 by Frank
If you are need to access the correct localization from your script without using a localize component, then you should call ScriptLocalization.Get (xx,false);
'false' at the end skips the RTL correction. Then, after replacing your text, you can call the ArabicFixer to correct for RTL:
var text = ScriptLocalization.Get("YourTerm", false); 

text = text.Replace("{0}", PlayerName);

if (LocalizationManager.IsRight2Left)               // Only fix for RTL if the current language is RTL
      text = ArabicSupport.ArabicFixer.Fix(text);


However, the plugin also supports Callbacks for modifying the translations.
The callbacks apply the RTL after the modification so it will work as well.

In the 'Unity Standard Localization' scene there is an object named 'GUI TextCallback',
It has an example that uses "{PLAYER} wins" and dynamically changes {PLAYER} by the Color of the player.

It also keeps the correct order of words, so in spanish it shows like "El {PLAYER} ha ganado" -> "El Rojo ha ganado"


Basically, you just need to add a function to one of your scripts that does the modification, and then on the Localize component, you have to select the object and method name.
Every time the object is localized, it will call your function to process it before showing it in the label.
	public class CallbackNotification : MonoBehaviour 
	{
		public void OnModifyLocalization()
		{
			if (string.IsNullOrEmpty(Localize.MainTranslation))
				return;
			
			string PlayerColor = LocalizationManager.GetTermTranslation( "Color/Red" );
			
			Localize.MainTranslation = Localize.MainTranslation.Replace("{PLAYER_COLOR}", PlayerColor);
		}
	}

See the "On Localize Call" section at the end of Localize component. Just drag the object with the script and select the method to use as a callback.




More info about that:

forum.unity3d.com/threads/i2-localizatio.../page-2#post-1880413
inter-illusion.com/forum/i2-localization...raweventcallback#128

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
Attachments:
Last edit: 3 years 10 months ago by Frank.

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

Time to create page: 0.147 seconds
Template by JoomlaShine