Add in terms from other source

More
7 years 6 months ago #2278 by alanmotionlab
Hi,

I have been using i2-localise for some time now and its great. I've been writing my own tool to help out with my game and I'd like (if possible) to be able to add terms to the dictionary from my editor window.

I've had a look at how terms are added in the i2 localise editor window, but it doesn't look like I can access it. If its not possible, its fine, I was just trying to make the process off adding these items into my game and be localised a little easier.

Thanks

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

More
7 years 6 months ago #2281 by Frank
Hi,

To add terms dynamically you should use the AddTerm function in the LanguageSource, then fill your translations and call UpdateDictionary and save project.
// This is the default LanguageSource (but you can select any other you want)
LanguageSource I2languages = I2.Loc.LocalizationManager.Sources [0];

// Create the term (if it doesn't already exist) and returns the struct that has all its translations
TermData data = I2Languages.AddTerm( "Term Hello", eTermType.Text, false );

// Fill the translations
data.Languages[ I2Languages.GetLanguageIndex("English") ] = "English Translation";
data.Languages[ I2Languages.GetLanguageIndex("Spanish") ] = "Traduccion al espannol";

// Update the Dictionary (only needed In-Game)
I2Languages.UpdateDictionary(true);

// Mark the source as dirty so that unity save it when you close the project
EditorUtility.SetDirty(I2Languages);

// You can also do this to force saving it (although you should call this last line only after you added all the terms you need)
AssetDatabase.SaveAssets();

In this threads there is a bit more of detail:
www.inter-illusion.com/forum/i2-localiza...-term-via-script#857
www.inter-illusion.com/forum/i2-localiza...base-in-runtime#2200

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

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

More
3 years 9 months ago #4215 by Graham
This example no longer seems functional. If you could update it that'd be great!

For the most part I was able to get it working myself, but the EditorUtility.SetDirty(); is giving the error "Argument 1: cannot convert from 'I2.Loc.LanguageSourceData' to 'UnityEngine.Object'"

Also, how can I assign a category to the new term in code?

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

More
3 years 9 months ago #4220 by Frank
Hi,
Here is the updated code:
			// This is the default LanguageSource (but you can select any other you want)
            LanguageSourceData I2Languages = I2.Loc.LocalizationManager.Sources[0];

			// Create the term (if it doesn't already exist) and returns the struct that has all its translations
            TermData data = I2Languages.AddTerm( "Term Hello", eTermType.Text, false );

			// Fill the translations
            data.Languages[ I2Languages.GetLanguageIndex("English") ] = "English Translation";
            data.Languages[ I2Languages.GetLanguageIndex("Spanish") ] = "Traduccion al espannol";

			// Update the Dictionary (only needed In-Game)
            I2Languages.UpdateDictionary(true);

			// Mark the source as dirty so that unity save it when you close the project
            I2Languages.Editor_SetDirty();

			// You can also do this to force saving it (although you should call this last line only after you added all the terms you need)
            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

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

Time to create page: 0.194 seconds
Template by JoomlaShine