void GUIItemNode(ItemData item, string key, LocalizationValue value, int itemIndex) { ILocalizationValueDrawer drawer; drawer = EditorLocalization.GetValueDrawer(value.TypeName); if (drawer == null) { drawer = EditorLocalization.GetValueDrawer("string"); } bool ineritValue = !item.values.ContainsKey(key); if (!ineritValue) { value.Value = drawer.OnGUI(value.Value); item.values[key] = value; if (baseData.lang != item.lang) { if (GUILayout.Button("T", TranslateButtonStyle, GUILayout.ExpandWidth(false))) { Translate(baseData, new List <TranslateItem>() { new TranslateItem() { itemData = item, key = key } }); //EditorUtility.DisplayProgressBar("Translate", "", 0f); //GoogleTranslator.Process(itemDatas[0].lang, item.lang, (string)baseData.values[key].Value, (b, result) => //{ // EditorUtility.ClearProgressBar(); // if (b) // { // value.Value = result; // item.values[key] = value; // DirtyData(item); // } //}); } } } else { var baseValue = baseData.values[key]; using (new GUIx.Scopes.ColorScope(GUI.color * new Color(1, 1, 1, 0.5f))) using (var checker = new EditorGUI.ChangeCheckScope()) { object newValue = drawer.OnGUI(baseValue.Value); if (checker.changed) { var clone = baseValue.Clone(); clone.Value = newValue; item.values[key] = clone; GUI.changed = true; } } } }
public void GenerateResourceFile(string fileName, LocalizationValue localizationValue = LocalizationValue.Default) { var localizations = new MobileLocalization(); using (var resXResourceWriter = new ResXResourceWriter(fileName)) { foreach (var propertyInfo in typeof(MobileLocalization).GetProperties()) { if (propertyInfo.GetCustomAttributes(false).Any(a => a is DefaultValueAttribute)) { object value = string.Empty; if (localizationValue == LocalizationValue.Default) { value = ((DefaultValueAttribute)propertyInfo.GetCustomAttributes(false).Single(a => a is DefaultValueAttribute)).Value; } else if (localizationValue == LocalizationValue.Key) { value = propertyInfo.Name; } resXResourceWriter.AddResource(propertyInfo.Name, value); } } foreach (var loc in localizations.LookupLocalizations) { resXResourceWriter.AddResource(loc.Key, loc.Value); } } }
protected override IDictionary <string, LocalizationValue> LoadValues(string lang) { IDictionary <string, LocalizationValue> result = null; switch (lang) { case "zh": result = LocalizationValue.StringDictionary(new Dictionary <string, string>() { { "Hello World", "你好世界" }, { "Language", "语言" } }); break; case "en": result = LocalizationValue.StringDictionary(new Dictionary <string, string>() { { "Hello World", "Hello World" }, { "Language", "Language" } }); break; case "zh-TW": result = LocalizationValue.StringDictionary(new Dictionary <string, string>() { { "Language", "語言" } }); break; } return(result); }
public string GetTextForKey(string key) { LocalizationList item = localizationSO.listData.Find(a => a.key == key); if (item == null) { return(null); } LocalizationValue itemValue = item.value.Find(a => a.language == currentLanguage); if (itemValue == null) { return(null); } return(itemValue.text); }
protected override IEnumerable <LocalizationString> ReadComponents(LocalizationStringsExportModel model, string componentFolderPath) { foreach (var localizationStringModel in model.LocalizationStrings) { var entity = PackageHandlerUtils.CreateEntity <LocalizationString>(localizationStringModel); if (localizationStringModel.DetailDataSets?.DetailDataSet1 != null) { var stringModels = localizationStringModel.DetailDataSets.DetailDataSet1.Rows; foreach (var stringModel in stringModels) { var localizationValue = new LocalizationValue(); var groupReq = stringModel.Requisites .FirstOrDefault(r => r.Code == GroupReqName); if (groupReq != null) { entity.Group = groupReq.Value; } var languageReq = stringModel.Requisites .FirstOrDefault(r => r.Code == LanguageReqName); if (languageReq != null) { localizationValue.Language = languageReq.Value; } var valueReq = stringModel.Requisites .FirstOrDefault(r => r.Code == ValueReqName); if (valueReq != null) { localizationValue.Value = valueReq.Value; } entity.Values.Add(localizationValue); } } yield return(entity); } }
public IEnumerable <LocalizationString> Read(ComponentsModel packageModel) { foreach (var model in packageModel.LocalizationStrings) { var entity = PackageHandlerUtils.CreateEntity <LocalizationString>(model); if (model.DetailDataSets?.DetailDataSet1 != null) { var stringModels = model.DetailDataSets.DetailDataSet1.Rows; foreach (var stringModel in stringModels) { var localizationValue = new LocalizationValue(); var groupReq = stringModel.Requisites .FirstOrDefault(r => r.Code == GroupReqName); if (groupReq != null) { entity.Group = groupReq.DecodedText; } var languageReq = stringModel.Requisites .FirstOrDefault(r => r.Code == LanguageReqName); if (languageReq != null) { localizationValue.Language = languageReq.DecodedText; } var valueReq = stringModel.Requisites .FirstOrDefault(r => r.Code == ValueReqName); if (valueReq != null) { localizationValue.Value = valueReq.DecodedText; } entity.Values.Add(localizationValue); } } yield return(entity); } }
public IEnumerable <LocalizationString> Read(SqlConnection connection, Version platformVersion) { var components = new Dictionary <string, LocalizationString>(); var query = this.GetLocalizationStringQuery(platformVersion); if (string.IsNullOrEmpty(query)) { return(components.Values.ToList()); } var command = new SqlCommand(query, connection); using (var reader = command.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { var localizationString = new LocalizationString { Name = reader["Name"] as string, Title = reader["Title"] as string, Group = reader["Group"] as string }; components.Add(localizationString.Name, localizationString); } } } query = this.GetLocalizationValueQuery(platformVersion); if (!string.IsNullOrEmpty(query)) { command = new SqlCommand(query, connection); using (var reader = command.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { var localizationStringName = reader["LocalizationStringName"] as string; if (!components.ContainsKey(localizationStringName)) { continue; } var localizationString = components[localizationStringName]; var localizationValue = new LocalizationValue { Language = reader["Language"] as string, Value = reader["Value"] as string }; localizationString.Values.Add(localizationValue); } } } } return(components.Values.ToList()); }
void GUINewItem() { if (string.IsNullOrEmpty(baseData.path)) { return; } string error = null; using (new GUILayout.HorizontalScope()) { searchKey = EditorGUILayoutx.SearchTextField(searchKey, GUIContent.none, GUILayout.Width(EditorGUIUtility.labelWidth)); int typeNameIndex = 0; string[] typeNames = EditorLocalization.GetValueTypeNames().ToArray(); for (int i = 0; i < typeNames.Length; i++) { if (typeNames[i] == newValueTypeName) { typeNameIndex = i; break; } } float width = (Screen.width - EditorGUIUtility.labelWidth) * 0.3f; width = Mathf.Min(width, 150); typeNameIndex = EditorGUILayout.Popup(typeNameIndex, typeNames.Select(o => ("type_" + o).Localization()).ToArray(), GUILayout.Width(width)); newValueTypeName = typeNames[typeNameIndex]; string newKeyCurrent; newKey = EditorGUILayoutx.DelayedPlaceholderField(newKey ?? string.Empty, out newKeyCurrent, new GUIContent("New Key".Localization()) /*, GUILayout.Width(EditorGUIUtility.labelWidth)*/); if (!string.IsNullOrEmpty(newKeyCurrent)) { if (baseData.values.ContainsKey(newKeyCurrent)) { error = string.Format("key <{0}> base exists", newKeyCurrent); } } if (!string.IsNullOrEmpty(newKey) && error == null) { var value = new LocalizationValue(newValueTypeName, Localization.GetValueProvider(newValueTypeName).DefaultValue); if (newValueTypeName == "string") { value.Value = newKey; } baseData.values[newKey] = value; newKey = string.Empty; GUIUtility.keyboardControl = -1; DiryBaseData(); } } if (error != null) { EditorGUILayout.HelpBox(error, MessageType.Error); } }