Exemplo n.º 1
0
        public void TranslateFormatTest()
        {
            var localizationConfiguration = new LocalizationConfiguration
            {
                BasePath          = "Localization",
                DefaultCulture    = new CultureInfo("cs"),
                SupportedCultures = new List <CultureInfo>
                {
                    new CultureInfo("en"),
                    new CultureInfo("es"),
                },
                TranslateFallbackMode = LocTranslateFallbackMode.Key,
                AutoLoadResources     = true,
            };

            var dictionaryManager = new FileDictionaryManager(localizationConfiguration, JsonDictionaryFactory.FactoryInstance);

            var fallbackCultureResolver = new FallbackCultureResolver(localizationConfiguration);
            var fileLocalizationManager = new FileLocalizationManager(
                localizationConfiguration, dictionaryManager, fallbackCultureResolver
                );

            var ls = fileLocalizationManager.TranslateFormat(localizationConfiguration.DefaultCulture, "global", "klíč-stringu", new object[] { "pondělí" });

            Assert.AreEqual("Dnes je pondělí.", ls.Value);
        }
Exemplo n.º 2
0
        public void TranslateConstant()
        {
            var localizationConfiguration = new LocalizationConfiguration
            {
                BasePath          = "LocalizationTree",
                DefaultCulture    = new CultureInfo("cs"),
                SupportedCultures = new List <CultureInfo>
                {
                    new CultureInfo("en")
                },
                TranslateFallbackMode = LocTranslateFallbackMode.Key,
                AutoLoadResources     = true,
            };

            var dictionaryManager = new FileDictionaryManager(localizationConfiguration, JsonDictionaryFactory.FactoryInstance);

            var fallbackCultureResolver = new FallbackCultureResolver(localizationConfiguration);
            var fileLocalizationManager = new FileLocalizationManager(
                localizationConfiguration, dictionaryManager, fallbackCultureResolver
                );

            var ls = fileLocalizationManager.TranslateConstant(new CultureInfo("cs"), null, "const-date");

            Assert.AreEqual("MMMM dd, yyyy", ls.Value);
            Assert.IsFalse(ls.ResourceNotFound);
        }
Exemplo n.º 3
0
        public void TranslateFormatTest()
        {
            var localizationConfiguration = new LocalizationConfiguration
            {
                BasePath          = "Localization",
                DefaultCulture    = new CultureInfo("cs"),
                SupportedCultures = new List <CultureInfo>
                {
                    new CultureInfo("cs-CZ"),
                    new CultureInfo("en"),
                    new CultureInfo("en-US"),
                    new CultureInfo("es"),
                },
                TranslateFallbackMode = LocTranslateFallbackMode.Key
            };

            var fallbackCultureResolver = new FallbackCultureResolver(localizationConfiguration);

            var cultureCs   = new CultureInfo("cs");
            var cultureCsCz = new CultureInfo("cs-CZ");
            var cultureEn   = new CultureInfo("en");
            var cultureEnUs = new CultureInfo("en-US");
            var cultureEs   = new CultureInfo("es");
            var cultureDe   = new CultureInfo("de");

            Assert.IsNull(fallbackCultureResolver.FallbackCulture(cultureCs));
            Assert.AreEqual(cultureCs, fallbackCultureResolver.FallbackCulture(cultureCsCz));
            Assert.AreEqual(cultureCs, fallbackCultureResolver.FallbackCulture(cultureEn));
            Assert.AreEqual(cultureEn, fallbackCultureResolver.FallbackCulture(cultureEnUs));
            Assert.AreEqual(cultureCs, fallbackCultureResolver.FallbackCulture(cultureEs));
            Assert.IsNull(fallbackCultureResolver.FallbackCulture(cultureDe));
        }
 public FileLocalizationManager(
     LocalizationConfiguration configuration,
     IFileDictionaryManager fileDictionaryManager,
     FallbackCultureResolver fallbackCultureResolver
     ) : base(configuration)
 {
     m_dictionaryManager       = fileDictionaryManager;
     m_fallbackCultureResolver = fallbackCultureResolver;
 }
