private static string AbpLocalizationInfoToJsonFile(AbpLocalizationInfo localizationInfo) { var jObject = new JObject { { "culture", localizationInfo.Culture } }; var value = new JObject(); foreach (var text in localizationInfo.Texts) { value.Add(text.Name, text.Value); } jObject.Add("texts", value); return(jObject.ToString()); }
private static AbpLocalizationInfo SortLocalizedKeys(AbpLocalizationInfo targetLocalizationInfo, AbpLocalizationInfo referenceLocalizationInfo) { var sortedLocalizationInfo = new AbpLocalizationInfo { Culture = targetLocalizationInfo.Culture, Texts = new List <NameValue>() }; foreach (var targetText in referenceLocalizationInfo.Texts.Select(text => targetLocalizationInfo.Texts.FirstOrDefault(x => x.Name == text.Name)) .Where(targetText => targetText != null)) { sortedLocalizationInfo.Texts.Add(targetText); } return(sortedLocalizationInfo); }
private AbpLocalizationInfo GetAbpLocalizationInfoOrNull(string path) { if (!File.Exists(path)) { throw new CliUsageException( $"File {path} does not exist!" + Environment.NewLine + Environment.NewLine + GetUsageInfo() ); } var json = File.ReadAllText(path); JObject jObject; try { jObject = JObject.Parse(json); } catch (Exception e) { return(null); } var culture = jObject.GetValue("culture") ?? jObject.GetValue("Culture"); var texts = jObject.GetValue("texts") ?? jObject.GetValue("Texts"); if (culture == null || texts == null) { return(null); } var localizationInfo = new AbpLocalizationInfo { Culture = culture.Value <string>(), Texts = new List <NameValue>() }; foreach (var text in texts) { var property = (text as JProperty); localizationInfo.Texts.Add(new NameValue(property?.Name, property?.Value.Value <string>())); } return(localizationInfo); }