Language Selector Popup

More
9 years 7 months ago #206 by Livealot
I modified the Popup selector provided in the example so that it would populate the popup list from languages in the editor and so that it would respect the current language rather than defaulting back to English. Upside is the popup list stays in synch with changes you make to the Language Source Editor. Downside is that it shows the user the full name of the languages (e.g., English (United States)). Hope this helps…

using UnityEngine;
using System.Collections;
using I2.Loc;

public class i2LangPopup : MonoBehaviour {

#if NGUI
void Start ()
{
UIPopupList mList = GetComponent<UIPopupList>();
mList.items.Clear();

//better to populate list from languages set up in Language Source Editor
foreach (string nextLang in LocalizationManager.GetAllLanguages()) {
mList.items.Add(nextLang);
}

EventDelegate.Add(mList.onChange, OnValueChange);

//this should be current language, not something static
mList.value = LocalizationManager.CurrentLanguage;
}

public void OnValueChange ()
{
LocalizationManager.CurrentLanguage = UIPopupList.current.value;
}
#endif
}

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

Time to create page: 0.529 seconds
Template by JoomlaShine