Beispiel #1
0
        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 }));
        }
Beispiel #2
0
        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"));
        }
Beispiel #3
0
        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();
            }
        }
Beispiel #4
0
        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)
            });
        }
Beispiel #5
0
        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));
        }
Beispiel #6
0
        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),
            });
        }
Beispiel #7
0
        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));
        }
Beispiel #8
0
        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));
        }