using UnityEngine;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System;
[Serializable]
public class MoodleTranslationData
{
public Dictionary<string, string> translations = new Dictionary<string, string>();
}
public class MoodleTranslator : MonoBehaviour
{
public string selectedLanguage;
private MoodleTranslationData translationData;
private void Awake()
{
LoadLanguage("EN");
}
public void LoadLanguage(string language)
{
selectedLanguage = language;
string jsonFilePath = "Localization/UI_" + language;
TextAsset jsonTextAsset = Resources.Load<TextAsset>(jsonFilePath);
Debug.Log(jsonTextAsset.text); //prints the whole json
if (jsonTextAsset != null)
{
translationData = JsonConvert.DeserializeObject<MoodleTranslationData>(jsonTextAsset.text);
foreach (var entry in translationData.translations)
{
Debug.Log($"Key: {entry.Key}, Value: {entry.Value}");
}
//foreach doesnt run
}
else
{
Debug.LogError("Failed to load JSON file: " + jsonFilePath);
}
}
}