void Awake() { if (string.IsNullOrEmpty(PlayerPrefs.GetString(locPrefName))) { PlayerPrefs.SetString(locPrefName, "English"); } string csvFileName = "Localization"; localizationText = (TextAsset)Resources.Load(csvFileName); try { //Debug.Log(localizationText.text); } catch { Debug.LogError("Null reference exception on localizationText; is the csv file open and locked so it can't be used by Unity?"); } if (string.IsNullOrEmpty(localizationText.text)) // get null ref on this if there is a /n at end of csv file { string nullContentError = "Failed to find any localization data"; Debug.Log(nullContentError); return; } // if data is retrieved, split up text from CSV file localization = new Dictionary <string, LocEntry>(); //Debug.Log(fileText); string[] lines = localizationText.text.Split("\n" [0]); for (int i = 0; i < lines.Length; i++) // split method grabs an extra empty line so minus 1 to loop { //Debug.Log(lines[i]); // this is a hard-coded dependency on number of languages, so need to modify this when adding new languages to the LocEntry struct string[] keyAndTranslations = lines[i].Split(translationSeparatorChar [0]); //Debug.Log(keyAndTranslations.Length); string key = keyAndTranslations[0]; // if block below throws an exception, check the Localization.csv file to ensure there is not empty line after the translations (that seems to happen sometimes on saving/export the csv) List <string> supportedLanguageTranslations = new List <string>(); for (int t = 1; t < keyAndTranslations.Length; t++) { supportedLanguageTranslations.Add(keyAndTranslations[t]); } LocEntry locEntry = new LocEntry(supportedLanguageTranslations.ToArray()); /* * string words = ""; * for (int f = 0; f < locEntry.translations.Length; f++) * { * words += locEntry.translations[f] + ","; * } * Debug.Log(locEntry.translations.Length.ToString()); * Debug.Log(words); */ localization.Add(key, locEntry); } }
public static string GetValueByKey(string key) { LocEntry entry = new LocEntry(); if (localization == null) { Debug.Log("Localization dictionary is null; ensure Localization.cs is before LocalizationText.cs in Script Execution Order"); return("LOC_ERROR_0"); } localization.TryGetValue(key, out entry); if (string.IsNullOrEmpty(entry.english)) { return("LOC_ERROR_1"); } switch (PlayerPrefs.GetString("Language")) { case "English": return(entry.english); case "French": return(entry.french); case "Spanish": return(entry.spanish); default: return(entry.english); } }
public static LocEntry GetLocEntryForKey(string key) { LocEntry entry = new LocEntry(); localization.TryGetValue(key, out entry); return(entry); }
public static bool TrySetLanguageByIndex(int languageIndex) { string languageToSet = "English"; // default to English if index unsupported bool success; LocEntry languageEntry = GetLocEntryForKey("LANGUAGE"); if (languageIndex >= languageEntry.translations.Length) { success = false; } else { success = true; } languageToSet = languageEntry.translations[languageIndex]; PlayerPrefs.SetString(locPrefName, languageToSet); Debug.Log("Language set to " + PlayerPrefs.GetString(locPrefName)); if (OnLanguageChanged != null) { OnLanguageChanged(); //Debug.Log("Broadcast change to Localization Text objects"); } else { Debug.Log("Failed to broadcast language change; are there any active LocalizationTexts in the scene?"); } return(success); }
public static string GetTranslationByKey(string key) { LocEntry entry = new LocEntry(); if (localization == null) { Debug.Log("Localization dictionary is null; ensure Localization.cs is before LocalizationText.cs in Script Execution Order"); return("LOC_ERROR_0"); } localization.TryGetValue(key, out entry); if (entry.translations == null) { return("LOC_ERROR_1"); } //Debug.Log("for key - " + key + ", player prefs is - " + PlayerPrefs.GetString("Language")); // trimming and normalizing the player pref fixes the bug with loc not working for the last dropdown input o_O switch (PlayerPrefs.GetString(locPrefName).Trim().Normalize()) { case "English": return(entry.translations[0]); // english case "Francés": return(entry.translations[1]); // french case "Español": return(entry.translations[2]); // spanish case "Portugués": return(entry.translations[3]); // portuguese case "Deutsche": return(entry.translations[4]); // german case "中文": return(entry.translations[5]); // chinese simplified case "日本人": return(entry.translations[6]); // japanese case "한국어": return(entry.translations[7]); // korean case "Indonesia": return(entry.translations[8]); // indonesian case "हिंदी": return(entry.translations[9]); // hindi case "Pусский": return(entry.translations[10]); // russian case "عربى": return(entry.translations[11]); // arabic default: return(entry.translations[0]); } }
public static int GetIndexFromPlayerPref() { string playerPrefLanguage = PlayerPrefs.GetString(locPrefName); LocEntry languageEntry = GetLocEntryForKey("LANGUAGE"); for (int i = 0; i < languageEntry.translations.Length; i++) { if (languageEntry.translations[i] == playerPrefLanguage) { return(i); } } Debug.Log("Failed to get index from player pref"); return(-1); }
private void Populate() { string list = ""; foreach (KeyValuePair <string, StoryCondition> condition in GameManager.Inst.QuestManager.StoryConditions) { list = list + condition.Value.ID + " (" + condition.Value.IsActive + ") = " + condition.Value.GetValue().ToString() + "\n"; } ConditionsList.text = list; list = ""; foreach (string topic in GameManager.Inst.PlayerProgress.DiscoveredTopics) { list = list + topic + "\n"; } TopicList.text = list; int y = 0; GameObject [] markers = GameObject.FindGameObjectsWithTag("LocMarker"); //remove existing loc entries foreach (GameObject locEntry in LocEntries) { GameObject.Destroy(locEntry); } LocEntries.Clear(); foreach (GameObject o in markers) { LocationMarker marker = o.GetComponent <LocationMarker>(); GameObject entry = GameObject.Instantiate(Resources.Load("LocationEntry")) as GameObject; entry.transform.parent = LocEntryAnchor; entry.transform.localPosition = Vector3.zero - new Vector3(0, y, 0); entry.transform.localScale = new Vector3(1, 1, 1); LocEntries.Add(entry); LocEntry loc = entry.GetComponent <LocEntry>(); loc.LocName.text = marker.Name; loc.Location = marker.transform.position; y += 45; } }
public void NewEntry(string project, string name) { _engine.Mutate(nameof(NewEntry), obs => obs.Select(context => { var proj = context.Data.Projects.Find(p => p.ProjectName == project); if (proj == null || proj.Entries.Any(l => l.Key == name)) { return(context); } var newEntry = new LocEntry(project, name); var newData = context.Data.ReplaceEntry(null, newEntry); return(context.Update(new NewEntryChange(newEntry), newData)); })); }
protected override void SetData() { if (DataChanged) { this.EditedFile.Entries.Clear(); for (int i = 0; i < (this.dataGridView.Rows.Count - 1); i++) { string tag = this.dataGridView.Rows[i].Cells[0].Value.ToString(); string localised = this.dataGridView.Rows[i].Cells[1].Value.ToString(); bool tooltip = Convert.ToBoolean(this.dataGridView.Rows[i].Cells[2].Value); LocEntry newEntry = new LocEntry(tag, localised, tooltip); this.EditedFile.Entries.Add(newEntry); } } base.SetData(); }
// Start is called before the first frame update void Awake() { if (string.IsNullOrEmpty(PlayerPrefs.GetString(locPrefName))) { PlayerPrefs.SetString(locPrefName, "English"); } string csvFileName = "Localization"; localizationText = (TextAsset)Resources.Load(csvFileName); Debug.Log(localizationText.text); if (string.IsNullOrEmpty(localizationText.text)) { string nullContentError = "Failed to find any localization data"; Debug.Log(nullContentError); logText.text += "nullContentError"; return; } // if data is retrieved, split up text from CSV file localization = new Dictionary <string, LocEntry>(); //Debug.Log(fileText); string[] lines = localizationText.text.Split(new[] { Environment.NewLine }, StringSplitOptions.None); for (int i = 0; i < lines.Length; i++) // split method grabs an extra empty line so minus 1 to loop { //Debug.Log(lines[i]); // this is a hard-coded dependency on number of languages, so need to modify this when adding new languages to the LocEntry struct string[] keyAndTranslations = lines[i].Split("," [0]); /* * for (int f = 0; f < keyAndTranslations.Length; f++) * { * Debug.Log(keyAndTranslations[f]); * } */ //Debug.Log(keyAndTranslations.Length); string key = keyAndTranslations[0]; LocEntry locEntry = new LocEntry(keyAndTranslations[1], keyAndTranslations[2], keyAndTranslations[3]); localization.Add(key, locEntry); } logText.text += "Localization dictionary loaded from CSV"; }
public EntryRemove(LocEntry entry) { Entry = entry; }
public EntryUpdate(LocEntry entry) { Entry = entry; }