public static void SynchronizeTypes(Assembly assembly, string directoryName) { string assemblyName = assembly.GetName().Name !; HashSet <string> newNames = (from t in assembly.GetTypes() let opts = LocalizedAssembly.GetDescriptionOptions(t) where opts != DescriptionOptions.None select t.Name).ToHashSet(); Dictionary <string, string?> memory = new Dictionary <string, string?>(); foreach (var fileName in Directory.EnumerateFiles(directoryName, "{0}.*.xml".FormatWith(assemblyName))) { var doc = XDocument.Load(fileName); HashSet <string> oldNames = doc.Element("Translations").Elements("Type").Select(t => t.Attribute("Name").Value).ToHashSet(); Dictionary <string, string> replacements = AskForReplacementsWithMemory(newNames.ToHashSet(), oldNames.ToHashSet(), memory, replacementKey: Path.GetFileNameWithoutExtension(fileName) !); //cloning var culture = fileName.After(assemblyName + ".").Before(".xml"); var locAssem = LocalizedAssembly.FromXml(assembly, CultureInfo.GetCultureInfo(culture), doc, replacements?.Inverse()); locAssem.ToXml().Save(fileName); } }
public static Dictionary <string, TypeInfoTS> GetEnums(IEnumerable <Type> allTypes) { var queries = QueryLogic.Queries; var result = (from type in allTypes where type.IsEnum let descOptions = LocalizedAssembly.GetDescriptionOptions(type) where descOptions != DescriptionOptions.None let kind = type.Name.EndsWith("Query") ? KindOfType.Query : type.Name.EndsWith("Message") ? KindOfType.Message : KindOfType.Enum select KVP.Create(GetTypeName(type), OnAddTypeExtension(new TypeInfoTS { Kind = kind, FullName = type.FullName, NiceName = descOptions.HasFlag(DescriptionOptions.Description) ? type.NiceName() : null, Members = type.GetFields(staticFlags) .Where(fi => kind != KindOfType.Query || queries.QueryDefined(fi.GetValue(null))) .ToDictionary(fi => fi.Name, fi => OnAddFieldInfoExtension(new MemberInfoTS { NiceName = fi.NiceName(), IsIgnoredEnum = kind == KindOfType.Enum && fi.HasAttribute <IgnoreAttribute>() }, fi)), }, type))).ToDictionaryEx("enums"); return(result); }
private static LocalizedAssemblyChanges Translate(ITranslator translator, LocalizedAssembly target, List <LocalizedTypeChanges> types) { List <IGrouping <CultureInfo, TypeNameConflict> > typeGroups = (from t in types where t.TypeConflict != null from tc in t.TypeConflict select tc).GroupBy(a => a.Key, a => a.Value).ToList(); foreach (IGrouping <CultureInfo, TypeNameConflict> gr in typeGroups) { List <string?> result = translator.TranslateBatch(gr.Select(a => a.Original.Description !).ToList(), gr.Key.Name, target.Culture.Name); gr.ZipForeach(result, (sp, translated) => sp.Translated = translated); } List <IGrouping <CultureInfo, MemberNameConflict> > memberGroups = (from t in types where t.MemberConflicts != null from mcKVP in t.MemberConflicts from mc in mcKVP.Value select mc).GroupBy(a => a.Key, a => a.Value).ToList(); foreach (IGrouping <CultureInfo, MemberNameConflict> gr in memberGroups) { var result = translator.TranslateBatch(gr.Select(a => a.Original !).ToList(), gr.Key.Name, target.Culture.Name); gr.ZipForeach(result, (sp, translated) => sp.Translated = translated); } return(new LocalizedAssemblyChanges { LocalizedAssembly = target, Types = types, }); }
public ActionResult Index(Lite <RoleEntity> role) { var cultures = TranslationLogic.CurrentCultureInfos(CultureInfo.GetCultureInfo("en")); var assemblies = AssembliesToLocalize().ToDictionary(a => a.FullName); var dg = DirectedGraph <Assembly> .Generate(assemblies.Values, a => a.GetReferencedAssemblies().Select(an => assemblies.TryGetC(an.FullName)).NotNull()); var dic = dg.CompilationOrderGroups().SelectMany(gr => gr.OrderBy(a => a.FullName)).ToDictionary(a => a, a => cultures.Select(ci => new TranslationFile { Assembly = a, CultureInfo = ci, IsDefault = ci.Name == a.GetCustomAttribute <DefaultAssemblyCultureAttribute>().DefaultCulture, FileName = LocalizedAssembly.TranslationFileName(a, ci) }).ToDictionary(tf => tf.CultureInfo)); if (role != null) { ViewBag.Role = role.InDB().Select(e => e.ToLite()).SingleEx(); } return(base.View(TranslationClient.ViewPrefix.FormatWith("Index"), dic)); }
private static MvcHtmlString InternalComboBox(HtmlHelper helper, ValueLine valueLine, Type uType, Enum value) { if (valueLine.ReadOnly) { MvcHtmlString result = MvcHtmlString.Empty; if (valueLine.WriteHiddenOnReadonly) { result = result.Concat(HiddenWithoutId(valueLine.Prefix, valueLine.UntypedValue.ToString())); } string str = value == null ? null : LocalizedAssembly.GetDescriptionOptions(uType).IsSet(DescriptionOptions.Members) ? value.NiceToString() : value.ToString(); return(result.Concat(helper.FormControlStatic(valueLine, valueLine.Prefix, str, valueLine.ValueHtmlProps))); } StringBuilder sb = new StringBuilder(); List <SelectListItem> items = valueLine.EnumComboItems ?? valueLine.CreateComboItems(); if (value != null) { items.Where(e => e.Value == value.ToString()) .SingleOrDefaultEx()?.Do(s => s.Selected = true); } valueLine.ValueHtmlProps.AddCssClass("form-control"); return(helper.SafeDropDownList(valueLine.Prefix, items, valueLine.ValueHtmlProps)); }
public int TotalOriginalLength() { var ci = CultureInfo.GetCultureInfo(LocalizedAssembly.GetDefaultAssemblyCulture(Type.Assembly.Assembly)); return((TypeConflict == null ? 0 : TypeConflict[ci].Original.Description.Length) + MemberConflicts.Values.Sum(m => m[ci].Original.Length)); }
public static List <LocalizedTypeChanges> GetMergeChanges(LocalizedAssembly target, LocalizedAssembly master, List <LocalizedAssembly> support) { var types = master.Types.Select(kvp => { Type type = kvp.Key; LocalizedType targetType = target.Types.GetOrThrow(type); LocalizedType masterType = master.Types[type]; List <LocalizedType> supportTypes = support.Select(la => la.Types.TryGetC(type)).NotNull().ToList(); Dictionary <CultureInfo, TypeNameConflict>?typeConflicts = TypeConflicts(targetType, masterType, supportTypes); var memberConflicts = (from m in masterType.Members !.Keys let con = MemberConflicts(m, targetType, masterType, supportTypes) where con != null select KeyValuePair.Create(m, con)).ToDictionary(); if (memberConflicts.IsEmpty() && typeConflicts == null) { return(null); } return(new LocalizedTypeChanges { Type = targetType, TypeConflict = typeConflicts, MemberConflicts = memberConflicts }); }).NotNull().ToList(); return(types); }
public LocalizableTypeTS(Type type) { var options = LocalizedAssembly.GetDescriptionOptions(type); this.type = type.Name; hasDescription = options.IsSet(DescriptionOptions.Description); hasPluralDescription = options.IsSet(DescriptionOptions.PluralDescription); hasMembers = options.IsSet(DescriptionOptions.Members); hasGender = options.IsSet(DescriptionOptions.Gender); }
public static Dictionary <string, TypeInfoTS> GetEntities(IEnumerable <Type> allTypes) { var models = (from type in allTypes where typeof(ModelEntity).IsAssignableFrom(type) && !type.IsAbstract select type).ToList(); var queries = QueryLogic.Queries; var schema = Schema.Current; var settings = Schema.Current.Settings; var result = (from type in TypeLogic.TypeToEntity.Keys.Concat(models) where !type.IsEnumEntity() && !ReflectionServer.ExcludeTypes.Contains(type) let descOptions = LocalizedAssembly.GetDescriptionOptions(type) let allOperations = !type.IsEntity() ? null : OperationLogic.GetAllOperationInfos(type) select KVP.Create(GetTypeName(type), OnAddTypeExtension(new TypeInfoTS { Kind = KindOfType.Entity, FullName = type.FullName, NiceName = descOptions.HasFlag(DescriptionOptions.Description) ? type.NiceName() : null, NicePluralName = descOptions.HasFlag(DescriptionOptions.PluralDescription) ? type.NicePluralName() : null, Gender = descOptions.HasFlag(DescriptionOptions.Gender) ? type.GetGender().ToString() : null, EntityKind = type.IsIEntity() ? EntityKindCache.GetEntityKind(type) : (EntityKind?)null, EntityData = type.IsIEntity() ? EntityKindCache.GetEntityData(type) : (EntityData?)null, IsLowPopulation = type.IsIEntity() ? EntityKindCache.IsLowPopulation(type) : false, IsSystemVersioned = type.IsIEntity() ? schema.Table(type).SystemVersioned != null : false, ToStringFunction = typeof(Symbol).IsAssignableFrom(type) ? null : LambdaToJavascriptConverter.ToJavascript(ExpressionCleaner.GetFieldExpansion(type, miToString)), QueryDefined = queries.QueryDefined(type), Members = PropertyRoute.GenerateRoutes(type).Where(pr => InTypeScript(pr)) .ToDictionary(p => p.PropertyString(), p => { var mi = new MemberInfoTS { NiceName = p.PropertyInfo?.NiceName(), TypeNiceName = GetTypeNiceName(p.PropertyInfo?.PropertyType), Format = p.PropertyRouteType == PropertyRouteType.FieldOrProperty ? Reflector.FormatString(p) : null, IsReadOnly = !IsId(p) && (p.PropertyInfo?.IsReadOnly() ?? false), Unit = UnitAttribute.GetTranslation(p.PropertyInfo?.GetCustomAttribute <UnitAttribute>()?.UnitName), Type = new TypeReferenceTS(IsId(p) ? PrimaryKey.Type(type).Nullify() : p.PropertyInfo?.PropertyType, p.Type.IsMList() ? p.Add("Item").TryGetImplementations() : p.TryGetImplementations()), IsMultiline = Validator.TryGetPropertyValidator(p)?.Validators.OfType <StringLengthValidatorAttribute>().FirstOrDefault()?.MultiLine ?? false, MaxLength = Validator.TryGetPropertyValidator(p)?.Validators.OfType <StringLengthValidatorAttribute>().FirstOrDefault()?.Max.DefaultToNull(-1), PreserveOrder = settings.FieldAttributes(p)?.OfType <PreserveOrderAttribute>().Any() ?? false, }; return(OnAddPropertyRouteExtension(mi, p)); }), Operations = allOperations == null ? null : allOperations.ToDictionary(oi => oi.OperationSymbol.Key, oi => OnAddOperationExtension(new OperationInfoTS(oi), oi, type)), RequiresEntityPack = allOperations != null && allOperations.Any(oi => oi.HasCanExecute != null), }, type))).ToDictionaryEx("entities"); return(result); }
public static TranslationController.LocalizableTypeTS ToLocalizableTypeTS(this Type type) { var options = LocalizedAssembly.GetDescriptionOptions(type); return(new TranslationController.LocalizableTypeTS() { type = type.Name, hasDescription = options.IsSet(DescriptionOptions.Description), hasPluralDescription = options.IsSet(DescriptionOptions.PluralDescription), hasMembers = options.IsSet(DescriptionOptions.Members), hasGender = options.IsSet(DescriptionOptions.Gender), }); }
public ActionResult SaveView(string assembly, string culture, string filter) { var currentAssembly = AssembliesToLocalize().Single(a => a.GetName().Name == assembly); List <TranslationRecord> list = GetTranslationRecords(); if (culture.HasText()) { LocalizedAssembly locAssembly = LocalizedAssembly.ImportXml(currentAssembly, CultureInfo.GetCultureInfo(culture), forceCreate: true); list.GroupToDictionary(a => a.Type).JoinDictionaryForeach(locAssembly.Types.Values.ToDictionary(a => a.Type.Name), (tn, tuples, lt) => { foreach (var t in tuples) { t.Apply(lt); } }); locAssembly.ExportXml(); } else { Dictionary <string, LocalizedAssembly> locAssemblies = TranslationLogic.CurrentCultureInfos(CultureInfo.GetCultureInfo("en")).ToDictionary(ci => ci.Name, ci => LocalizedAssembly.ImportXml(currentAssembly, ci, forceCreate: true)); Dictionary <string, List <TranslationRecord> > groups = list.GroupToDictionary(a => a.Lang); list.GroupToDictionary(a => a.Lang).JoinDictionaryForeach(locAssemblies, (cn, recs, la) => { recs.GroupToDictionary(a => a.Type).JoinDictionaryForeach(la.Types.Values.ToDictionary(a => a.Type.Name), (tn, tuples, lt) => { foreach (var t in tuples) { t.Apply(lt); } }); la.ExportXml(); }); } return(RedirectToAction("View", new { assembly = assembly, culture = culture, searchPressed = true, filter = filter })); }
public ActionResult SaveSync(string assembly, string culture) { Assembly currentAssembly = AssembliesToLocalize().Where(a => a.GetName().Name == assembly).SingleEx(() => "Assembly {0}".FormatWith(assembly)); LocalizedAssembly locAssembly = LocalizedAssembly.ImportXml(currentAssembly, CultureInfo.GetCultureInfo(culture), forceCreate: true); List <TranslationRecord> records = GetTranslationRecords(); records.GroupToDictionary(a => a.Type).JoinDictionaryForeach(DictionaryByTypeName(locAssembly), (tn, tuples, lt) => { foreach (var t in tuples) { t.Apply(lt); } }); locAssembly.ExportXml(); return(RedirectToAction("Index")); }
public static List <NamespaceSyncStats> SyncNamespaceStats(LocalizedAssembly target, LocalizedAssembly master) { return(master.Types.Select(kvp => { var ltm = kvp.Value; var ltt = target.Types.TryGetC(kvp.Key); var count = ((ltm.IsTypeCompleted() && ltt?.IsTypeCompleted() != true) ? 1 : 0) + ltm.Members !.Count(kvp2 => kvp2.Value != null && ltt?.Members !.TryGetC(kvp2.Key) == null); return new { Type = kvp.Key, count }; }) .Where(a => a.count > 0) .GroupBy(a => a.Type !.Namespace !) .Select(gr => new NamespaceSyncStats { @namespace = gr.Key, types = gr.Count(), translations = gr.Sum(a => a.count) }).ToList()); }
internal static LocalizedType ImportXml(Type type, DescriptionOptions opts, LocalizedAssembly assembly, XElement x) { string?description = !opts.IsSetAssert(DescriptionOptions.Description, type) ? null : (x == null || x.Attribute("Name").Value != type.Name ? null : x.Attribute("Description")?.Value) ?? (!assembly.IsDefault ? null : DescriptionManager.DefaultTypeDescription(type)); var xMembers = x?.Elements("Member") .Select(m => KeyValuePair.Create(m.Attribute("Name").Value, m.Attribute("Description").Value)) .Distinct(m => m.Key) .ToDictionary(); LocalizedType result = new LocalizedType { Type = type, Options = opts, Assembly = assembly, Description = description, PluralDescription = !opts.IsSetAssert(DescriptionOptions.PluralDescription, type) ? null : ((x == null || x.Attribute("Name").Value != type.Name ? null : x.Attribute("PluralDescription")?.Value) ?? (!assembly.IsDefault ? null : type.GetCustomAttribute <PluralDescriptionAttribute>()?.PluralDescription) ?? (description == null ? null : NaturalLanguageTools.Pluralize(description, assembly.Culture))), Gender = !opts.IsSetAssert(DescriptionOptions.Gender, type) ? null : ((x?.Attribute("Gender")?.Value.Single()) ?? (!assembly.IsDefault ? null : type.GetCustomAttribute <GenderAttribute>()?.Gender) ?? (description == null ? null : NaturalLanguageTools.GetGender(description, assembly.Culture))), Members = !opts.IsSetAssert(DescriptionOptions.Members, type) ? null : (from m in GetMembers(type) where DescriptionManager.OnShouldLocalizeMember(m) let value = xMembers?.TryGetC(m.Name) ?? (!assembly.IsDefault ? null : DescriptionManager.DefaultMemberDescription(m)) where value != null select KeyValuePair.Create(m.Name, value)) .ToDictionary() }; return(result); }
public static LocalizedAssembly FromXml(Assembly assembly, CultureInfo cultureInfo, XDocument?doc, Dictionary <string, string>?replacements /*new -> old*/) { Dictionary <string, XElement>?file = doc?.Element("Translations").Elements("Type") .Select(x => KeyValuePair.Create(x.Attribute("Name").Value, x)) .Distinct(x => x.Key) .ToDictionary(); var result = new LocalizedAssembly { Assembly = assembly, Culture = cultureInfo, IsDefault = GetDefaultAssemblyCulture(assembly) == cultureInfo.Name }; result.Types = (from t in assembly.GetTypes() let opts = GetDescriptionOptions(t) where opts != DescriptionOptions.None let x = file?.TryGetC(replacements?.TryGetC(t.Name) ?? t.Name) select LocalizedType.ImportXml(t, opts, result, x)) .ToDictionary(lt => lt.Type); return(result); }
private TranslatedSummaryState CalculateStatus(Assembly a, CultureInfo ci) { var fileName = LocalizedAssembly.TranslationFileName(a, ci); if (!System.IO.File.Exists(fileName)) { return(TranslatedSummaryState.None); } var target = DescriptionManager.GetLocalizedAssembly(a, ci) !; CultureInfo defaultCulture = CultureInfo.GetCultureInfo(a.GetCustomAttribute <DefaultAssemblyCultureAttribute>().DefaultCulture); var master = DescriptionManager.GetLocalizedAssembly(a, defaultCulture) !; var result = TranslationSynchronizer.GetMergeChanges(target, master, new List <LocalizedAssembly>()); if (result.Any()) { return(TranslatedSummaryState.Pending); } return(TranslatedSummaryState.Completed); }
public void SaveTypes(string assembly, string culture, [Required, FromBody] AssemblyResultTS result) { var currentAssembly = AssembliesToLocalize().Single(a => a.GetName().Name == assembly); var cultureGroups = (from a in result.types.Values from lt in a.cultures.Values group new { a.type, lt } by lt.culture into cg select cg).ToList(); foreach (var cultureGroup in cultureGroups) { LocalizedAssembly locAssembly = LocalizedAssembly.ImportXml(currentAssembly, CultureInfo.GetCultureInfo(cultureGroup.Key), forceCreate: true) !; var types = cultureGroup.ToDictionary(a => a.type !, a => a.lt !); /*CSBUG*/ foreach (var lt in locAssembly.Types.Values) { var ts = types.TryGetC(lt.Type.Name); if (ts != null) { if (ts.typeDescription != null) { var td = ts.typeDescription; lt.Gender = td.gender?[0]; lt.Description = td.description; lt.PluralDescription = td.pluralDescription; } lt.Members !.SetRange(ts.members.Select(a => KVP.Create(a.Key !, a.Value.description !))); } } locAssembly.ExportXml(); } }
public AssemblyResultTS Retrieve(string assembly, string culture, string filter) { Assembly ass = AssembliesToLocalize().Where(a => a.GetName().Name == assembly).SingleEx(() => "Assembly {0}".FormatWith(assembly)); CultureInfo defaultCulture = CultureInfo.GetCultureInfo(ass.GetCustomAttribute <DefaultAssemblyCultureAttribute>().DefaultCulture); CultureInfo?targetCulture = culture == null ? null : CultureInfo.GetCultureInfo(culture); var cultures = TranslationLogic.CurrentCultureInfos(defaultCulture); Dictionary <string, LocalizableTypeTS> types = (from ci in cultures let la = DescriptionManager.GetLocalizedAssembly(ass, ci) where la != null || ci == defaultCulture || ci == targetCulture let la2 = la ?? LocalizedAssembly.ImportXml(ass, ci, forceCreate: true) from t in la2.Types.Values let lt = new LocalizedTypeTS { culture = ci.Name, typeDescription = new LocalizedDescriptionTS { gender = t.Gender?.ToString(), description = t.Description, pluralDescription = t.PluralDescription, }, members = t.Members.Select(kvp => new LocalizedMemberTS { name = kvp.Key, description = kvp.Value }).ToDictionary(a => a.name), } group lt by t.Type into g select KVP.Create(g.Key.Name, g.Key.ToLocalizableTypeTS().Let(localizedTypes => { localizedTypes.cultures = g.ToDictionary(a => a.culture); return(localizedTypes); }))) .ToDictionaryEx("types"); types.ToList().ForEach(lt => lt.Value.FixMembers(defaultCulture)); if (filter.HasText()) { var complete = types.Extract((k, v) => v.type.Contains(filter, StringComparison.InvariantCultureIgnoreCase) || v.cultures.Values.Select(a => a.typeDescription !).Any(td => td.description != null && td.description.Contains(filter, StringComparison.InvariantCultureIgnoreCase) || td.pluralDescription != null && td.pluralDescription.Contains(filter, StringComparison.InvariantCultureIgnoreCase))); var filtered = types.Extract((k, v) => { var allMembers = v.cultures.Values.SelectMany(a => a.members.Keys).Distinct().ToList(); var filteredMembers = allMembers.Where(m => m.Contains(filter, StringComparison.InvariantCultureIgnoreCase) || v.cultures.Values.Any(lt => lt.members.GetOrThrow(m).description?.Contains(filter, StringComparison.InvariantCultureIgnoreCase) ?? false)) .ToList(); if (filteredMembers.Count == 0) { return(false); } foreach (var item in v.cultures.Values) { item.members = item.members.Where(a => filteredMembers.Contains(a.Key)).ToDictionary(); } return(true); }); types = complete.Concat(filtered).ToDictionary(); } return(new AssemblyResultTS { types = types.OrderBy(a => a.Key).ToDictionary(), cultures = cultures.Select(c => c.ToCulturesTS()) .ToDictionary(a => a.name) }); }
private static LocalizedAssemblyChanges Translate(ITranslator[] translators, LocalizedAssembly target, List <LocalizedTypeChanges> types) { List <IGrouping <CultureInfo, TypeNameConflict> > typeGroups = (from t in types where t.TypeConflict != null from tc in t.TypeConflict ! select tc).GroupBy(a => a.Key, a => a.Value).ToList(); foreach (IGrouping <CultureInfo, TypeNameConflict> gr in typeGroups) { var valid = gr.Where(a => a.Original.Description != null); var originalDescriptions = valid.Select(a => (a.Original.Options.HasFlag(DescriptionOptions.Gender) ? (NaturalLanguageTools.GetDeterminer(a.Original.Gender, false, gr.Key) + " " + a.Original.Description !) : a.Original.Description) + (a.Original.Options.HasFlag(DescriptionOptions.PluralDescription) ? "\n" + a.Original.PluralDescription : "") ).ToList(); foreach (var tr in translators) { var translations = tr.TranslateBatch(originalDescriptions, gr.Key.Name, target.Culture.Name); if (translations != null) { valid.ZipForeach(translations, (sp, translated) => { if (translated != null) { var lines = translated.Lines(); var singular = lines[0]; var plural = sp.Original.Options.HasFlag(DescriptionOptions.PluralDescription) ? lines[1] : null; char?gender = null; if (sp.Original.Options.HasFlag(DescriptionOptions.Gender) && NaturalLanguageTools.TryGetGenderFromDeterminer(singular.TryBefore(" "), false, target.Culture, out gender)) { singular = singular.After(" "); } sp.AutomaticTranslations.Add(new AutomaticTypeTranslation { Singular = singular, Plural = plural, Gender = gender, TranslatorName = tr.Name }); } }); } } } List <IGrouping <CultureInfo, MemberNameConflict> > memberGroups = (from t in types where t.MemberConflicts != null from mcKVP in t.MemberConflicts from mc in mcKVP.Value select mc).GroupBy(a => a.Key, a => a.Value).ToList(); foreach (IGrouping <CultureInfo, MemberNameConflict> gr in memberGroups) { var valid = gr.Where(a => a.Original != null).ToList(); var originalDescriptions = valid.Select(a => a.Original !).ToList(); foreach (var tr in translators) { var translations = tr.TranslateBatch(originalDescriptions, gr.Key.Name, target.Culture.Name); if (translations != null) { gr.ZipForeach(translations, (sp, translated) => { if (translated != null) { sp.AutomaticTranslations.Add(new AutomaticTranslation { Text = translated, TranslatorName = tr.Name }); } }); } } } return(new LocalizedAssemblyChanges { LocalizedAssembly = target, Types = types, }); }
public AssemblyResultTS Sync(string assembly, string culture, string? @namespace = null) { Assembly ass = AssembliesToLocalize().Where(a => a.GetName().Name == assembly).SingleEx(() => "Assembly {0}".FormatWith(assembly)); CultureInfo targetCulture = CultureInfo.GetCultureInfo(culture); CultureInfo defaultCulture = CultureInfo.GetCultureInfo(ass.GetCustomAttribute <DefaultAssemblyCultureAttribute>().DefaultCulture); var cultures = TranslationLogic.CurrentCultureInfos(defaultCulture); Dictionary <CultureInfo, LocalizedAssembly> reference = (from ci in cultures let la = DescriptionManager.GetLocalizedAssembly(ass, ci) where la != null || ci == defaultCulture || ci == targetCulture select KVP.Create(ci, la ?? LocalizedAssembly.ImportXml(ass, ci, forceCreate: ci == defaultCulture || ci == targetCulture))).ToDictionary(); var master = reference.Extract(defaultCulture); var target = reference.Extract(targetCulture); var changes = TranslationSynchronizer.GetAssemblyChanges(TranslationServer.Translator, target, master, reference.Values.ToList(), null, @namespace, out int totalTypes); return(new AssemblyResultTS { totalTypes = totalTypes, cultures = cultures.Select(c => c.ToCulturesTS()).ToDictionary(a => a.name), types = changes.Types.Select(t => t.Type.Type.ToLocalizableTypeTS().Let(localizedTypes => { localizedTypes.cultures = cultures.ToDictionary(c => c.Name, c => GetLocalizedType(t, c, c.Equals(targetCulture))); return localizedTypes; })).ToDictionary(lt => lt.type), }); }
public List <NamespaceSyncStats> SyncStats(string assembly, string culture) { Assembly ass = AssembliesToLocalize().Where(a => a.GetName().Name == assembly).SingleEx(() => "Assembly {0}".FormatWith(assembly)); CultureInfo targetCulture = CultureInfo.GetCultureInfo(culture); CultureInfo defaultCulture = CultureInfo.GetCultureInfo(ass.GetCustomAttribute <DefaultAssemblyCultureAttribute>().DefaultCulture); var targetAssembly = DescriptionManager.GetLocalizedAssembly(ass, targetCulture) ?? LocalizedAssembly.ImportXml(ass, targetCulture, forceCreate: true) !; var defaultAssembly = DescriptionManager.GetLocalizedAssembly(ass, defaultCulture) ?? LocalizedAssembly.ImportXml(ass, defaultCulture, forceCreate: true) !; return(TranslationSynchronizer.SyncNamespaceStats(targetAssembly, defaultAssembly)); }
private static LocalizedAssemblyChanges Translate(ITranslator[] translators, LocalizedAssembly target, List <LocalizedTypeChanges> types) { List <IGrouping <CultureInfo, TypeNameConflict> > typeGroups = (from t in types where t.TypeConflict != null from tc in t.TypeConflict ! select tc).GroupBy(a => a.Key, a => a.Value).ToList(); foreach (IGrouping <CultureInfo, TypeNameConflict> gr in typeGroups) { var valid = gr.Where(a => a.Original.Description != null); var originalDescriptions = valid.Select(a => a.Original.Description !).ToList(); foreach (var tr in translators) { var translations = tr.TranslateBatch(originalDescriptions, gr.Key.Name, target.Culture.Name); if (translations != null) { valid.ZipForeach(translations, (sp, translated) => { if (translated != null) { sp.AutomaticTranslations.Add(new AutomaticTranslation { Text = translated, TranslatorName = tr.Name }); } }); } } } List <IGrouping <CultureInfo, MemberNameConflict> > memberGroups = (from t in types where t.MemberConflicts != null from mcKVP in t.MemberConflicts from mc in mcKVP.Value select mc).GroupBy(a => a.Key, a => a.Value).ToList(); foreach (IGrouping <CultureInfo, MemberNameConflict> gr in memberGroups) { var valid = gr.Where(a => a.Original != null).ToList(); var originalDescriptions = valid.Select(a => a.Original !).ToList(); foreach (var tr in translators) { var translations = tr.TranslateBatch(originalDescriptions, gr.Key.Name, target.Culture.Name); if (translations != null) { gr.ZipForeach(translations, (sp, translated) => { if (translated != null) { sp.AutomaticTranslations.Add(new AutomaticTranslation { Text = translated, TranslatorName = tr.Name }); } }); } } } return(new LocalizedAssemblyChanges { LocalizedAssembly = target, Types = types, }); }
public ActionResult Sync(string assembly, string culture, bool translatedOnly, Lite <RoleEntity> role) { Assembly ass = AssembliesToLocalize().Where(a => a.GetName().Name == assembly).SingleEx(() => "Assembly {0}".FormatWith(assembly)); CultureInfo targetCulture = CultureInfo.GetCultureInfo(culture); CultureInfo defaultCulture = CultureInfo.GetCultureInfo(ass.GetCustomAttribute <DefaultAssemblyCultureAttribute>().DefaultCulture); Dictionary <CultureInfo, LocalizedAssembly> reference = (from ci in TranslationLogic.CurrentCultureInfos(defaultCulture) let la = DescriptionManager.GetLocalizedAssembly(ass, ci) where la != null || ci == defaultCulture || ci == targetCulture select KVP.Create(ci, la ?? LocalizedAssembly.ImportXml(ass, ci, forceCreate: true))).ToDictionary(); var master = reference.Extract(defaultCulture); var target = reference.Extract(targetCulture); DictionaryByTypeName(target); //To avoid finding duplicated types on save int totalTypes; var changes = TranslationSynchronizer.GetAssemblyChanges(TranslationClient.Translator, target, master, reference.Values.ToList(), role, null, out totalTypes); ViewBag.Role = role; ViewBag.TotalTypes = totalTypes; ViewBag.Culture = targetCulture; return(base.View(TranslationClient.ViewPrefix.FormatWith("Sync"), changes)); }
public static LocalizedAssemblyChanges GetAssemblyChanges(ITranslator[] translators, LocalizedAssembly target, LocalizedAssembly master, List <LocalizedAssembly> support, Lite <RoleEntity>?role, string? @namespace, out int totalTypes) { var types = GetMergeChanges(target, master, support); if (role != null) { types = types.Where(t => TranslationLogic.GetCountNotLocalizedMemebers(role !, t.Type.Assembly.Culture, t.Type.Type) > 0).ToList(); } if (@namespace != null) { types = types.Where(t => t.Type.Type.Namespace == @namespace).ToList(); } totalTypes = types.Count; if (types.Sum(a => a.TotalOriginalLength()) > MaxTotalSyncCharacters) { types = types.GroupsOf(a => a.TotalOriginalLength(), MaxTotalSyncCharacters).First().ToList(); } var result = Translate(translators, target, types); return(result); }
static Dictionary <string, LocalizedType> DictionaryByTypeName(LocalizedAssembly locAssembly) { return(locAssembly.Types.Values.ToDictionaryEx(a => a.Type.Name, "LocalizedTypes")); }
public ActionResult View(string assembly, string culture, bool searchPressed, string filter) { Assembly ass = AssembliesToLocalize().Where(a => a.GetName().Name == assembly).SingleEx(() => "Assembly {0}".FormatWith(assembly)); CultureInfo defaultCulture = CultureInfo.GetCultureInfo(ass.GetCustomAttribute <DefaultAssemblyCultureAttribute>().DefaultCulture); CultureInfo targetCulture = culture == null ? null : CultureInfo.GetCultureInfo(culture); Dictionary <CultureInfo, LocalizedAssembly> reference = !searchPressed ? null : (from ci in TranslationLogic.CurrentCultureInfos(defaultCulture) let la = DescriptionManager.GetLocalizedAssembly(ass, ci) where la != null || ci == defaultCulture || ci == targetCulture select KVP.Create(ci, la ?? LocalizedAssembly.ImportXml(ass, ci, forceCreate: true))).ToDictionary(); ViewBag.filter = filter; ViewBag.searchPressed = searchPressed; ViewBag.Assembly = ass; ViewBag.DefaultCulture = defaultCulture; ViewBag.Culture = targetCulture; return(base.View(TranslationClient.ViewPrefix.FormatWith("View"), reference)); }
static QuerySettings() { FormatRules = new List <FormatterRule> { new FormatterRule("Default", c => true, c => b => FormatTools.TextBlockTemplate(b, TextAlignment.Left, null)), new FormatterRule("Checkbox", c => c.Type.UnNullify() == typeof(bool), c => b => FormatTools.CheckBoxTemplate(b, c.Format == null ? null : ConverterFactory.New(Reflector.GetPropertyFormatter(c.Format, null)))), new FormatterRule("Enum", c => c.Type.UnNullify().IsEnum, c => b => FormatTools.TextBlockTemplate(b, TextAlignment.Left, LocalizedAssembly.GetDescriptionOptions(c.Type.UnNullify()).IsSet(DescriptionOptions.Members) ? Converters.EnumDescription: null)), new FormatterRule("Number", c => Reflector.IsNumber(c.Type), c => b => FormatTools.TextBlockTemplate(b, TextAlignment.Right, c.Format == null ? null : ConverterFactory.New(Reflector.GetPropertyFormatter(c.Format, null)))), new FormatterRule("DateTime", c => c.Type.UnNullify() == typeof(DateTime), c => b => FormatTools.TextBlockTemplate(b, TextAlignment.Right, c.Format == null ? null : ConverterFactory.New(Reflector.GetPropertyFormatter(c.Format, null)))), new FormatterRule("TimeSpan", c => c.Type.UnNullify() == typeof(TimeSpan), c => b => FormatTools.TextBlockTemplate(b, TextAlignment.Right, c.Format == null ? null : ConverterFactory.New(Reflector.GetPropertyFormatter(c.Format, null)))), new FormatterRule("Lite", c => c.Type.IsLite(), //Not on entities! c => b => FormatTools.LightEntityLineTemplate(b)), new FormatterRule("NumberUnit", c => Reflector.IsNumber(c.Type) && c.Unit != null, c => b => FormatTools.TextBlockTemplate(b, TextAlignment.Right, ConverterFactory.New(Reflector.GetPropertyFormatter(c.Format, c.Unit)))) }; PropertyFormatters = new Dictionary <PropertyRoute, Func <Binding, DataTemplate> >(); }
public override string ToString() { return("Changes for {0}".FormatWith(LocalizedAssembly.ToString())); }