Mock implementation of ITextLocalizer with simplest of logic: · Supports single app language: "en" · GetText checks that the UserLanguage spec. matches "en" and if so simply wraps the msgid as follows: "xxxyyy". E.g. "Hello" -> "xxxHelloyyy". If no language match then returns null.
Inheritance: ITextLocalizer
        public void NuggetLocalizer_can_process_nugget_multiline()
        {
            ITextLocalizer textLocalizer = new TextLocalizer_Mock_PrefixSuffix("xxx", "yyy");

            i18n.NuggetLocalizer obj = new i18n.NuggetLocalizer(new i18nSettings(new WebConfigSettingService()), textLocalizer);

            string pre = "[[[1\r\n2]]] [[[\r\n3]]]";
            string post = obj.ProcessNuggets(pre, languages);
            Assert.AreEqual("xxx1\r\n2yyy xxx\r\n3yyy", post);
        }
        public void NuggetLocalizer_can_process_formatted_nugget_with_two_variables_firstempty_secondnonempty()
        {
            ITextLocalizer textLocalizer = new TextLocalizer_Mock_PrefixSuffix();

            i18n.NuggetLocalizer obj = new i18n.NuggetLocalizer(new i18nSettings(new WebConfigSettingService()), textLocalizer);

            string pre = "[[[Will occur %0 every %1 years||||||10///First variable is a month]]]";
                // Value for first variable is missing.
            string post = obj.ProcessNuggets(pre, languages);
            Assert.AreEqual("Will occur  every 10 years", post);
        }
Exemple #3
0
        public void NuggetLocalizer_can_process_nugget_multiline()
        {
            ITextLocalizer textLocalizer = new TextLocalizer_Mock_PrefixSuffix("xxx", "yyy");

            i18n.NuggetLocalizer obj = new i18n.NuggetLocalizer(new i18nSettings(new WebConfigSettingService()), textLocalizer);

            string pre  = "[[[1\r\n2]]] [[[\r\n3]]]";
            string post = obj.ProcessNuggets(pre, languages);

            Assert.AreEqual("xxx1\r\n2yyy xxx\r\n3yyy", post);
        }
Exemple #4
0
        public void NuggetLocalizer_can_process_formatted_nugget_with_two_variables_firstnonempty_secondempty()
        {
            ITextLocalizer textLocalizer = new TextLocalizer_Mock_PrefixSuffix();

            i18n.NuggetLocalizer obj = new i18n.NuggetLocalizer(new i18nSettings(new WebConfigSettingService()), textLocalizer);

            string pre = "[[[Will occur %0 every %1 years|||April|||///First variable is a month]]]";
            // Value for second variable is missing.
            string post = obj.ProcessNuggets(pre, languages);

            Assert.AreEqual("Will occur April every  years", post);
        }
Exemple #5
0
        public void NuggetLocalizer_can_translate_nested_nugget_hard()
        {
            ITextLocalizer textLocalizer = new TextLocalizer_Mock_PrefixSuffix("!", "!");

            i18n.NuggetLocalizer obj = new i18n.NuggetLocalizer(new i18nSettings(new WebConfigSettingService(null)), textLocalizer);

            string pre = "[[[Error %0. %1 (%2)|||03/04/2015|||((([[[Error Details]]])))|||Test]]]";
            // Value for second variable is missing.
            string post = obj.ProcessNuggets(pre, languages);

            Assert.AreEqual("!Error 03/04/2015. !Error Details! (Test)!", post);
        }
Exemple #6
0
        public void NuggetLocalizer_can_translate_nested_nugget()
        {
            ITextLocalizer textLocalizer = new TextLocalizer_Mock_PrefixSuffix("!", "!");

            i18n.NuggetLocalizer obj = new i18n.NuggetLocalizer(new i18nSettings(new WebConfigSettingService(null)), textLocalizer);

            string pre = "[[[%0 is required|||(((Some [[[Nested Nugget]]])))]]]";
            // Value for second variable is missing.
            string post = obj.ProcessNuggets(pre, languages);

            Assert.AreEqual("!Some !Nested Nugget! is required!", post);
        }
Exemple #7
0
        public void NuggetLocalizer_can_visualize_nugget()
        {
            ITextLocalizer textLocalizer = new TextLocalizer_Mock_PrefixSuffix("xxx", "yyy");
            var            settings      = new i18nSettings(new WebConfigSettingService())
            {
                VisualizeMessages = true
            };

            i18n.NuggetLocalizer obj = new i18n.NuggetLocalizer(settings, textLocalizer);

            string pre  = "[[[123]]] [[[456]]]";
            string post = obj.ProcessNuggets(pre, languages);

            Assert.AreEqual("!xxx123yyy! !xxx456yyy!", post);
        }
        public void NuggetLocalizer_can_visualize_nugget()
        {
            ITextLocalizer textLocalizer = new TextLocalizer_Mock_PrefixSuffix("xxx", "yyy");
            var settings = new i18nSettings(new WebConfigSettingService())
            {
                VisualizeMessages = true
            };

            i18n.NuggetLocalizer obj = new i18n.NuggetLocalizer(settings, textLocalizer);

            string pre = "[[[123]]] [[[456]]]";
            string post = obj.ProcessNuggets(pre, languages);
            Assert.AreEqual("!xxx123yyy! !xxx456yyy!", post);
        }
        public void NuggetLocalizer_can_translate_parameter()
        {
            ITextLocalizer textLocalizer = new TextLocalizer_Mock_PrefixSuffix("!", "!");
            i18n.NuggetLocalizer obj = new i18n.NuggetLocalizer(new i18nSettings(new WebConfigSettingService(null)), textLocalizer);

            string pre = "[[[%0 is required|||(((ZipCode)))]]]";
            // Value for second variable is missing.
            string post = obj.ProcessNuggets(pre, languages);
            Assert.AreEqual("!!ZipCode! is required!", post);
        }