Help me(button)!!!

More
10 years 3 months ago #247 by truongson
Help me(button)!!! was created by truongson
Dear Frank!
I want to convert the 2 buttons with 2 languages​​. But when I do it, it did not work. It can be said that sometimes it works, sometimes it does not. You can only do workarounds, as well as how to switch 2 button for 2 languages​​.
ex:
button1 - language1
button2 - language2

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

More
10 years 3 months ago #249 by Frank
Replied by Frank on topic Help me(button)!!!
Hi,
All example scenes have buttons that switch language. Most of the example scenes do the switching in a different way in order to show all the available options.

Basically, to enable a language you have to call in the script:
I2.Loc.LocalizationManager.CurrentLanguage = "English";
If any of the language sources in the scene or in the I2Language.prefab has a Language named "English" it will enable that language.
If "English" is not found, the plugin fallbacks to any available region (e.g. "English (Canada)")

On the examples, I attached an script to the buttons and when a click is detected, they set the CurrentLanguage appropiately.


Can you please, confirm me that the example scenes work for you? That way we can rule out any issue on the installation.
Also, what UI system are you using (NGUI, uGUI, DFGUI, etc) so that I could point you to the correct example/approach.

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

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

More
10 years 3 months ago #250 by truongson
Replied by truongson on topic Help me(button)!!!
Thank you for your reply.
but you're misunderstanding my problem.
I used to use NGUl to create buttons (ex: image button "Play" == English, image button "Jouer" == France) I want to change the language button. When I select English, the Play button will be used, whereas

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

More
10 years 3 months ago #251 by Frank
Replied by Frank on topic Help me(button)!!!
Hi,
I hope now I'm understanding you correctly:

If you only need to change the text/image in a button depending on the language you should follow the following steps:
1- Create a term for that button in the I2Languages.prefab (e.g. "PLAY BUTTON")
2- Select the image or text you want to display for each language
3- Assign a "Localize" component to label or sprite that is a child of the button.

Thats it. As soon as you change the language, the plugin will change the text or image of the button to display the one you selected on step 2.

Check the following video to see the steps in action (see how the image and text is changed according to the language. You should do the same by assigning the "Localize" component to the Sprite or Label that is a child of the button.


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.

More
10 years 3 months ago #252 by truongson
Replied by truongson on topic Help me(button)!!!
Thank you. But if you use the ImageButton it will have 4 states: normal, hover, press, disabled. I want to replace all ..

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

More
10 years 3 months ago - 10 years 3 months ago #253 by Frank
Replied by Frank on topic Help me(button)!!!
Ahh, I understand now.
What you want to localize is not actually the sprite that shows the image in the button, but the UIImageButton component that holds the images for the 4 states.

Out of the box, I2 Localization doesn't support the ImageButton component. But its easy to write a custom script that uses the I2 localization callback functions to do what you need.

You could add the following script to your code and it will localize your 4 states.

LocalizeButton.cs
using UnityEngine;
using I2.Loc;

public class LocalizeButton : MonoBehaviour
{
	public UIImageButton _TargetImageButton;
	
	public string Term_Normal, Term_Hover, Term_Pressed, Term_Disabled;
	
	void Start()
	{
		// Register this class to do custom localizations
		LocalizationManager.OnLocalizeEvent += CustomLocalization;
	}
	
	void OnDestroy()
	{
		LocalizationManager.OnLocalizeEvent -= CustomLocalization;
	}
	
	
	// This function gets called whenever the language is changed
	public static void CustomLocalization()
	{
		_TargetImageButton.normalSprite 	= ScriptLocalization.Get (Term_Normal);
		_TargetImageButton.hoverSprite 		= ScriptLocalization.Get (Term_Hover);
		_TargetImageButton.pressedSprite 	= ScriptLocalization.Get (Term_Pressed);
		_TargetImageButton.disabledSprite 	= ScriptLocalization.Get (Term_Disabled);
	}
}

You wont need to add a Localize component to the button, Just add this one instead.
Then, drag the ImageButton into the TargetImageButton field in the inspector.
And create a term in the languageSource for each of the button states. (e.g. "BUTTON_PLAY_HOVER", "BUTTON_PLAY_NORMAL", etc)

Assign those terms into the terms slots in the LocalizeButton inspector and thats it.
Whenever you change the language, it will change the 4 sprites that are shown.

Please, let me know if that helps, or if you need further info on how to set it up.

Nonetheless, I like the idea of also localizing the ImageButton and other components like that. I will add that feature as soon as possible. Thanks for letting me know that was a needed feature!!

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
Last edit: 10 years 3 months ago by Frank.
The following user(s) said Thank You: truongson

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

Time to create page: 0.154 seconds
Template by JoomlaShine