- Home /
Resources.Load doesn't load whole text file
Hi all, I'm faced with an issue while implementing a localisation for my project. The problem is somehow related to localisation json file reading on real Android device. Every time an application loads the localisations file it is not fully loaded and ends on the middle of file.
So I have a singleton JSON deserialization class with public static method:
public static string Get(string key, string lang)
{
var fileName = "l10n";
if (instance == null)
{
var fileContent = Resources.Load<TextAsset>(fileName);
if (fileContent == null)
{
Debug.LogError("NO FILE: " + fileName);
return null;
}
var fileContentString = fileContent.ToString();
Debug.LogFormat("L10N = {0}", fileContentString); // Log file content to see it in Logcat
L10n data = null;
try
{
data = JsonUtility.FromJson<L10n>(fileContentString);
}
catch (System.ArgumentException e)
{
Debug.LogError("NULL. " + fileName + ":" + fileContentString + "\n" + e);
}
instance = data;
}
return instance.GetTranslations(key, lang);
}
The translation file is located in Resources
folder, is named l10n.json
and has some simple structure like:
{
"languages": ["RU", "EN", ...],
"keys": [ "LANG", "OK", "NO", ...],
"translations": [
{"texts": ["РУС", "ENG", ...]},
{"texts": ["Да", "Yes", ...]},
{"texts": ["Отмена", "Cancel", ...]}
...
]
}
Unfortunately I couldn't fine any similar issue in the internet. So most likely it means that there should be some my mistake =\
Need help / advise.
p.s. Worth to mention that everything works fine in editor.
Try moving those files to Assets/Strea$$anonymous$$gAssets
folder and loading them manually string json = System.IO.File.ReadAllText( System.IO.Path.Combine( Application.strea$$anonymous$$gAssetsPath , "folder_name" , "file_name.json" ) );
@andrew-lukasik will try, tnx =)
Your answer
Follow this Question
Related Questions
Load A complete unity game using other program 2 Answers
Deserialize (stream) wants CreateInstance method 0 Answers
Loading subassets at runtime 1 Answer
Resources.LoadAsync seems to load more than the requested files 0 Answers
ArgumentException: Cannot deserialize JSON to new instances of type 0 Answers