Can't access global source from UnityScript

  • pedrevans
  • Topic Author
  • Visitor
  • Visitor
8 years 7 months ago - 8 years 7 months ago #989 by pedrevans
I have an application written in UnityScript ("JavaScript") with new UI components.

Documentation says that it's possible to access the global source without instantiating the prefab in every scene.

For test purposes I want to change the language from the Default.

The documentation says to use something like the following code
		if (LocalizationManager.HasLanguage("German")) {
			LocalizationManager.CurrentLanguage = "German";
		}

When I do this I get an Unknown Identifier "LocalizationManager" error at compile time (unsurprising).

I'd be grateful for a tip on how to make this work :)
Last edit: 8 years 7 months ago by pedrevans. Reason: Incorrect code example

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

More
8 years 7 months ago #990 by Frank
Hi,
There is a problem with I2 and JavaScript because of the order in which unity compiles.

I2 supports several plugins (NGUI, TextMeshPro, etc). Most of they are not in the Plugins folder (which is compiled first). So, I had to place the I2 outside of the plugins folder to be able of accessing those plugins.

Problem is that from JavaScript you can't access C# things that are outside the Plugins.

If you are using the new Unity UI (not NGUI, TextMeshpro or other targets), then you could move I2 into the plugins folder.
That way you can access its classes from within your JavaScripts.

inter-illusion.com/forum/i2-localization...ipts?limitstart=0#77

Also, in your code you need to add:
using I2.Loc;

or add I2.Loc before the LocalizationManager:
if (I2.Loc.LocalizationManager.HasLanguage("German")) {
			I2.Loc.LocalizationManager.CurrentLanguage = "German";
		}

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.

  • pedrevans
  • Topic Author
  • Visitor
  • Visitor
8 years 7 months ago #994 by pedrevans
Replied by pedrevans on topic Can't access global source from UnityScript
Thanks for the prompt reply!

I did as you suggested and moved I2 to the Plugins directory. I had to remove my own copy of SimpleJSON as that clashed with I2's. Also UnityScript and default arguments don't get on with ach other so I had to add two parameters.

Now it looks this.
if (LocalizationManager.HasLanguage("German", true, true)) {
			LocalizationManager.CurrentLanguage = "German";
}

Now the LocalizationManager is found, but unfortunately the code has no effect.

I had in the meantime implemented buttons to change languages and that works fine, but this code snippet seems to be overridden by something else.

I have the feeling that I am doing something wrong but at the moment I can't figure out what. Any ideas?

Thanks again

Pete

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

  • pedrevans
  • Topic Author
  • Visitor
  • Visitor
8 years 7 months ago #996 by pedrevans
Replied by pedrevans on topic Can't access global source from UnityScript
Investigating further, I found that the language change is taking place but is only effective after the next scene change. I tried moving the language changing code snippet to Awake() but that didn't make any difference.

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

More
8 years 7 months ago #997 by Frank
Hi,
To make it work you should move the code into the OnEnable or Start function.
When the language is changed, it iterates thru all of the Localize components and localize them. But some of them could be missed while in the Awake pass.

Also, you could call LocalizationManager.LocalizeAll() to be sure. If you are actually changing the language, it will automatically call that function, but if the previous language was the same you are setting, then it could skip that call.

Can I ask, what are trying to achieve by setting the language initially?
The plugin does a few things for you:
- The first time your game starts, it will use the Device Language. That setting is saved on the PlayerPrefs for the next time the game starts.
- If the language is not found, then it uses the first language in the Localization Source.

So, if you going to set the language on startup to German, just make that language be the first in your Language Source. That way it will be picked up on startup.
Unless the device settings is set to Chinese or other supported language in which case that language will be prioritized as it could make more sense.

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.

  • pedrevans
  • Topic Author
  • Visitor
  • Visitor
8 years 7 months ago #998 by pedrevans
Replied by pedrevans on topic Can't access global source from UnityScript
I had originally put this in Start() where it didn't to work.
LocalizeAll's protection level is "internal" so I can't use it.

However, you are perfectly right, the other mechanisms that you mentioned and the fact that the language is saved in the plist obviate the need for this code, at least in all my current development and execution scenarios. I didn't originally realise that these mechanisms were in place until I had spent some time trying it out, I was following the tutorial which suggested using that code.

Thanks for your help

Pete

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

Time to create page: 0.171 seconds
Template by JoomlaShine