Select Language Term by Term

More
9 years 9 months ago #533 by CuiCuiStudios
Hi, this is my first post here so let me say that I love this plugin and it´s something really useful in our projects.

And now the question... :P

I have a game for learning languages and I need the text on the UI to be in one language, and the terms on Game in other different language. Is there some function I could call to change the default language in just those terms?

Thanks so much!

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

More
9 years 9 months ago - 9 years 9 months ago #534 by Frank
Replied by Frank on topic Select Language Term by Term
Hi,
There is no built-in support for two active languages at the same time, so you will have to add an script to the Game or UI elements to access the alternative language.

Fortunately, one easy way to do it is by using the Localization callback.
Every time the Localize component translates a term, before it assigns it to the label it calls a Callback function that allows you modifying that translation.
Here is some info about it: inter-illusion.com/forum/i2-localization...ny-scripting-api#468

What you can do its to create a script like:
	public class AlternativeLocalization : MonoBehaviour
	{
		public void OnEnable()
		{
			// Register callback
			Localize loc = GetComponent<I2.Loc.Localize>();
			loc.LocalizeCallBack.Target = this;
			loc.LocalizeCallBack.MethodName = "OnModifyLocalization";
		}
		
		public void OnModifyLocalization()
		{
			string Language = "English";
			string term, secondary;
			GetComponent<I2.Loc.Localize>().GetFinalTerms(out term, out secondary);
			
			var termData = LocalizationManager.GetTermData(term);
			int LanguageIndex = LocalizationManager.Sources[0].GetLanguageIndex(Language);

			if (LanguageIndex>=0)
				Localize.MainTranslation = termData.Languages[LanguageIndex];				
		}
	}

Just add that script to any label with a Localize component, and it will override the translation with the English one.

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

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

More
9 years 9 months ago #535 by CuiCuiStudios
Thanks so much!! It works like a charm.

I want to take the post for a little request for the plugin. Is about the SetTerm Function and the Localize Script.

Well if I use the UI and attach to a button a label with the Localize component. I can access to string.Term but I think, at least for me, that would be better a direct access to SetTerm function, because it actualize automatically the label. I created my own script for this, no problem, but I will really appreciate this function by default when I use the UI.

Thanks so much!!!

Gabriel.

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

More
8 years 11 months ago #1208 by chillerVille
Hi Frank!

Thanks for the awesome I2 Localization system, it works 98% of the time. :) I'm here about that 2%: In our project we have screens where some of the texts are in Japanese and some in English. Both languages have their own fonts. If I use the method described in the thread, the texts will get correct translations, but they will all use the same font - how can I also set the correct font in OnModifyLocalization()?

Thanks!

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

More
8 years 11 months ago #1209 by Frank
Replied by Frank on topic Select Language Term by Term
Hi,

On the callbacks there are several variables that can be changed, not only the MainTranslation but the SecondaryTranslation as well. That secondary translation its the one that controls which font its going to be used.

Here you can find the complete list of variables that can be modified and what they are used for:
Callback's Documentation

If you LanguageSource or Localize component has references to the Fonts (check the references section), then by setting the SecondaryTranslation to the name of the font, it will make the label use that.

You will need to set that in the Localization callback if you are supporting two languages enabled at the same time similar to how CuiCuiStudios its doing.
But if you just have one language enabled at the same time, then you don't even need to modify the SecondaryTranslation term on the callback, just set the translationTerm in the editor and set the fonts per language.

Here are the steps to change the font per language (there its also an example of that in the Standard Unity Component's example scene)
inter-illusion.com/assets/I2Localization...FontperLanguage.html

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.

More
8 years 11 months ago - 8 years 11 months ago #1210 by chillerVille

Frank wrote: Hi,

On the callbacks there are several variables that can be changed, not only the MainTranslation but the SecondaryTranslation as well. That secondary translation its the one that controls which font its going to be used.

Here you can find the complete list of variables that can be modified and what they are used for:
Callback's Documentation

If you LanguageSource or Localize component has references to the Fonts (check the references section), then by setting the SecondaryTranslation to the name of the font, it will make the label use that.

You will need to set that in the Localization callback if you are supporting two languages enabled at the same time similar to how CuiCuiStudios its doing.
But if you just have one language enabled at the same time, then you don't even need to modify the SecondaryTranslation term on the callback, just set the translationTerm in the editor and set the fonts per language.

Here are the steps to change the font per language (there its also an example of that in the Standard Unity Component's example scene)
inter-illusion.com/assets/I2Localization...FontperLanguage.html

Hope that helps,
Frank


Hi Frank!

I spent some time looking at the documents, but couldn't figure it out. Ok, let's say that I have this callback for the GUI texts that use the system language (and associated font):
	public void OnModifyLocalization() {

		string language = m_sceneManager.GetSystemLanguage();
		string term, secondary;
		GetComponent<I2.Loc.Localize>().GetFinalTerms(out term, out secondary);
		
		var termData = LocalizationManager.GetTermData(term);
		int languageIndex = LocalizationManager.Sources[0].GetLanguageIndex(language);

		if (languageIndex >= 0) {
			if (termData != null)
				Localize.MainTranslation = termData.Languages[languageIndex];
		}
	}

... what do I need to do to make this callback also change the text item's font to the font for the language returned by m_sceneManager.GetSystemLanguage()? :) We have a term called "CatmaniaFont" that contains the name of the font for each of the languages our app supports.

I hope this question is clearer than the one before. :)
Last edit: 8 years 11 months ago by chillerVille.

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

Time to create page: 0.174 seconds
Template by JoomlaShine