コード例 #1
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),
            });
        }
コード例 #2
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));
        }