Ejemplo n.º 1
0
        public void AddLocalization(string languageCode, string key, string value)
        {
            Dictionary <string, string> values;

            if (!Localizations.TryGetValue(languageCode, out values))
            {
                values = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                Localizations.Add(languageCode, values);
            }

            values[key] = value;
        }
Ejemplo n.º 2
0
        public PluginDocumentationPage(Type pluginType)
        {
            PluginType = pluginType;
            var image = pluginType.GetImage(0).Source;

            _xml = GetXML(pluginType);

            var authorAttribut = pluginType.GetPluginAuthorAttribute();

            if (authorAttribut != null)
            {
                AuthorName      = authorAttribut.Author;
                AuthorEmail     = authorAttribut.Email;
                AuthorInstitute = authorAttribut.Institute;
                AuthorURL       = authorAttribut.URL;
            }

            if (pluginType.GetComponentCategoryAttributes().Count() > 0)
            {
                Category = pluginType.GetComponentCategoryAttributes().First().Category;
            }
            else
            {
                Category = ComponentCategory.Undefined;
            }
            Settings = GetSettings(pluginType);

            if (_xml == null || _xml.Name != "documentation")
            {
                //entity doesn't have a proper _xml file
                _xml = null;
                Localizations.Add("en", CreateLocalizedEntityDocumentationPage(this, pluginType, null, "en", image as BitmapFrame));
            }
            else
            {
                foreach (var lang in XMLHelper.GetAvailableLanguagesFromXML(_xml.Elements("language").Select(langElement => langElement.Attribute("culture").Value)))
                {
                    Localizations.Add(lang, CreateLocalizedEntityDocumentationPage(this, pluginType, _xml, lang, image as BitmapFrame));
                }
                if (!Localizations.ContainsKey("en"))
                {
                    throw new Exception("Documentation should at least support english language!");
                }

                References = XMLHelper.ReadReferences(_xml);
            }
        }
Ejemplo n.º 3
0
        public virtual void LoadLocalizations(TEntity ent)
        {
            TranslateService translateService = ServiceProvider.GetService <TranslateService>();

            foreach (var culture in CultureHelper.Cultures)
            {
                TLocaleModel localeModel = Activator.CreateInstance <TLocaleModel>();

                Type           entType          = ent.GetType();
                Type           localeType       = localeModel.GetType();
                PropertyInfo[] entProperties    = entType.GetProperties();
                PropertyInfo[] localeProperties = localeType.GetProperties();

                foreach (PropertyInfo localeProperty in localeProperties)
                {
                    if (localeProperty.IsStringProperty())
                    {
                        PropertyInfo entProperty = entProperties.FirstOrDefault(w => w.Name == localeProperty.Name);

                        if (entProperty == null)
                        {
                            continue;
                        }

                        localeProperty.SetValue(
                            localeModel,
                            translateService.GetTranslation(entProperty.GetValue(ent, null).ToString(), culture.Code),
                            null
                            );
                    }
                }

                localeModel.CultureCode = culture.Code;
                Localizations.Add(localeModel);
            }
        }
