public List <LocalizationViewModel> GetAll(string columnName, string searchString, Guid countryId)
        {
            List <Localization> entities;

            switch (columnName.ToLower())
            {
            case "localizationkey":
                entities = _repository.GetByLocalizationKey(searchString, countryId);
                break;

            case "localizationvalue":
                entities = _repository.GetByLocalizationValue(searchString, countryId);
                break;

            default:
                entities = _repository.GetAll(countryId);
                break;
            }

            if (entities == null)
            {
                throw new Exception(LOCALIZATION_LOCALIZATIONCLASS_NOT_FOUND);
            }

            return(LocalizationMapper.MapToLocalizationViewModel(entities));
        }
Beispiel #2
0
        public void LocalisationsCanBeLoadedAndMatched()
        {
            var reader1 = new BufferedReader(
                "l_english:\n" +
                " key1:0 \"value 1\" # comment\n" +
                " key2:0 \"value \"subquoted\" 2\"\n"
                );
            var reader2 = new BufferedReader(
                "l_french:\n" +
                " key1:0 \"valuee 1\"\n" +
                " key2:0 \"valuee \"subquoted\" 2\"\n"
                );
            var reader3 = new BufferedReader(
                "l_english:\n" +
                " key1:0 \"replaced value 1\"\n"
                );

            var locs = new LocalizationMapper();

            locs.ScrapeStream(reader1, "english");
            locs.ScrapeStream(reader2, "french");
            locs.ScrapeStream(reader3, "english");

            Assert.Equal("replaced value 1", locs.GetLocBlockForKey("key1").english);
            Assert.Equal("value \"subquoted\" 2", locs.GetLocBlockForKey("key2").english);
            Assert.Equal("valuee 1", locs.GetLocBlockForKey("key1").french);
            Assert.Equal("valuee \"subquoted\" 2", locs.GetLocBlockForKey("key2").french);
        }
        public void NameLocBlockDefaultsToNullopt()
        {
            var reader      = new BufferedReader(string.Empty);
            var countryName = ImperatorToCK3.Imperator.Countries.CountryName.Parse(reader);

            var locMapper = new LocalizationMapper();

            Assert.Null(countryName.GetNameLocBlock(locMapper, new()));
        }
Beispiel #4
0
        public void LocUnseparatedFromKeyIsIgnored()
        {
            var reader = new BufferedReader(
                "l_english:\n" +
                " key1 \"loc\""
                );
            var locMapper = new LocalizationMapper();

            locMapper.ScrapeStream(reader, "english");
            Assert.Null(locMapper.GetLocBlockForKey("key1"));
        }
Beispiel #5
0
        public void UnquotedLocIsIgnored()
        {
            var reader = new BufferedReader(
                "l_english:\n" +
                " key1:0 unqotedValue"
                );
            var locMapper = new LocalizationMapper();

            locMapper.ScrapeStream(reader, "english");
            Assert.Null(locMapper.GetLocBlockForKey("key1"));
        }
        public LocalizationViewModel GetLocalizationAsViewModel(Guid localizationId)
        {
            var entity = _repository.Get(localizationId);

            if (entity == null)
            {
                throw new Exception(LOCALIZATION_LOCALIZATIONCLASS_NOT_FOUND);
            }

            return(LocalizationMapper.MapToLocalizationViewModel(entity));
        }
Beispiel #7
0
        public void CommentLinesAreIgnored()
        {
            var reader = new BufferedReader(
                "l_english:\n" +
                "#key1: \"loc\""
                );
            var locMapper = new LocalizationMapper();

            locMapper.ScrapeStream(reader, "english");
            Assert.Null(locMapper.GetLocBlockForKey("key1"));
        }
Beispiel #8
0
        public void LocalisationsReturnsEnglishForMissingLanguage()
        {
            var locs   = new LocalizationMapper();
            var reader = new BufferedReader(
                "l_english:\n" +
                " key1:1 \"value 1\" # comment\n"
                );

            locs.ScrapeStream(reader, "english");

            Assert.Equal("value 1", ((LocBlock)locs.GetLocBlockForKey("key1")).french);
        }
Beispiel #9
0
        private void LocalizeView(object view)
        {
            var mapper = new LocalizationMapper {
                Current = LocalizationPackage
            };

            mapper.Localize(view);

            var localizable = view as ILocalizableView;

            localizable?.ApplyLocale();
        }
