using I2.Loc; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; public class ToggleLocalizationTest : MonoBehaviour { private LanguageSource languageSource; // Start is called before the first frame update void Awake() { //languageSource = this.gameObject.AddComponent(); LocalizationConfig.localization = true; //ReadCSVFrom_StreamingFolder(Application.streamingAssetsPath + "/Localization/OperationUILocalization.csv"); LocalizationManager.OnLocalizeEvent += LocalizationManager_OnLocalizeEvent; } private void LocalizationManager_OnLocalizeEvent() { Debug.Log("LocalizationManager_OnLocalizeEvent"); } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Q)) { if (LocalizationManager.HasLanguage("Chinese")) { LocalizationManager.CurrentLanguage = "Chinese"; } } if (Input.GetKeyDown(KeyCode.E)) { if (LocalizationManager.HasLanguage("English")) { LocalizationManager.CurrentLanguage = "English"; Debug.Log("English"); } else { Debug.Log("NoEnglish"); } } } public void UpdateTemp() { var localize = this.GetComponent(); // Change the term localize.SetTerm("REWARD_1"); if (Input.GetKeyDown(KeyCode.A)) { var source = LocalizationManager.Sources[1]; var termData = source.GetTermData("Term001"); termData.Languages[0] = "Text002"; } if (Input.GetKeyDown(KeyCode.B)) { var source = LocalizationManager.Sources[2]; var termData = source.GetTermData("Term001"); termData.Languages[0] = "Text003"; } } void ReadCSVFrom_Resources() { var asset = Resources.Load("localization.csv"); // Check for errors (file not found) if (asset == null) { Debug.LogWarning("Unable to load Localization data"); return; } UseLocalizationCSV(asset.text); } // This approach is useful for letting the user modify the csv file void ReadCSVFrom_StreamingFolder(string filePath) { try { var CSVstring = File.ReadAllText(filePath); UseLocalizationCSV(CSVstring); } catch (System.Exception e) { Debug.LogWarning("Unable to load Localization data"); } } void UseLocalizationCSV(string CSVfile) { // Source[0] is the I2Languages.asset languageSource.SourceData.Import_CSV(string.Empty, CSVfile, eSpreadsheetUpdateMode.Replace, ','); LocalizationManager.LocalizeAll(); // Force localing all enabled labels/sprites with the new data } }