Editor Node - Dialog

More
6 years 4 months ago #2607 by pete
Editor Node - Dialog was created by pete
Hello everyone,

I was wondering if this is possible to extract string from Nodes from that tool:
github.com/Seneral/Node_Editor_Framework...ples/Dialogue-System

It is a node editor, where you store all the data into a scriptable object.
I would like to be able to localize all the strings in the node editor.

Is it possible?

Thanks!

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

More
6 years 4 months ago #2620 by pete
Replied by pete on topic Editor Node - Dialog
Frank,

I will probably have to create something to be able to read the node directly.
I would need to know where should I start looking for and what would be the best approach to be able to read a Scriptable Object with your Localize component.

I guess, I would need to add a method inside your component that looks for scriptable object and parse them?
Is it possible to add multiple entries with your localize component? Or I need to add multiple component?

What would be the best way, approach to this?

Thanks!

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

More
6 years 4 months ago #2621 by Frank
Replied by Frank on topic Editor Node - Dialog
Hi,
I'm not very familiar with NodeCanvas and the DialogSystem. But from looking at the code in the repo you posted, I think you have several options to add localization to it.

First, you should kept all the localization terms and translations in I2Languages.prefab. That will allow you to synchronize to spreadsheet, do live synchronizations and easier auto-translate.

Using that, the text you save in the nodes, should be the Term name and not the actual line to be displayed. Given that you have anything for the textname, then the English text can be used as the term name (e.g. "this is a text").
That should make it easy to port the current texts, given that you don't have to do any change in the Nodes.

Once that setup is done (terms added to I2Languages.prefab while Nodes's text is the terms name), to make the localization work, add a Localize component to the Text components you are using in your scenes.

Then change in your code, whenever the node dialog is set into Localize.SetTerm(xx)
   //label.text = node.DialogLine;      // from this

   label.GetComponent<Localize>().SetTerm( node.DialogLine );  // into this

That will change the term, fetch the translation for the current language and modify the label.text. Given that you are also using the normal Localize component, then if the user changes the language, any dialog that its displayed will automatically update.


As a bonus, to simplify setting the Term names in the nodes, you can modify the code to show the Term's selection UI:
change
github.com/Seneral/Node_Editor_Framework.../Nodes/DialogNode.cs line 55
DialogLine = EditorGUILayout.TextArea(DialogLine, GUILayout.ExpandHeight(true));

into
GUILayout.Label("", GUILayout.ExpandWidth(true));  // only used to get the termRect, because ShowGUI doesn't use GUILayout
var termRect = GUILayoutUtility.GetLastRect();

TermsPopup_Drawer.ShowGUI(termRect, ref DialogLine, new GUIContent("Dialog"), null);
LocalizationEditor.OnGUI_Keys_Languages( DialogLine, null, true );

You will have to make a variant of the TermsPopup_Drawer.ShowGUI that uses a string instead of SerializedProperty, but that should be pretty straightforward to do.

Again, this is just a quick overview based on just looking at the code without actually trying it, but it hope it helps you get more info on how to do the localization.
Please, if you have any more doubts as you implement it, don't hesitate in letting me know.

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
6 years 4 months ago #2622 by pete
Replied by pete on topic Editor Node - Dialog
Thanks Frank,

I'll give it a try, I'm not sure yet about all the steps you gave me, but I'll try to dig a little bit before asking you for more help.

Thanks again!

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

More
6 years 4 months ago #2624 by pete
Replied by pete on topic Editor Node - Dialog
Thanks Frank,

I was able to make it work to update the strings as they go.
I was also able to validate that the language is correctly updated for the strings in the node, that is great (Tried French and English)!

But, I have an issue with your bonus section.
GUILayout.Label("", GUILayout.ExpandWidth(true));  // only used to get the termRect, because ShowGUI doesn't use GUILayout
var termRect = GUILayoutUtility.GetLastRect();

TermsPopup_Drawer.ShowGUI(termRect, ref DialogLine, new GUIContent("Dialog"), null);
LocalizationEditor.OnGUI_Keys_Languages( DialogLine, null, true );

this TermsPopup_Drawer and this LocalizationEditor.OnGUI_Keys_Languages "don't exist in the current context" (the usual error when this is not existing, declared or missing a namespace)
My question is: what do I need to do to make it work?

Thanks!

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

More
6 years 4 months ago - 6 years 4 months ago #2625 by Frank
Replied by Frank on topic Editor Node - Dialog
The problem is that the class TermsPopup_Drawer is defined as Editor only, so your code doesn't see it.
assets\i2\localization\scripts\editor\inspectors\termspopup_drawer.cs

Given that you have to make a duplicate of the ShowGUI replacing SerializedProperty with string, you should copy the ShowGUI function to the file where you need it, then replace the SerializedProperty with a ref string.

Something like this:
        public static bool ShowGUI(Rect position, ref string property, GUIContent label, LanguageSource source, string filter = "")
	{
		EditorGUI.BeginChangeCheck ();

		var Terms = (source==null ? LocalizationManager.GetTermsList() : source.GetTermsList());

		if (string.IsNullOrEmpty(filter) == false)
		{
                     Terms = Filter(Terms, filter);
		}

		Terms.Sort(System.StringComparer.OrdinalIgnoreCase);
		Terms.Add("");
		Terms.Add("<inferred from text>");
		Terms.Add("<none>");

		var index = (property == "-" || property == "" ? Terms.Count - 1 : 
                        (property == " " ? Terms.Count - 2 : 
                        Terms.IndexOf(property)));
            var newIndex = EditorGUI.Popup(position, label, index, DisplayOptions(Terms));

            if (EditorGUI.EndChangeCheck())
            {
                property = (newIndex < 0 || newIndex == Terms.Count - 1) ? string.Empty : Terms[newIndex];
                if (newIndex == Terms.Count - 1)
                    property = "-";
                else
                if (newIndex < 0 || newIndex == Terms.Count - 2)
                    property = string.Empty;
                else
                    property = Terms[newIndex];

                return true;
            }

            return false;
}

EDIT: it can get ever simpler. As you are not longer using a propertydrawer, you can remove the Rect parameter. and instead of EditorGUI.Popup, call EditorGUILayout.Popup.
Then, when calling the function, there is no need for the GUILayout.Label and GUILayoutUtility.GetLastRect


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: 6 years 4 months ago by Frank.

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

Time to create page: 0.201 seconds
Template by JoomlaShine