123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 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<LanguageSource>();
- 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<Localize>();
- // 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<TextAsset>("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
- }
- }
|