Welcome, Guest
Username: Password: Remember me

TOPIC: Best way to update Term via script

Best way to update Term via script 3 years 4 months ago #856

  • Deadcow
  • Deadcow's Avatar
  • Offline
  • New Member
  • Posts: 7
  • Karma: 0
I have some class that contains TermData variable, which refrs to valid term in LanguageSource.

I'm updatng this term values, like Languages translations, like this

message.Term.Languages[0] = EditorGUILayout.TextArea(message.Term.Languages[0]);
message.Term.Languages[1] = EditorGUILayout.TextArea(message.Term.Languages[1]);

and values updated perfectly.

Bun I need also update Term name by some conditions, and I noticed that

message.Term.Term = newTermName;

not working. So now I use this method to update name:

private void UpdateTerm(string term)
{
Debug.LogWarning("old: " + Term.Term + ", new: " + term);

var localizations = Term.Languages;

LocalizationManager.UpdateSources();
var source = LocalizationManager.Sources[0];
source.RemoveTerm(Term.Term);

Term = source.AddTerm(term);
Term.Languages = localizations;

LocalizationManager.UpdateSources();
}

It seems like very lame way to do what I need to do. And new terms not appear in Language Source inspector untill I hot Play or Restart Unity.

Is there a way to easilly update term name?
Thanks
The administrator has disabled public write access.

Best way to update Term via script 3 years 4 months ago #857

  • Frank
  • Frank's Avatar
  • Offline
  • Administrator
  • Posts: 1146
  • Thank you received: 246
  • Karma: 74
Hi,
Terms are stored inside a list in the languageSource because unity 4 doesn't support serializing Dictionaries. But to speed up accessing the localization Data, I2L uses a dictionary that links to the correct TermData.

That way, terms are shared between the list and the dictionary to keep the memory usage low but we get both benefits: unity can serialize our data, and its fast to access it at runtime.

However, if you change the term's name, it will be updated in the list, but the dictionary will not know about that.
You will have to call the method UpdateDictionary() in the LocalizationManager. That will synchronize the dictionary with the list's content.

Alternatively, if you are modifying lot of terms every frame, you can access the dictionary directly and remove the term by using the old name, and add it again using the new name without calling UpdateSource or other expensive method.

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
The administrator has disabled public write access.
Time to create page: 0.183 seconds
Template by JoomlaShine