- Home /
Question by
FantaLaTone · Feb 17, 2020 at 03:12 PM ·
unity 5jsonlocalization
my localization loader only load one text's value
im trying to make own simple localization system but there's one problem . my localization system's text loader only load one text's value. here's my codes
Test.cs using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine;
public class Test : MonoBehaviour
{
public ItemList jsonKey;
public bool isReady = false;
string path;
string jsonText;
public string selectedLang;
public string key;
public Dictionary<string, string> itemDic= new Dictionary<string, string>();
public void Start()
{
selectedLang = "en-";
SetDic();
}
public void SetDic()
{
path = Application.streamingAssetsPath + "/turkish.json";
jsonText = File.ReadAllText(path);
jsonKey = JsonUtility.FromJson<ItemList>(jsonText);
for (int i = 0; i < jsonKey.itemList.Length; i++)
{
itemDic.Add(jsonKey.itemList[i].key, jsonKey.itemList[i].value);
}
isReady = true;
}
}
TestLoader.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TestLoader : MonoBehaviour
{
public Test test;
public string keyName;
public void Start()
{
GameObject tempObj = GameObject.Find("Localization Manager");
test = tempObj.GetComponent<Test>();
Load();
}
public void Load()
{
test.key = test.selectedLang + keyName;
if (test.isReady)
{
if (test.itemDic.ContainsKey(test.key))
{
this.GetComponent<Text>().text = test.itemDic[test.key];
Debug.Log(test.itemDic[test.key]);
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Help me with this json code please 1 Answer
Loaclization in WebGL? 1 Answer
Save data to a location without override 1 Answer