Categorizing Terms And Scripting

More
9 years 4 months ago - 9 years 4 months ago #937 by Niklas.B
Hi!

I'm working on a project where we will be localizing both using the localize component and also through our own custom scripts which we will assign term keys in the editor.

Using 'ScriptLocalization.Get' it took me quite a while to realize that I needed to use the full path for the term, i.e. category + term.
Having categories is definitely necessary when using the localize component, but having to enter the full path in the editor using our own scripts is really inconvenient.

Is there anyway to reduce it and only use the term key, or even better, is there a good way to add the drop list of all terms in a custom script the same way
as seen when using the Localize component?

Regards
Niklas
Last edit: 9 years 4 months ago by Niklas.B.

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

More
9 years 4 months ago #939 by Frank
Hi,

There is currently no DecoratorDrawer for showing the term as a popup.

If you are using a custom inspector, you can add a popup by using:
public void OnGUI () 
		{
.... your code ...
			EditorGUI.BeginChangeCheck ();

			var Terms = LocalizationManager.GetTermsList ();
			var newIndex = EditorGUI.Popup (position, "My Term Variable", Terms.IndexOf (term), Terms.ToArray());

			if (EditorGUI.EndChangeCheck ())
				term = newIndex < 0 ? string.Empty : Terms [newIndex];
		}

However, I just made a quick PropertyDrawer to allow showing that even if you don't have a custom inspector.
Based on this, I'm going to improve that drawer in the next version to allow expanding the term and using filters like in the Localize component.

Here is the drawer. Just add this line at the bottom of the LocalizeManager.cs
}

	public class TermsPopup : PropertyAttribute {}     // this line
}


and add this class at Assets\I2\Localization\Scripts\Editor\Inspectors\TermsPopup_Drawer.cs
using UnityEngine;
using UnityEditor;
using System.Collections;

namespace I2.Loc
{
	[CustomPropertyDrawer (typeof (TermsPopup))]
	public class TermsPopup_Drawer : PropertyDrawer 
	{
		public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) 
		{
			EditorGUI.BeginChangeCheck ();

			var Terms = LocalizationManager.GetTermsList ();
			Terms.Sort(System.StringComparer.OrdinalIgnoreCase);
			Terms.Add ("<none>");
			var newIndex = EditorGUI.Popup (position, label.text, Terms.IndexOf (property.stringValue), Terms.ToArray());

			if (EditorGUI.EndChangeCheck ())
				property.stringValue = (newIndex < 0 || newIndex == Terms.Count - 1) ? string.Empty : Terms [newIndex];
		}
	}
}


Then, in your scripts, if you add the TermsPopup attribute to an string, it will show a popup with the terms:
	public class MyTest : MonoBehaviour 
	{
		[I2.Loc.TermsPopup]
		public string test;
	}

will look like:




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
Attachments:
The following user(s) said Thank You: Niklas.B

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

More
9 years 4 months ago #942 by Niklas.B
That's amazing!

Works exactly how we wanted it to. Thanks for the quick response!

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

Time to create page: 0.131 seconds
Template by JoomlaShine