Checking current language from script

More
9 years 2 months ago #1042 by whipexx
Greetings,

I need to check the language from script because I need a server to send me some text that changes dynamically; this can be solved by using a simple if to check if the language is English or not.

I know it sounds dumb but I could't figure it out now find anything here, so ¿How can I check the language from script?


Cheers

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

More
9 years 2 months ago #1043 by Frank
Hi,
To know the currently selected language you can use the property:
var language = I2.Loc.LocalizationManager.CurrentLanguage;

Also, if you get some dynamic text from a server, you can translate it into the selected language by using the In-Game Translation feature. Just call any of this functions:

Blocking: Query google for the translation and waits until google returns
var text = GoogleTranslation.ForceTranslate("Hello World", "auto", "es");

Async: (Preferred Method) Translate English to Spanish and call OnTranslationReady when finished, the game continues running while waiting for google
public void TestFunc()
{
    GoogleTranslation.Translate("Hello World", "en", "es", OnTranslationReady);
}

public void OnTranslationReady( string result )
{
}

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
9 years 2 months ago - 9 years 2 months ago #1053 by whipexx
Thank you very much, I was trying to get the language on the start method and apparently it is not initialised yet. But when asking the language after the button press it works.


_______________

Not wanting to create another thread for a short question I will just ask it here:

I've read that when you click play to the game it automatically tries to select the systems language if it is one of the languages that are available; if that does not work it defaults to the first language of the list.
But testing this I've found that it does not always get the correct language.
Could you give me any more insights in how the starting language selection works?
Last edit: 9 years 2 months ago by whipexx.

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

Time to create page: 0.143 seconds
Template by JoomlaShine