public static bool LoadLanguage(string filename) { if (filename == null) { _textTable = null; return(false); } string filePath = Path.Combine(Path.Combine(Application.streamingAssetsPath, "Languages"), filename + ".po"); string textAsset; try { textAsset = File.ReadAllText(filePath); } catch (Exception) { return(false); } if (_textTable == null) { _textTable = new Hashtable(); } _textTable.Clear(); StringReader reader = new StringReader(textAsset); string key = null; string val = null; string line; while ((line = reader.ReadLine()) != null) { if (line.StartsWith("msgid \"")) { key = line.Substring(7, line.Length - 8); } else if (line.StartsWith("msgstr \"")) { val = line.Substring(8, line.Length - 9); } if (key != null && val != null) { _textTable.Add(key, val); key = null; val = null; } } reader.Close(); OnLanguageLoaded?.Invoke(_firstLaunch); _firstLaunch = false; return(true); }
public bool LoadLanguage(SystemLanguage language) { // Load to Map bool success = GetLanguageMap(language, Map); if (success) { // Saving LanguageIndex.Value = (int)language; // MSG OnLanguageLoaded.Invoke(); } return(success); }
/// <summary> /// Load language and fill the dictionary /// </summary> /// <param name="_Language"></param> public static void LoadLanguage(string _Language) { if (Fields == null) { Fields = new Dictionary <string, string>(); } Fields.Clear(); string lang = _Language; TextAsset textAsset = Resources.Load <TextAsset>(@"Languages/" + lang); string allText = ""; if (textAsset == null) { textAsset = Resources.Load <TextAsset>(@"Languages/en"); } if (textAsset == null) { Debug.LogError("File not found: Assets/Resources/Languages/" + lang + ".txt"); } allText = textAsset.text; string[] lines = allText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); string key, value; for (int i = 0; i < lines.Length; i++) { if (lines[i].IndexOf("=") >= 0 && !lines[i].StartsWith("#")) { key = lines[i].Substring(0, lines[i].IndexOf("=")); value = lines[i].Substring(lines[i].IndexOf("=") + 1, lines[i].Length - lines[i].IndexOf("=") - 1).Replace("\\n", Environment.NewLine); Fields.Add(key, value); } } OnLanguageLoaded?.Invoke(); }
private void OnSceneLoaded(Scene arg0, LoadSceneMode loadSceneMode) { OnLanguageLoaded?.Invoke(false); }