Ejemplo n.º 4
0
        public void LoadTemplate(string template, TemplateModel parameters)
        {
            PassbookGeneratorSection section = ConfigurationManager.GetSection("passbookGenerator") as PassbookGeneratorSection;

            if (section == null)
            {
                throw new System.Configuration.ConfigurationErrorsException("\"passbookGenerator\" section could not be loaded.");
            }

            String path = TemplateModel.MapPath(section.AppleWWDRCACertificate);

            if (File.Exists(path))
            {
                this.AppleWWDRCACertificate = File.ReadAllBytes(path);
            }

            TemplateElement templateConfig = section
                                             .Templates
                                             .OfType <TemplateElement>()
                                             .FirstOrDefault(t => String.Equals(t.Name, template, StringComparison.OrdinalIgnoreCase));

            if (templateConfig == null)
            {
                throw new System.Configuration.ConfigurationErrorsException(String.Format("Configuration for template \"{0}\" could not be loaded.", template));
            }

            this.Style = templateConfig.PassStyle;

            if (this.Style == PassStyle.BoardingPass)
            {
                this.TransitType = templateConfig.TransitType;
            }

            // Certificates
            this.CertificatePassword = templateConfig.CertificatePassword;
            this.CertThumbprint      = templateConfig.CertificateThumbprint;

            path = TemplateModel.MapPath(templateConfig.Certificate);
            if (File.Exists(path))
            {
                this.Certificate = File.ReadAllBytes(path);
            }

            if (String.IsNullOrEmpty(this.CertThumbprint) && this.Certificate == null)
            {
                throw new System.Configuration.ConfigurationErrorsException("Either Certificate or CertificateThumbprint is not configured correctly.");
            }

            // Standard Keys
            this.Description        = templateConfig.Description.Value;
            this.OrganizationName   = templateConfig.OrganizationName.Value;
            this.PassTypeIdentifier = templateConfig.PassTypeIdentifier.Value;
            this.TeamIdentifier     = templateConfig.TeamIdentifier.Value;

            // Associated App Keys
            if (templateConfig.AppLaunchURL != null && !String.IsNullOrEmpty(templateConfig.AppLaunchURL.Value))
            {
                this.AppLaunchURL = templateConfig.AppLaunchURL.Value;
            }

            this.AssociatedStoreIdentifiers.AddRange(templateConfig.AssociatedStoreIdentifiers.OfType <ConfigurationProperty <int> >().Select(s => s.Value));

            // Visual Appearance Keys
            this.BackgroundColor    = templateConfig.BackgroundColor.Value;
            this.ForegroundColor    = templateConfig.ForegroundColor.Value;
            this.GroupingIdentifier = templateConfig.GroupingIdentifier.Value;
            this.LabelColor         = templateConfig.LabelColor.Value;
            this.LogoText           = templateConfig.LogoText.Value;
            this.SuppressStripShine = templateConfig.SuppressStripShine.Value;

            // Web Service Keys
            this.AuthenticationToken = templateConfig.AuthenticationToken.Value;
            this.WebServiceUrl       = templateConfig.WebServiceURL.Value;

            // Fields
            this.AuxiliaryFields.AddRange(TemplateFields(templateConfig.AuxiliaryFields, parameters));
            this.BackFields.AddRange(TemplateFields(templateConfig.BackFields, parameters));
            this.HeaderFields.AddRange(TemplateFields(templateConfig.HeaderFields, parameters));
            this.PrimaryFields.AddRange(TemplateFields(templateConfig.PrimaryFields, parameters));
            this.SecondaryFields.AddRange(TemplateFields(templateConfig.SecondaryFields, parameters));

            // Template Images
            foreach (ImageElement image in templateConfig.Images)
            {
                String imagePath = TemplateModel.MapPath(image.FileName);
                if (File.Exists(imagePath))
                {
                    this.Images[image.Type] = File.ReadAllBytes(imagePath);
                }
            }

            // Model Images (Overwriting template images)
            foreach (KeyValuePair <PassbookImage, byte[]> image in parameters.GetImages())
            {
                this.Images[image.Key] = image.Value;
            }

            // Localization
            foreach (LanguageElement localization in templateConfig.Localizations)
            {
                Dictionary <string, string> values;

                if (!Localizations.TryGetValue(localization.Code, out values))
                {
                    values = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                    Localizations.Add(localization.Code, values);
                }

                foreach (LocalizedEntry entry in localization.Localizations)
                {
                    values[entry.Key] = entry.Value;
                }
            }
        }
