Is it possible to add terms trough script

More
2 years 4 months ago #2364 by smaika
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,

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

More
2 years 4 months ago #2365 by Frank
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 following user(s) said Thank You: smaika

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

More
2 years 4 months ago #2367 by Frank
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 following user(s) said Thank You: smaika

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

Time to create page: 0.147 seconds
Template by JoomlaShine