private void DrawKeys() { scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, false, true, GUIStyle.none, GUIStyle.none, GUI.skin.box, GUILayout.Height(position.height - EditorGUIUtility.singleLineHeight * 7)); LocalizationStruct removingStruct = null; foreach (LocalizationStruct ls in _dictionary.localisedStrings) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(ls.key, GUILayout.Width(200)); ls.Translation(_dictionary.Languages[tab]).translation = EditorGUILayout.TextField(ls.Translation(_dictionary.Languages[tab]).translation); GUI.color = Color.red; if (GUILayout.Button("X", GUILayout.Width(20))) { removingStruct = ls; } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); } if (removingStruct != null) { _dictionary.localisedStrings.Remove(removingStruct); } EditorGUILayout.EndScrollView(); }
public void AddString(string sName) { LocalizationStruct s = new LocalizationStruct(); s.key = sName; foreach (SystemLanguage sl in Languages) { s.translations.Add(new LocalizationPair(sl, "")); } localisedStrings.Add(s); }
public string Translate(string localizationKey, SystemLanguage lang) { if (!Languages.Contains(lang)) { Debug.LogWarning("No language " + lang + " in dictionary!"); return(localizationKey); } LocalizationStruct str = localisedStrings.FirstOrDefault(s => s.key == localizationKey); if (str == null) { Debug.LogWarning("No key " + localizationKey + " in dictionary!"); return(localizationKey); } return(str.translations.FirstOrDefault(t => t.language == lang).translation); }
public override void OnInspectorGUI() { LocalizationStruct stru = _txt.LocalizedString.Dictionary.localisedStrings.FirstOrDefault(s => s.key == _txt.LocalizedString.Key); List <string> strings = new List <string>(); foreach (LocalizationStruct st in _txt.LocalizedString.Dictionary.localisedStrings) { strings.Add(st.key); } int id = 0; if (stru != null) { id = _txt.LocalizedString.Dictionary.localisedStrings.IndexOf(stru); } _txt.LocalizedString.Key = _txt.LocalizedString.Dictionary.localisedStrings[EditorGUILayout.Popup(id, strings.ToArray())].key; _txt.LineBreak = EditorGUILayout.Toggle("Break lines", _txt.LineBreak); EditorUtility.SetDirty(target); }
public void Send(LocalizationStruct str) { Downloader.Send(str, "https://docs.google.com/forms/d/e/1FAIpQLSduKqkQkdWroZcOZUBm_mgWIVkMccMjZt6J_QqSN0KBoZokKw/formResponse"); }
private void Read(string text) { Regex CSVParser = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))"); Regex r = new Regex(@"(?m)^[^""\r\n]*(?:(?:""[^""]*"")+[^""\r\n]*)*"); MatchCollection m = r.Matches(text); List <string[]> values = new List <string[]>(); string[] lines = m.Cast <Match>().Select(ma => ma.Value).ToArray(); foreach (string line in lines) { String[] Fields = CSVParser.Split(line); int i = 0; foreach (string s in Fields) { if (s.StartsWith("\"") && s.EndsWith("\"")) { Fields[i] = s.Substring(1, s.Length - 2); Fields[i] = RemoveDoubleQuotes(Fields[i]); } i++; } values.Add(Fields); } var languages = values[0].ToList(); languages.RemoveAt(0); _dictionary.Languages = new List <SystemLanguage>(); foreach (string lang in languages) { Debug.Log(lang); SystemLanguage newLang = SystemLanguage.Unknown; try { newLang = (SystemLanguage)Enum.Parse(typeof(SystemLanguage), lang); } catch { newLang = SystemLanguage.Unknown; } Debug.Log(newLang); _dictionary.Languages.Add(newLang); } _dictionary.localisedStrings = new List <LocalizationStruct>(); for (var i = 1; i < values.Count; i++) { LocalizationStruct locStruct = new LocalizationStruct(); locStruct.key = values[i][0]; for (var j = 1; j <= languages.Count; j++) { locStruct.translations.Add(new LocalizationPair(_dictionary.Languages[j - 1], values[i][j])); } _dictionary.localisedStrings.Add(locStruct); } EditorUtility.SetDirty(_dictionary); AssetDatabase.SaveAssets(); }
public static void Send(LocalizationStruct str, string path) { Instance.StartCoroutine(Post(path, str.key, str.translations[0].translation, str.translations[1].translation)); }