Hey guys,
Just wanted to post a snippet in case it turns out to be helpful for anyone using an alternate localization solution with NGUI.
I'm currently using Smart Localization which can be found here: http://forum.unity3d.com/threads/173837-RELEASED-Smart-Localization-for-Unity3D
It's really good, it's free and has some neat features such as Microsoft Translate integration.
In order to use it with NGUI, simply type your string key into the label field and drag this script on.
Cheers!
Code (csharp):
using UnityEngine;
using System.Collections;
using System.Globalization;
[RequireComponent(typeof(UIWidget))]
[AddComponentMenu("NGUI/UI/LocalizeWidget")]
{
// No public variables, we'll get the key from the widget field
private string key;
private string mLanguage;
private LanguageManager loc;
// Localize the widget on start.
{
// Reference the language manager
loc = LanguageManager.Instance;
// Hook up a delegate to run the localize script whenever a language was changed
loc.OnChangeLanguage += new ChangeLanguageEventHandler(Localize);
// Initial localize run
Localize();
}
// Incase the script didn't get the message from being inactive
{
if(mLanguage != loc.language)
Localize();
}
// Force-localize the widget.
private void Localize(LanguageManager thisLanguage=null)
{
UIWidget w = GetComponent<UIWidget>();
UILabel lbl = w as UILabel;
UISprite sp = w as UISprite;
// If no localization key has been specified, use the label's text as the key
if (lbl != null)
string val = loc.GetTextValue(key);
if(string.IsNullOrEmpty(val))
val = "Missing String";
if (lbl != null)
{
// If this is a label used by input, we should localize its default value instead
UIInput input = NGUITools.FindInParents<UIInput>(lbl.gameObject);
if (input != null input.label == lbl)
input.defaultText = val;
else
}
else if (sp != null)
{
sp.spriteName = val;
sp.MakePixelPerfect();
}
// Set this widget's current language
mLanguage = loc.language;
}
}
출처 : http://forum.unity3d.com/threads/smart-localization-with-ngui.189253/
참조 : http://forum.unity3d.com/threads/released-smart-localization-for-unity3d.173837/