Ejemplo n.º 5
0
        public void InitializeFromTag(
            Imperator.Countries.Country country,
            Dictionary <ulong, Imperator.Countries.Country> imperatorCountries,
            LocalizationMapper localizationMapper,
            LandedTitles landedTitles,
            ProvinceMapper provinceMapper,
            CoaMapper coaMapper,
            TagTitleMapper tagTitleMapper,
            GovernmentMapper governmentMapper,
            SuccessionLawMapper successionLawMapper,
            DefiniteFormMapper definiteFormMapper
            )
        {
            IsImportedOrUpdatedFromImperator = true;
            ImperatorCountry = country;

            // ------------------ determine CK3 title

            LocBlock?validatedName;

            // hard code for Antigonid Kingdom, Seleucid Empire and Maurya (which use customizable localization for name and adjective)
            if (ImperatorCountry.Name == "PRY_DYN")
            {
                validatedName = localizationMapper.GetLocBlockForKey("get_pry_name_fallback");
            }
            else if (ImperatorCountry.Name == "SEL_DYN")
            {
                validatedName = localizationMapper.GetLocBlockForKey("get_sel_name_fallback");
            }
            else if (ImperatorCountry.Name == "MRY_DYN")
            {
                validatedName = localizationMapper.GetLocBlockForKey("get_mry_name_fallback");
            }
            // normal case
            else
            {
                validatedName = ImperatorCountry.CountryName.GetNameLocBlock(localizationMapper, imperatorCountries);
            }

            HasDefiniteForm = definiteFormMapper.IsDefiniteForm(ImperatorCountry.Name);

            string?title;

            if (validatedName is not null)
            {
                title = tagTitleMapper.GetTitleForTag(ImperatorCountry.Tag, ImperatorCountry.GetCountryRank(), validatedName.english);
            }
            else
            {
                title = tagTitleMapper.GetTitleForTag(ImperatorCountry.Tag, ImperatorCountry.GetCountryRank());
            }

            if (title is null)
            {
                throw new ArgumentException("Country " + ImperatorCountry.Tag + " could not be mapped!");
            }

            Name = title;

            SetRank();

            PlayerCountry = ImperatorCountry.PlayerCountry;

            // ------------------ determine previous and current holders
            history.InternalHistory.SimpleFields.Remove("holder");
            history.InternalHistory.SimpleFields.Remove("government");
            // there was no 0 AD, but year 0 works in game and serves well for adding BC characters to holder history
            var firstPossibleDate = new Date(0, 1, 1);

            foreach (var impRulerTerm in ImperatorCountry.RulerTerms)
            {
                var rulerTerm   = new RulerTerm(impRulerTerm, governmentMapper);
                var characterId = rulerTerm.CharacterId;
                var gov         = rulerTerm.Government;

                var startDate = new Date(rulerTerm.StartDate);
                if (startDate < firstPossibleDate)
                {
                    startDate = new Date(firstPossibleDate);                     // TODO: remove this workaround if CK3 supports negative dates
                    firstPossibleDate.ChangeByDays(1);
                }

                history.InternalHistory.AddSimpleFieldValue("holder", characterId, startDate);
                if (gov is not null)
                {
                    history.InternalHistory.AddSimpleFieldValue("government", gov, startDate);
                }
            }

            // ------------------ determine color
            var color1Opt = ImperatorCountry.Color1;

            if (color1Opt is not null)
            {
                Color1 = color1Opt;
            }
            var color2Opt = ImperatorCountry.Color2;

            if (color2Opt is not null)
            {
                Color2 = color2Opt;
            }

            // determine successions laws
            SuccessionLaws = successionLawMapper.GetCK3LawsForImperatorLaws(ImperatorCountry.GetLaws());

            // ------------------ determine CoA
            CoA = coaMapper.GetCoaForFlagName(ImperatorCountry.Flag);

            // ------------------ determine other attributes

            var srcCapital = ImperatorCountry.Capital;

            if (srcCapital is not null)
            {
                var provMappingsForImperatorCapital = provinceMapper.GetCK3ProvinceNumbers((ulong)srcCapital);
                if (provMappingsForImperatorCapital.Count > 0)
                {
                    var foundCounty = landedTitles.GetCountyForProvince(provMappingsForImperatorCapital[0]);
                    if (foundCounty is not null)
                    {
                        CapitalCounty = new(foundCounty.Name, foundCounty);
                    }
                }
            }

            // ------------------ Country Name Locs

            var nameSet = false;

            if (validatedName is not null)
            {
                Localizations.Add(Name, validatedName);
                nameSet = true;
            }
            if (!nameSet)
            {
                var impTagLoc = localizationMapper.GetLocBlockForKey(ImperatorCountry.Tag);
                if (impTagLoc is not null)
                {
                    Localizations.Add(Name, impTagLoc);
                    nameSet = true;
                }
            }
            // giving up
            if (!nameSet)
            {
                Logger.Warn($"{Name} needs help with localization! {ImperatorCountry.Name}?");
            }

            // --------------- Adjective Locs
            TrySetAdjectiveLoc(localizationMapper, imperatorCountries);
        }
