コード例 #1
0
        public void ProvideTranslationFromHighlyPrioritizedSource()
        {
            var inMemorySource = new InMemorySource();

            inMemorySource.SaveString("greeting", enCulture, "Hello from memory!");
            CreateFileWithTranslations(localizationsFilePath, new []
            {
                new LocalFileSource.StringTranslationRecord
                {
                    TextCode    = "greeting",
                    CultureId   = enCulture.LCID,
                    Translation = "Hello from file!"
                }
            });
            var localFileSource     = new LocalFileSource(localizationsFilePath);
            var sourcesList         = new LocalizationSourcesList();
            var localizationFactory = new LocalizationFactory(sourcesList);

            localizationFactory.RegisterSource(inMemorySource, 0);
            localizationFactory.RegisterSource(localFileSource, 1);

            var code             = new LocalizationCode("greeting");
            var translatedString = localizationFactory.GetString(code);

            Assert.AreEqual("Hello from file!", translatedString);
        }
コード例 #2
0
        public void ProvideTranslationFromSpecificSource()
        {
            var inMemorySource = new InMemorySource();

            inMemorySource.SaveString("greeting", enCulture, "Hello world!");
            var sourcesList         = new LocalizationSourcesList();
            var localizationFactory = new LocalizationFactory(sourcesList);

            localizationFactory.RegisterSource(inMemorySource, 0);

            var code             = new LocalizationCode("greeting", LocalizationSourceType.InMemory);
            var translatedString = localizationFactory.GetString(code, enCulture);

            Assert.AreEqual("Hello world!", translatedString);
        }
コード例 #3
0
        public void ProvideCorrectTranslation_WhenSeveralTranslationsExist()
        {
            var inMemorySource = new InMemorySource();

            inMemorySource.SaveString("greeting", enCulture, "Hello world!");
            inMemorySource.SaveString("greeting", ruCulture, "Привет мир!");
            var sourcesList         = new LocalizationSourcesList();
            var localizationFactory = new LocalizationFactory(sourcesList);

            localizationFactory.RegisterSource(inMemorySource, 0);

            var code             = new LocalizationCode("greeting", LocalizationSourceType.InMemory);
            var translatedString = localizationFactory.GetString(code, ruCulture);

            Assert.AreEqual("Привет мир!", translatedString);
        }