API calls without first using Localize component

More
9 years 6 months ago #333 by Jos
Hello!

I'm using my own components, which make use of the I2.Loc.LocalizationManager.GetTermTranslation() method.

If i don't have an instance of the Localization component on a TextMesh someplace in my scene, any calls to 'GetTermTranslated()' fail, returning empty strings. However, if i DO have an Localization instance in my scene, it seems to work fine.

Is there some init-ing which the Localization component does, which the call to GetTermTranslation() doesn't?

Thanks!

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

More
9 years 6 months ago #334 by Frank
Hi,
That issue is fixed on 2.3.1 which I should be releasing in the next days.
A quick tweak to have it working while the version new version gets released is to add the InitializeIfNeeded function and add a call it on the GetTermTranslation

Like in:
		static void InitializeIfNeeded()
		{
			if (string.IsNullOrEmpty(mCurrentLanguage))
			{
				RegisterSceneSources();
				RegisterSourceInResources();
				SelectStartupLanguage();
			}
		}

		public static string GetTermTranslation (string Term)
		{
			InitializeIfNeeded();

			for (int i=0, imax=Sources.Count; i<imax; ++i)
			{
				string val = Sources[i].GetTermTranslation (Term);
				if (!string.IsNullOrEmpty(val))
					return val;
			}
			return string.Empty;
		}

That way you can retrieve the localization without using the Localize component in your scenes.
Other way to do it, its by selecting the language before calling GetTermTranslation. That will trigger an initialization as well.

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: Jos

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

More
7 years 2 months ago #2190 by alice_funo
This issue crept up on me because I'm calling LocalizationUtils::GetLocalizedString(string term, LanguageCode regionCode), which does GetTermData, which doesn't have the "InitializeIfNeeded" function.

Adding it will make it work. Just pointing it out so maybe there will be a more official fix :)

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

Time to create page: 0.160 seconds
Template by JoomlaShine