Ejemplo n.º 6
0
        public void InitializeFromGovernorship(
            Imperator.Countries.Country country,
            Imperator.Jobs.Governorship governorship,
            Dictionary <ulong, Imperator.Characters.Character> imperatorCharacters,
            LocalizationMapper localizationMapper,
            LandedTitles landedTitles,
            ProvinceMapper provinceMapper,
            CoaMapper coaMapper,
            TagTitleMapper tagTitleMapper,
            DefiniteFormMapper definiteFormMapper,
            Mappers.Region.ImperatorRegionMapper imperatorRegionMapper
            )
        {
            IsImportedOrUpdatedFromImperator = true;

            // ------------------ determine CK3 title

            if (country.CK3Title is null)
            {
                throw new ArgumentException($"{country.Tag} governorship of {governorship.RegionName} could not be mapped to CK3 title: liege doesn't exist!");
            }

            HasDefiniteForm = definiteFormMapper.IsDefiniteForm(governorship.RegionName);

            string?title = null;

            title        = tagTitleMapper.GetTitleForGovernorship(governorship.RegionName, country.Tag, country.CK3Title.Name);
            DeJureLiege  = country.CK3Title;
            DeFactoLiege = country.CK3Title;
            if (title is null)
            {
                throw new ArgumentException($"{country.Tag} governorship of {governorship.RegionName} could not be mapped to CK3 title!");
            }

            Name = title;

            SetRank();

            PlayerCountry = false;

            var impGovernor         = imperatorCharacters[governorship.CharacterID];
            var normalizedStartDate = governorship.StartDate.Year > 0 ? governorship.StartDate : new Date(1, 1, 1);

            // ------------------ determine holder
            history.InternalHistory.AddSimpleFieldValue("holder", $"imperator{impGovernor.ID}", normalizedStartDate);

            // ------------------ determine government
            var ck3LiegeGov = country.CK3Title.GetGovernment(governorship.StartDate);

            if (ck3LiegeGov is not null)
            {
                history.InternalHistory.AddSimpleFieldValue("government", ck3LiegeGov, normalizedStartDate);
            }

            // ------------------ determine color
            var color1Opt = country.Color1;

            if (color1Opt is not null)
            {
                Color1 = color1Opt;
            }
            var color2Opt = country.Color2;

            if (color2Opt is not null)
            {
                Color2 = color2Opt;
            }

            // determine successions laws
            // https://github.com/ParadoxGameConverters/ImperatorToCK3/issues/90#issuecomment-817178552
            SuccessionLaws = new() { "high_partition_succession_law" };

            // ------------------ determine CoA
            CoA = null;             // using game-randomized CoA

            // ------------------ determine capital
            var governorProvince = impGovernor.ProvinceID;

            if (imperatorRegionMapper.ProvinceIsInRegion(governorProvince, governorship.RegionName))
            {
                foreach (var ck3Prov in provinceMapper.GetCK3ProvinceNumbers(governorProvince))
                {
                    var foundCounty = landedTitles.GetCountyForProvince(ck3Prov);
                    if (foundCounty is not null)
                    {
                        CapitalCounty = new(foundCounty.Name, foundCounty);
                        break;
                    }
                }
            }

            // ------------------ Country Name Locs
            var      nameSet                  = false;
            LocBlock?regionLocBlock           = localizationMapper.GetLocBlockForKey(governorship.RegionName);
            var      countryAdjectiveLocBlock = country.CK3Title.Localizations[country.CK3Title.Name + "_adj"];

            if (regionLocBlock is not null && countryAdjectiveLocBlock is not null)
            {
                var nameLocBlock = new LocBlock(regionLocBlock);
                nameLocBlock.ModifyForEveryLanguage(countryAdjectiveLocBlock,
                                                    (ref string orig, string adj) => orig = $"{adj} {orig}"
                                                    );
                Localizations.Add(Name, nameLocBlock);
                nameSet = true;
            }
            if (!nameSet && regionLocBlock is not null)
            {
                var nameLocBlock = new LocBlock(regionLocBlock);
                Localizations.Add(Name, nameLocBlock);
                nameSet = true;
            }
            if (!nameSet)
            {
                Logger.Warn($"{Name} needs help with localization!");
            }

            // --------------- Adjective Locs
            var adjSet = false;

            if (countryAdjectiveLocBlock is not null)
            {
                var adjLocBlock = new LocBlock(countryAdjectiveLocBlock);
                Localizations.Add(Name + "_adj", adjLocBlock);
                adjSet = true;
            }
            if (!adjSet)
            {
                Logger.Warn($"{Name} needs help with adjective localization!");
            }
        }