Beispiel #10
0
        public Dynasty(Family imperatorFamily, LocalizationMapper localizationMapper)
        {
            ID   = "dynn_IMPTOCK3_" + imperatorFamily.ID.ToString();
            Name = ID;

            var imperatorMembers = imperatorFamily.Members;

            if (imperatorMembers.Count > 0)
            {
                Imperator.Characters.Character?firstMember = imperatorMembers[0] as Imperator.Characters.Character;
                if (firstMember?.CK3Character is not null)
                {
                    Culture = firstMember.CK3Character.Culture;                     // make head's culture the dynasty culture
                }
            }
            else
            {
                Logger.Warn($"Couldn't determine culture for dynasty {ID}, needs manual setting!");
            }

            foreach (var member in imperatorMembers.Values)
            {
                var ck3Member = (member as Imperator.Characters.Character).CK3Character;
                if (ck3Member is not null)
                {
                    ck3Member.DynastyID = ID;
                }
            }

            var impFamilyLocKey = imperatorFamily.Key;
            var impFamilyLoc    = localizationMapper.GetLocBlockForKey(impFamilyLocKey);

            if (impFamilyLoc is not null)
            {
                Localization = new(Name, impFamilyLoc);
            }
            else                 // fallback: use unlocalized Imperator family key
            {
                Localization = new(Name, new LocBlock {
                    english = impFamilyLocKey,
                    french = impFamilyLocKey,
                    german = impFamilyLocKey,
                    russian = impFamilyLocKey,
                    simp_chinese = impFamilyLocKey,
                    spanish = impFamilyLocKey
                });
            }
        }
        public void AdjLocBlockReturnsCorrectLocForRevolts()
        {
            var reader = new BufferedReader(
                "adjective = CIVILWAR_FACTION_ADJECTIVE \n base = { name = someName adjective = someAdjective }"
                );
            var countryName = ImperatorToCK3.Imperator.Countries.CountryName.Parse(reader);

            var locMapper = new LocalizationMapper();

            locMapper.AddLocalization("CIVILWAR_FACTION_ADJECTIVE", new LocBlock {
                english = "$ADJ$"
            });
            locMapper.AddLocalization("someAdjective", new LocBlock {
                english = "Roman"
            });
            Assert.Equal("Roman", countryName.GetAdjectiveLocBlock(locMapper, new()).english);
        }
Beispiel #12
0
        public void LocalizationCanBeAddedForKey()
        {
            var localizationMapper = new LocalizationMapper();

            Assert.Null(localizationMapper.GetLocBlockForKey("key1"));
            localizationMapper.AddLocalization("key1", new LocBlock {
                english = "Roman",
                french  = "Romain"
            });

            var locBlock = localizationMapper.GetLocBlockForKey("key1");

            Assert.Equal("Roman", locBlock.english);
            Assert.Equal("Romain", locBlock.french);
            Assert.Equal("Roman", locBlock.german);
            Assert.Equal("Roman", locBlock.russian);
            Assert.Equal("Roman", locBlock.simp_chinese);
            Assert.Equal("Roman", locBlock.spanish);
        }
Beispiel #13
0
        public LocBlock?GetAdjectiveLocBlock(LocalizationMapper localizationMapper, Dictionary <ulong, Country> imperatorCountries)
        {
            var adj = GetAdjective();
            var directAdjLocMatch = localizationMapper.GetLocBlockForKey(adj);

            if (directAdjLocMatch is not null && adj == "CIVILWAR_FACTION_ADJECTIVE")
            {
                // special case for revolts
                if (BaseName is not null)
                {
                    var baseAdjLoc = BaseName.GetAdjectiveLocBlock(localizationMapper, imperatorCountries);
                    if (baseAdjLoc is not null)
                    {
                        directAdjLocMatch.ModifyForEveryLanguage(baseAdjLoc, (ref string orig, string modifying) =>
                                                                 orig = orig.Replace("$ADJ$", modifying)
                                                                 );
                        return(directAdjLocMatch);
                    }
                }
            }
Beispiel #14
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!");
            }
        }
Beispiel #15
0
        public void LocalisationsReturnNullForMissingKey()
        {
            var locs = new LocalizationMapper();

            Assert.Null(locs.GetLocBlockForKey("key1"));
        }
 public LocalizationCrudFactory() : base()
 {
     mapper = new LocalizationMapper();
     dao    = SqlDao.GetInstance();
 }
Beispiel #17
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);
        }