Get Term Translation in Editor
9 years 6 months ago #903
by adamliu
Get Term Translation in Editor was created by adamliu
Hi, I just want to know if there's a way to get the translation in the editor, because I want to generate some xml that uses the translation. I tried to use GetTermTranslation(), seems it doesn't work. Thanks.
Please Log in or Create an account to join the conversation.
9 years 6 months ago #904
by Frank
Are you
Give I2L
5 stars!
Are you
Please lets us know how to improve it!
Replied by Frank on topic Get Term Translation in Editor
Hi,
To access the translation from a custom editor/inspector, you need to first load the LanguageSources if they are not already loaded. And then you can access the mTerms and mLanguages variables inside the source:
What do you mean by "it doesn't work"?
If you try getting the GetTermTranslation(xx) where xx is a valid term it should return the translation for the current language or the first one.
If in the editor, you may need to add a LocalizationManager.UpdateSources() before calling that function.
Hope that helps,
Frank
To access the translation from a custom editor/inspector, you need to first load the LanguageSources if they are not already loaded. And then you can access the mTerms and mLanguages variables inside the source:
LocalizationManager.UpdateSources(); // If the sources are not loaded yet, this will load them
var languageSource = LocalizationManager.Sources[0]; // This is the I2Languages.prefab. Any other source in the Globals Source array or the scene
// will also be in the array
// languageSource.Languages is an array with all the languages <name and code>
// languageSource.mTerms is an array with all the terms and its translations
foreach (TermData data in languageSource.mTerms)
{
Debug.Log( data.Term ); // Key
// Print all translatiosn for this term
foreach (var translation in data.Languages )
Debug.Log(translation);
}
I tried to use GetTermTranslation(), seems it doesn't work
What do you mean by "it doesn't work"?
If you try getting the GetTermTranslation(xx) where xx is a valid term it should return the translation for the current language or the first one.
If in the editor, you may need to add a LocalizationManager.UpdateSources() before calling that function.
Hope that helps,
Frank
Are you

Are you

To get the betas as soon as they are ready,
check this out
Please Log in or Create an account to join the conversation.
9 years 6 months ago #905
by adamliu
Replied by adamliu on topic Get Term Translation in Editor
Yeah guess it's because the UpdateSources() thing. I didn't call it before I call LocalizationManager.GetTermTranslation. So when I called LocalizationManager.Sources.Count, the result is 0. But after I saw your reply I called LocalizationManager.Sources.Count again, and it become 1... Now the problem is solved. Thanks you.
Please Log in or Create an account to join the conversation.
Time to create page: 0.141 seconds