Exemplo n.º 5
0
 public DatabaseTranslateService(
     FallbackCultureResolver fallbackCultureResolver,
     CultureHierarchyUoW cultureHierarchyUoW,
     StaticTextUoW staticTextUoW,
     LocalizationConfiguration configuration,
     CultureUoW cultureUoW,
     DictionaryScopeUoW dictionaryScopeUoW,
     ILogger <DatabaseTranslateService> logger,
     IMemoryCache memoryCache
     ) : base(configuration, cultureUoW, dictionaryScopeUoW, logger, memoryCache)
 {
     m_fallbackCultureResolver = fallbackCultureResolver;
     m_cultureHierarchyUoW     = cultureHierarchyUoW;
     m_staticTextUoW           = staticTextUoW;
 }
        public void Init()
        {
            var localizationConfiguration = new LocalizationConfiguration
            {
                BasePath          = "Localization",
                DefaultCulture    = new CultureInfo("cs"),
                SupportedCultures = new List <CultureInfo>
                {
                    new CultureInfo("en"),
                    new CultureInfo("cs"),
                },
                TranslateFallbackMode = LocTranslateFallbackMode.Key
            };

            m_dictionaryManager = new FileDictionaryManager(localizationConfiguration, JsonDictionaryFactory.FactoryInstance);

            var fallbackCultureResolver = new FallbackCultureResolver(localizationConfiguration);

            m_fileLocalizationManager = new FileLocalizationManager(
                localizationConfiguration, m_dictionaryManager, fallbackCultureResolver
                );
        }
Exemplo n.º 7
0
        public void TreeTest()
        {
            var localizationConfiguration = new LocalizationConfiguration
            {
                BasePath          = "LocalizationTree",
                DefaultCulture    = new CultureInfo("cs"),
                SupportedCultures = new List <CultureInfo>
                {
                    new CultureInfo("en"),
                    new CultureInfo("en-US"),
                    new CultureInfo("en-GB"),
                    new CultureInfo("en-CA"),
                    new CultureInfo("es-MX"),
                    new CultureInfo("es-US"),
                },
                TranslateFallbackMode = LocTranslateFallbackMode.Key,
                AutoLoadResources     = true
            };

            var dictionaryManager = new FileDictionaryManager(
                localizationConfiguration, JsonDictionaryFactory.FactoryInstance
                );

            var fallbackCultureResolver = new FallbackCultureResolver(localizationConfiguration);
            var fileLocalizationManager = new FileLocalizationManager(
                localizationConfiguration, dictionaryManager, fallbackCultureResolver
                );

            var s1 = fileLocalizationManager.Translate("text-1-odst", new CultureInfo("cs"));

            Assert.AreEqual("global cs [text-1-odst]", s1);

            var s2 = fileLocalizationManager.Translate("extra-cs-key", new CultureInfo("en-MX"));

            Assert.AreEqual("extra string in CS culture", s2);

            var s3 = fileLocalizationManager.Translate("extra-cs-key", new CultureInfo("es-MX"));

            Assert.AreEqual("extra string in CS culture", s3);

            const string nopeKey = "nope-key";
            var          sNope   = fileLocalizationManager.Translate(nopeKey, new CultureInfo("es-MX"));

            Assert.AreEqual(nopeKey, sNope);

            localizationConfiguration.TranslateFallbackMode = LocTranslateFallbackMode.EmptyString;

            var sNope2 = fileLocalizationManager.Translate(nopeKey, new CultureInfo("es-MX"));

            Assert.AreEqual("", sNope2);

            localizationConfiguration.TranslateFallbackMode = LocTranslateFallbackMode.Exception;

            var exceptionThrown = false;

            try
            {
                var sNope3 = fileLocalizationManager.Translate(nopeKey, new CultureInfo("es-MX"));
            }
            catch (TranslateException)
            {
                exceptionThrown = true;
            }

            Assert.IsTrue(exceptionThrown);
        }