- Home /
Question by
kaiz12 · Oct 19, 2019 at 10:42 AM ·
androidwebrequeststreamingassetslocalization
Getting Localization data in Android with streamingAssets and UnityWebRequest
Hi I used Unity localization tutorial to localize text in my app - In editor it works fine, but in Android it works partly (first canvas it doesn't find strings - shows missingTextString and other canvas is translated fine(buttons)). In the code I use missingTextString to debug errors too. It's more handy. Unity version is 2019.2.0f1 and I'm testing it in Android is 8.1
So the code:
IEnumerator LoadLocalizedTextOnAndroid(string fileName)
{
localizedText = new Dictionary<string, string>();
string filePath;
filePath = Path.Combine(Application.streamingAssetsPath + "/", fileName);
missingTextString = "Android filePath: "+filePath;
string dataAsJson;
if (filePath.Contains("://") || filePath.Contains(":///"))
{
UnityWebRequest uwr = UnityWebRequest.Get(filePath);
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
{
Debug.Log(uwr.error);
dataAsJson = "error";
missingTextString += uwr.error;
}
else
{
dataAsJson = uwr.downloadHandler.text;
missingTextString = missingTextString+" - "+ uwr.downloadHandler.text+" Juhuu";
}
}
else
{
dataAsJson = File.ReadAllText(filePath);
Debug.Log("DataAsJson = "+dataAsJson);
missingTextString += dataAsJson;
}
LocalizationData loadedData = JsonUtility.FromJson<LocalizationData>(dataAsJson);
for (int i = 0; i < loadedData.items.Length; i++)
{
localizedText.Add(loadedData.items[i].key, loadedData.items[i].value);
Debug.Log("KEYS:" + loadedData.items[i].key);
}
isReady = true;
}
Comment