Smart localization asset with the Unity Samples: UI
Hello,
I hope to find a quick answer i am really new to the Ui, GUI and specially localization techniques, well i should have the Unity Samples: UI 3D menu (that you can find in the scene folder of the project) to make it change languages for the system language or the chosen language using Smart localization assets... i so far been able to do it with text i create myself but to access the "Unity Samples: UI" element and change them when ever i wanted i just failed and all this is for hours later so... please try to help me even if this could be obvious solution... thank you and this is my code that i've attached to the canvas of the 3D scene (from the Unity Samples project) :
using UnityEngine;
using System.Collections;
using SmartLocalization;
using System.Collections.Generic;
public class SmartLocTutorial : MonoBehaviour
{
string _welcome;
string _newGame;
AudioClip _playSound;
GameObject _gameObject;
Texture _texture;
private Dictionary<string,string> currentLanguageValues;
private List<SmartCultureInfo> availableLanguages;
// Use this for initialization
void Start ()
{
LanguageManager languageManager = LanguageManager.Instance;
SmartCultureInfo systemLanguage = languageManager.GetSupportedSystemLanguage ();
if (systemLanguage != null) {
languageManager.ChangeLanguage (systemLanguage);
}
if (languageManager.NumberOfSupportedLanguages > 0) {
currentLanguageValues = languageManager.RawTextDatabase;
availableLanguages = languageManager.GetSupportedLanguages ();
} else {
Debug.LogError ("No languages are created!, Open the Smart Localization plugin at Window->Smart Localization and create your language!");
}
languageManager.OnChangeLanguage += OnChangeLanguage;
// languageManager.ChangeLanguage ("en");
}
void OnDestroy ()
{
if (LanguageManager.HasInstance)
LanguageManager.Instance.OnChangeLanguage -= OnChangeLanguage;
}
void OnChangeLanguage (LanguageManager thisLanguageManager)
{
// _welcome = thisLanguageManager.GetTextValue ("Welcome.Key");
GameObject.Find ("TitleLabel").GetComponentInChildren<GUIText> ().text = thisLanguageManager.GetTextValue ("Welcome.Key");
// _newGame = thisLanguageManager.GetTextValue ("NewGame.Key");
GameObject.Find ("_newGame").GetComponentInChildren<GUIText> ().text = thisLanguageManager.GetTextValue ("NewGame.Key");
_playSound = thisLanguageManager.GetAudioClip ("PlaySound.Key");
_texture = thisLanguageManager.GetTexture ("Texture.key");
_gameObject = thisLanguageManager.GetPrefab ("GameObj.key");
}
void OnGui ()
{
// if (GUILayout.Button ("English")) {
// LanguageManager.Instance.ChangeLanguage ("en");
// }
// if (GUILayout.Button ("Français")) {
// LanguageManager.Instance.ChangeLanguage ("fr");
// }
}
// Update is called once per frame
// void Update ()
// {
//
// }
}
Answer by NiklasBorglund · Oct 26, 2015 at 08:14 PM
I just made an example of how the whole Unity3D Sample UI asset could work with Smart Localization and put it up on GitHub : https://github.com/NiklasBorglund/SampleUIExample-SmartLocalization
Hope it helps!
Oh thank you Niklas i was really in a hurry so i did just the same you did with the project in the GitHub, i was doing it wrong but it worked, so thank you for the effort, it was a question out of stress sorry. hope it will be helpful for other beginners .
Your answer
Follow this Question
Related Questions
CharacterInfo.glyphWidth always 0 2 Answers
Scaling an image sent to UI Image 0 Answers
Refresh Chat room messages 1 Answer
How do I make an external text document show only between certain lines in UI Text 1 Answer
Method Skipping Inputs 2 Answers