public async Task <JsonResult> Locale(string lang = "tr", string key = "name") { if (!LanguageModel.IsValidLanguageKey(lang)) { return(Json(new { Error = "not valid language!" }, JsonRequestBehavior.AllowGet)); } var word = await _wordService.GetByKey(key); if (word == null) { return(Json(new { Info = "word not found!" }, JsonRequestBehavior.AllowGet)); } var model = new LocaleModel { Key = word.Key, Lang = lang, Value = word.Key }; var type = word.GetType(); var translationFieldName = string.Format("Translation_{0}", lang.ToUpperInvariant()); var propInfo = type.GetProperty(translationFieldName, new Type[0]); if (propInfo != null) { model.Value = propInfo.GetValue(word, null) != null?propInfo.GetValue(word, null).ToString() : string.Empty; } return(Json(model, JsonRequestBehavior.AllowGet)); }
public static LocalisationModel CreateLocaleFromFile(string fileName) { LocalisationModel container = new LocalisationModel( Path.GetFileNameWithoutExtension(fileName)); IEnumerable <string> lines = File.ReadLines(fileName); bool firstline = true; foreach (string line in lines) { if (string.IsNullOrWhiteSpace(line)) { continue; } if (firstline) { container.LanguageName = line.Replace(":", "").Trim(); firstline = false; } else { LocaleModel content = new LocaleModel() { Key = line.Split(':')[0].Trim(), Value = Regex.Match(line.Split(':')[1], "\"([^\"]*)\"").Groups[1].Value.Trim() }; container.LocalisationMap.Add(content); } } return(container); }
public override void OnInspectorGUI() { DrawDefaultInspector(); WLocale tgt = (WLocale)target; _languages.Build(new Menu <LangModel> .BuildCallback( "Languages", tgt.languages, l => l.title, s => { _selectedLanguage = s.Model; TextAsset t = Resources.Load <TextAsset>(Path.Combine(tgt.path, $"locale_{_selectedLanguage.id}")); if (null == t) { _selectedLocale = new LocaleModel(_selectedLanguage.id); } else { _selectedLocale = JsonUtility.FromJson <LocaleModel>(t.text); } } )); if (null != _selectedLocale) { EditorGUILayout.LabelField(_selectedLocale.lang, EditorStyles.boldLabel); } }
public string translateKey(string key) { LocaleModel locale = LocalisationMap.FirstOrDefault(l => string.Equals(l.Key, key, StringComparison.CurrentCultureIgnoreCase)); return(locale?.Value); }
public string GetText(string key) { LocaleModel locale = _data[SelectedLang.Value]; LocaleTextModel textModel = locale.texts.Find(x => x.key == key); if (null != textModel) { return(textModel.value); } LocaleTextModel defaultTextModel = _data[DefaultLang].texts.Find(x => x.key == key); return(null != defaultTextModel ? defaultTextModel.value : null); }
public void InitLocaleManager(string defaultLang = "en") { TextAsset[] tas = Resources.LoadAll <TextAsset>(path); foreach (TextAsset t in tas) { LocaleModel locale = JsonUtility.FromJson <LocaleModel>(t.text); _data[locale.lang] = locale; } DefaultLang = defaultLang; Assert.If(!_data.ContainsKey(DefaultLang), $"Locale: can't find {DefaultLang}"); SelectedLang = new WObservable <string>(DefaultLang); }
private void CollectionViewSource_Filter(object sender, FilterEventArgs e) { LocaleModel item = e.Item as LocaleModel; if (item == null) { return; } if (FilterKey == ColumnToFilter.Key && !string.IsNullOrEmpty(FilterKeyTextBox?.Text)) { e.Accepted = item.Key.ToLower().Contains(FilterKeyTextBox.Text.ToLower()); } else if (FilterKey == ColumnToFilter.Value && !string.IsNullOrEmpty(FilterValueTextBox?.Text)) { e.Accepted = item.Value.ToLower().Contains(FilterValueTextBox.Text.ToLower()); } }
/// <summary> /// Lấy thông tin. /// </summary> /// <param name="inputObject">DataModel</param> /// <returns>DataModel</returns> private InitDataModel GetInfo(InitDataModel inputObject) { // Khởi tạo biến cục bộ var getResult = new InitDataModel(); var processDao = new MasterServicesDao(); var localeCom = new LocaleCom(); var codeCom = new CodeCom(); var localeModel = new LocaleModel<ServiceObject>(); // Map dữ liệu DataHelper.CopyObject(inputObject, getResult); // Lấy ngôn ngữ chuẩn var basicLocale = localeCom.GetDefault(DataComLogics.CD_APP_CD_CLN); // Trường hợp status là edit hoặc copy if (inputObject.IsEdit || inputObject.IsCopy) { // Khởi tạo biến cục bộ var listData = DataHelper.CreateList<ServiceObject>(); // Lấy danh sách dữ liệu đa ngôn ngữ var listLocale = processDao.GetListLocale(inputObject.ServiceCd); // Khởi tạo biến dùng trong loop var rowNo = 0; var localeName = string.Empty; // Duyệt danh sách dữ liệu đa ngôn ngữ foreach (var info in listLocale) { // Lấy thông tin tên localeName = codeCom.GetName( WebContextHelper.LocaleCd, DataComLogics.GRPCD_CLN_LOCALES, info.LocaleCd, false); // Lấy số dòng if (info.LocaleCd != basicLocale) { info.RowNo = rowNo++; } // Gán thông tin dữ liệu info.LocaleName = localeName; // Xóa thông tin khi sao chép if (inputObject.IsCopy) { info.ServiceName = string.Empty; info.SearchName = string.Empty; } // Thêm vào danh sách kết quả listData.Add(info); } // Tiến hành convert đối tượng locale localeModel = DataHelper.ToLocaleModel(basicLocale, listData); } // Khởi tạo giá trị init if (inputObject.IsAdd) { localeModel.DataInfo.ServiceCd = DataHelper.GetUniqueKey(); localeModel.DataInfo.ServiceName = string.Empty; localeModel.DataInfo.SearchName = string.Empty; // localeModel.DataInfo.Slug = string.Empty; localeModel.DataInfo.FileCd = string.Empty; localeModel.DataInfo.LocaleCd = basicLocale; localeModel.DataInfo.SortKey = decimal.One; localeModel.DataInfo.DeleteFlag = false; if (inputObject.IsAddInit) { localeModel.ListLocale.Clear(); } } // Lấy danh sách code var listLocales = codeCom.GetDiv( WebContextHelper.LocaleCd, DataComLogics.GRPCD_CLN_LOCALES, basicLocale, false, false); var listDeleteFlag = codeCom.GetDivDeleteFlag(WebContextHelper.LocaleCd, false); // Lấy giá trị combo var cbLocales = DataHelper.ToComboItems(listLocales, string.Empty); var cbDeleteFlag = DataHelper.ToComboItems( listDeleteFlag, localeModel.DataInfo.DeleteFlag); // Gán giá trị trả về getResult.BasicLocale = basicLocale; getResult.LocaleModel = localeModel; getResult.CboLocales = cbLocales.ListItems; getResult.CboLocalesSeleted = cbLocales.SeletedValue; getResult.CboDeleteFlag = cbDeleteFlag.ListItems; getResult.LocaleModel.DataInfo.DeleteFlag = cbDeleteFlag.SeletedValueBoolean; // Kết quả trả về return getResult; }