Welcome, Guest
Username: Password: Remember me

TOPIC: Is it possible to add terms trough script

Is it possible to add terms trough script 4 months 2 weeks ago #2364

  • smaika
  • smaika's Avatar
  • Offline
  • New Member
  • Posts: 4
  • Karma: 0
Well, I have a list of string (about 180 long) and I want to create a term for each of them, so is it possible to loop through this list and create a term for each of them, and then I can simply click translate all and be done instead of having to click add ---> write the term name 180 times.
of course, I will use a custom inspector to run the function that will loop the list and add the terms, I know how to do all that I only need to what is the function for adding terms.

I hope it's clear.

Thanks,
The administrator has disabled public write access.

Is it possible to add terms trough script 4 months 2 weeks ago #2365

  • Frank
  • Frank's Avatar
  • Offline
  • Administrator
  • Posts: 915
  • Thank you received: 196
  • Karma: 58
Hi,
You can use the LanguageSource.AddTerm function

Here is an example of creating 100 terms:
var source = LocalizationManager.Sources[0];

for (int i=0; i<100; ++i)
{
     var termData = source.AddTerm( "TermName"+i, eTermType.Text, false );
     termData.Languages[0] = "Translation for language "+i;
}

source.UpdateDictionary();
EditorUtility.SetDirty(source);
AssetDatabase.SaveAssets();

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.
The following user(s) said Thank You: smaika

Is it possible to add terms trough script 4 months 2 weeks ago #2367

  • Frank
  • Frank's Avatar
  • Offline
  • Administrator
  • Posts: 915
  • Thank you received: 196
  • Karma: 58
Also,

termData.Languages[] is the array with all the translations.
If you English language is the first one in the LanguageSource, you are free to use Languages[0] = xxx as in the example above.

If you want to make the tool more robust and support other languages,etc, you can use:
var termData = source.AddTerm( "TermName", eTermType.Text, false );

var englishIdx = source.GetLanguageIndex("English");
termData.Languages[englishIdx] = "Whatever";
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.
The following user(s) said Thank You: smaika
Time to create page: 0.154 seconds
Colors