Ejemplo n.º 7
0
        public TemplateDocumentationPage(string templateFile, string relativeTemplateDirectory, TemplateDirectory templateDir)
        {
            _relativeTemplateDirectory = relativeTemplateDirectory;
            TemplateFile = templateFile;
            TemplateDir  = templateDir;

            string templateXMLFile = Path.Combine(Path.GetDirectoryName(templateFile), Path.GetFileNameWithoutExtension(templateFile) + ".xml");

            if (!File.Exists(templateXMLFile))
            {
                throw new Exception(string.Format("Missing meta infos for template {0}!", templateFile));
            }

            TemplateXML = XElement.Load(templateXMLFile);

            BitmapFrame icon = null;

            if (TemplateXML.Element("icon") != null && TemplateXML.Element("icon").Attribute("file") != null)
            {
                var iconFile = Path.Combine(Path.GetDirectoryName(templateFile), TemplateXML.Element("icon").Attribute("file").Value);
                if (iconFile == null || !File.Exists(iconFile))
                {
                    iconFile = Path.Combine(Path.GetDirectoryName(templateFile), Path.GetFileNameWithoutExtension(templateFile) + ".png");
                }
                if (File.Exists(iconFile))
                {
                    try
                    {
                        icon = BitmapFrame.Create(new BitmapImage(new Uri(iconFile)));
                        Icon = iconFile;
                    }
                    catch (Exception)
                    {
                        icon = null;
                        Icon = "";
                    }
                }
            }

            var authorElement = XMLHelper.FindLocalizedChildElement(TemplateXML, "author");

            if (authorElement != null)
            {
                AuthorName = authorElement.Value;
            }

            var relevantPlugins = TemplateXML.Element("relevantPlugins");

            if (relevantPlugins != null)
            {
                RelevantPlugins = new List <string>();
                foreach (var plugin in relevantPlugins.Elements("plugin"))
                {
                    var name = plugin.Attribute("name");
                    if (name != null)
                    {
                        RelevantPlugins.Add(name.Value);
                    }
                }
            }

            foreach (var title in TemplateXML.Elements("title"))
            {
                var langAtt = title.Attribute("lang");
                if (langAtt != null && !AvailableLanguages.Contains(langAtt.Value))
                {
                    Localizations.Add(langAtt.Value, new LocalizedTemplateDocumentationPage(this, langAtt.Value, icon));
                }
            }
            if (!Localizations.ContainsKey("en"))
            {
                throw new Exception("Documentation should at least support english language!");
            }
        }