Auto - generating terms

  • RafalTyl
  • Topic Author
  • Visitor
  • Visitor
3 years 2 months ago #1589 by RafalTyl
Auto - generating terms was created by RafalTyl
Hi,
I'd like to ask you about the possibility of automatic generation of localization terms using your plugin. More specifically:

1) Is it possible to use the script parsing tool to achieve the following: I'd like to go through all the scripts and find all hard - coded strings, create unique terms for each of them, and replace with localized strings. For example, I have several occurences of, let's say:
ExampleObject.DisplayString("HardCodedString")
I'd like to replace all the occurences of "HardCodedString" with a serialized string properly defined in the ScriptLocalization.cs, without explicitly defining the string that I'm looking for. All that I've been able to find is a possibility to parse the scrips using already defined terms.

2) How should I deal with ScriptableObjects? I our project, we have a text box referencing several ScriptableObjects used as data containers for tutorial messages. The text box does the following, when a tutorial message is requested:
ShowTutorial(int tutorialIndex) {
...

textComponent.text = textScriptableObjects[tutorialIndex].text;

...
}
where textComponent is of type UnityEngine.UI.Text and textScriptableObjects is an array of custom SOs containing tutorial messages in their text field.
Is it possible go through the ScriptableObjects and auto - generate terms for them, or should I do it by hand?

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

More
3 years 2 months ago - 3 years 2 months ago #1590 by Frank
Replied by Frank on topic Auto - generating terms
Hi,
Sorry for the delay in answering, I wanted to double check the code and find a plan to cover what you are mentioning in the next releases.

) Is it possible to use the script parsing tool to achieve the following: I'd like to go through all the scripts and find all hard - coded strings, create unique terms for each of them, and replace with localized strings. For example, I have several occurences of, let's say:


The plugin currently doesn't auto-detect hardcoded string from code.

The Scripting Tool is able to detect this cases: var value = ScriptLocalization.Get("HardCodedString")
it will detect that "HardCodedString" and will create a shortcut so that you could remove the hardcoded part and use a variable instead (this avoids typos)

So, it will generate: var value = ScriptLocalization.Get( ScriptLocalization.HardCodedString )

But, it will not add "HardCodedString" as a new Term, it will just create the shortcut for you.

Said, that I have been planning in adding more features to that Scripting Tool, and now is a good time :-)

Among the features I'm adding are:
- Remember previously baked terms
- Detect hardcoded string and give you the option to replace them by shortcuts and also generate the terms.
- Allow baking both hardcoded string and ScriptLocalization.Get(xx), and replace the source with the new shortcut.

2) How should I deal with ScriptableObjects? I our project, we have a text box referencing several ScriptableObjects used as data containers for tutorial messages. The text box does the following, when a tutorial message is requested:


If you are getting your texts from an scriptableObject, I2 Localization can't directly translate them for you. However you could do the following:

Either query for the translation:
textComponent.text = ScriptLocalization.Get(textScriptableObjects[tutorialIndex].text);

Or, add a localize component to your textComponent and then use the text from the scriptable object as the Term:
textComponent.GetComponent<Localize>().SetTerm( textScriptableObjects[tutorialIndex].text );

Calling SetTerm will trigger the localization, replace the parameters and call any callback you have set.


Said that, I'm adding a new class to the plugin that will be helpful to you: LocalizedString

You just need to replace the "string" type from your ScriptableObject by "LocalizedString" and whenever you get the text from that variable, it will return the localized version.
LocalizedString tutorialText;

.....
tutorialText = "Start";       // this sets "Start" as the term used for the tutorialText
string translation = tutorialText;   // will return "Inicio" if the current Language is Spanish

That class is still in one of the development branches, but I will move it to the main branch and release a beta version with it.

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
Last edit: 3 years 2 months ago by Frank.

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

Time to create page: 0.112 seconds
Template by JoomlaShine