public MetadataRecord BuildMetadataRecord(string defaultLanguage, string defaultValue, ICollection <Translation> translations, ICollection <Language> languages) { var result = new MetadataRecord(); var languageExists = languages.Any(_ => _.Code == defaultLanguage); if (languageExists) { var translation = translations.FirstOrDefault(_ => _.LanguageCode == defaultLanguage); result.Translations.Add(new TranslationResult { Language = defaultLanguage, Value = translation == null ? $"[{defaultValue}]" : translation.Value }); return(result); } foreach (var language in languages) { var translation = translations.FirstOrDefault(_ => _.LanguageCode == defaultLanguage); result.Translations.Add(new TranslationResult { Language = defaultLanguage, Value = translation == null ? $"[{defaultValue}]" : translation.Value }); } return(result); }
private MetadataRecord BuildMetadataRecord(Type type, string defaultLanguage, ICollection <Translation> translations) { var names = Enum.GetNames(type); var result = new MetadataRecord(); foreach (var name in names) { var child = new MetadataRecord(); var value = GetValue(type, name); var trs = translations.Where(_ => _.Code == GetTranslationCode(type, name)); if (!trs.Any()) { child.Translations.Add(new TranslationResult { Language = defaultLanguage, Value = $"[{name}]" }); } else { foreach (var tr in trs) { child.Translations.Add(new TranslationResult { Language = tr.LanguageCode, Value = tr.Value }); } } result.Children.Add(value, child); } return(result); }