Best way to update Term via script

4 years 8 months ago #856 by Deadcow
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;

var source = LocalizationManager.Sources[0];

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


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?

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

4 years 8 months ago #857 by Frank
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,

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.

Time to create page: 0.329 seconds
Template by JoomlaShine