Adding Keys & Translations via script
10 years 6 months ago #112
by Jos
Adding Keys & Translations via script was created by Jos
Hello.
I have a need to be able to add a translation key via code, if possible. I have a set of components with embedded strings (public string vars), and would like to dynamically generate keys for them. So, via an OnValidate() call, i'd call the (theoretical) "AddKey()" method with whatever name i'm going to use (probably SceneName + GameObject.name).
I'm currently looking at LocalizationEditorDB_Misc's "AddKey(string newKey)" method, and would like to make it public - would this be the route you would take?
It would also be handy to add the existing text to the default language, but i can't really seem to track down where or how that is done.
Anyway, another low-priority feature request.
Jos
I have a need to be able to add a translation key via code, if possible. I have a set of components with embedded strings (public string vars), and would like to dynamically generate keys for them. So, via an OnValidate() call, i'd call the (theoretical) "AddKey()" method with whatever name i'm going to use (probably SceneName + GameObject.name).
I'm currently looking at LocalizationEditorDB_Misc's "AddKey(string newKey)" method, and would like to make it public - would this be the route you would take?
It would also be handy to add the existing text to the default language, but i can't really seem to track down where or how that is done.
Anyway, another low-priority feature request.
Jos
Please Log in or Create an account to join the conversation.
10 years 6 months ago #113
by Jos
Replied by Jos on topic Adding Keys & Translations via script
I now see that the LocalizationEditorDB class is in an Editor folder, which explains why i haven't been able to access the (now) public AddKey() method from my non-editor classes.
I'm flummoxed as to how to get around this, without some crazy refactoring of the code (which neither i nor you would want to do, just to support this).
I will continue to futz.
I'm flummoxed as to how to get around this, without some crazy refactoring of the code (which neither i nor you would want to do, just to support this).
I will continue to futz.
Please Log in or Create an account to join the conversation.
10 years 6 months ago #114
by Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
Replied by Frank on topic Adding Keys & Translations via script
Hi, if you are using version 2.1.0, there are a few methods to help adding/removing Languages and terms from the Sources.
For adding and modifying a term
1- You need to select a source (In most cases there will be only 1)
2- Add the tem to the source and it will return the termData defining that term
3- Add the translation, type and code for the term
Source.AddTerm returns a termData of the new term if it doesn't exist in the source, or the termData of the existing term so you can further modify it.
Thanks,
Frank
For adding and modifying a term
1- You need to select a source (In most cases there will be only 1)
2- Add the tem to the source and it will return the termData defining that term
3- Add the translation, type and code for the term
LanguageSource Source = LocalizationManager.Sources[0];
TermData termData = Source.AddTerm( term );
termData.Languages[ Source.GetLanguageIndex("English") ] = "Hello";
Source.AddTerm returns a termData of the new term if it doesn't exist in the source, or the termData of the existing term so you can further modify it.
Thanks,
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.
10 years 6 months ago #115
by Jos
Replied by Jos on topic Adding Keys & Translations via script
ahh, ok, great thanks!
Jos
Jos
Please Log in or Create an account to join the conversation.
Time to create page: 0.190 seconds