示例#1
0
 public List <ErrorSpan?> TestBundleErrorsSpan(string input)
 {
     var(_, error) = LinguiniBuilder.Builder().Locale("en-US")
                     .AddResource(input)
                     .Build();
     return(error.Select(e => e.GetSpan()).ToList());
 }
示例#2
0
        public void TestExceptions()
        {
            var bundler = LinguiniBuilder.Builder()
                          .Locales("en-US", "sr-RS")
                          .AddResources(_wrong, _res1)
                          .SetUseIsolating(false)
                          .SetFormatterFunc(_formatter)
                          .SetTransformFunc(_transform)
                          .AddFunction("id", _idFunc)
                          .AddFunction("zero", _zeroFunc);

            Assert.Throws(typeof(LinguiniException), () => bundler.UncheckedBuild());
        }
示例#3
0
        public void TestEscapeFunction()
        {
            var bundle = LinguiniBuilder.Builder()
                         .Locale("en-US")
                         .AddResource(_testEscapeFunc)
                         .AddFunction("ID", _idFunc)
                         .UncheckedBuild();
            const string expected = @"hh\:mm";

            Assert.AreEqual(expected, bundle.GetAttrMessage("x0"));
            Assert.AreEqual(expected, bundle.GetAttrMessage("x1"));
            Assert.AreEqual(expected, bundle.GetAttrMessage("x2"));
            Assert.AreEqual(expected, bundle.GetAttrMessage("x3"));
        }
示例#4
0
        public void TestConcurrencyBundler()
        {
            var bundler = LinguiniBuilder.Builder()
                          .CultureInfo(new CultureInfo("en-US"))
                          .SkipResources()
                          .UseConcurrent()
                          .UncheckedBuild();

            Parallel.For(0, 10, i => bundler.AddResource($"term-1 = {i}", out _));
            Parallel.For(0, 10, i => bundler.AddResource($"term-2= {i}", out _));
            Parallel.For(0, 10, i => bundler.TryGetAttrMsg("term-1", null, out _, out _));
            Parallel.For(0, 10, i => bundler.AddResourceOverriding($"term-2= {i + 1}"));
            Assert.True(bundler.HasMessage("term-1"));
        }
示例#5
0
        public void TestEnumeration()
        {
            var bundler = LinguiniBuilder.Builder()
                          .Locale("en-US")
                          .AddResource(_multi)
                          .AddFunction("id", _idFunc)
                          .AddFunction("zero", _zeroFunc)
                          .UncheckedBuild();
            var messages  = bundler.GetMessageEnumerable().ToArray();
            var functions = bundler.GetFuncEnumerable().ToArray();

            CollectionAssert.AreEquivalent(new[] { "term1", "term2" }, messages);
            CollectionAssert.AreEquivalent(new[] { "id", "zero" }, functions);
        }
示例#6
0
        public void TestExample()
        {
            var bundler = LinguiniBuilder.Builder()
                          .CultureInfo(new CultureInfo("en"))
                          .AddResource("hello-user =  Hello, { $username }!")
                          .SetUseIsolating(false)
                          .UncheckedBuild();

            var props = new Dictionary <string, IFluentType>()
            {
                { "username", (FluentString)"Test" }
            };

            var message = bundler.GetAttrMessage("hello-user", props);

            Assert.AreEqual("Hello, Test!", message);
        }
示例#7
0
        public void TestReplaceMessage()
        {
            var bundler = LinguiniBuilder.Builder()
                          .CultureInfo(new CultureInfo("en"))
                          .AddResource(_replace1)
                          .SetUseIsolating(false);

            var bundle = bundler.UncheckedBuild();

            Assert.IsTrue(bundle.TryGetAttrMsg("term1", null, out _, out var termMsg));
            Assert.AreEqual("val1", termMsg);
            Assert.IsTrue(bundle.TryGetAttrMsg("term2", null, out _, out var termMsg2));
            Assert.AreEqual("val2", termMsg2);

            bundle.AddResourceOverriding(_replace2);
            Assert.IsTrue(bundle.TryGetAttrMsg("term2", null, out _, out _));
            Assert.IsTrue(bundle.TryGetAttrMsg("term1", null, out _, out termMsg));
            Assert.AreEqual("xxx", termMsg);
            Assert.IsTrue(bundle.TryGetAttrMsg("new1.attr", null, out _, out var newMsg));
            Assert.AreEqual("6", newMsg);
        }