public void HtmlLocalizerOfTTest_UseIndexerWithArguments_ReturnsLocalizedHtmlString()
        {
            // Arrange
            var applicationEnvironment = new Mock <IApplicationEnvironment>();

            applicationEnvironment.Setup(a => a.ApplicationName).Returns("TestApplication");

            var localizedString = new LocalizedHtmlString("Hello", "Bonjour test");

            var htmlLocalizer = new Mock <IHtmlLocalizer>();

            htmlLocalizer.Setup(h => h["Hello", "test"]).Returns(localizedString);

            var htmlLocalizerFactory = new Mock <IHtmlLocalizerFactory>();

            htmlLocalizerFactory.Setup(h => h.Create(typeof(TestClass)))
            .Returns(htmlLocalizer.Object);

            var htmlLocalizerOfT = new HtmlLocalizer <TestClass>(htmlLocalizerFactory.Object);

            // Act
            var actualLocalizedString = htmlLocalizerOfT["Hello", "test"];

            // Assert
            Assert.Equal(localizedString, actualLocalizedString);
        }
        public void ViewLocalizer_UseIndexerWithArguments_ReturnsLocalizedHtmlString()
        {
            // Arrange
            var hostingEnvironment = new Mock <IHostingEnvironment>();

            hostingEnvironment.Setup(a => a.ApplicationName).Returns("TestApplication");

            var localizedString = new LocalizedHtmlString("Hello", "Bonjour test");

            var htmlLocalizer = new Mock <IHtmlLocalizer>();

            htmlLocalizer.Setup(h => h["Hello", "test"]).Returns(localizedString);

            var htmlLocalizerFactory = new Mock <IHtmlLocalizerFactory>();

            htmlLocalizerFactory.Setup(
                h => h.Create("TestApplication.example", "TestApplication")).Returns(htmlLocalizer.Object);

            var viewLocalizer = new ViewLocalizer(htmlLocalizerFactory.Object, hostingEnvironment.Object);

            var view = new Mock <IView>();

            view.Setup(v => v.Path).Returns("example");
            var viewContext = new ViewContext();

            viewContext.View = view.Object;

            viewLocalizer.Contextualize(viewContext);

            // Act
            var actualLocalizedString = viewLocalizer["Hello", "test"];

            // Assert
            Assert.Equal(localizedString, actualLocalizedString);
        }
Esempio n. 3
0
 public void Add(NotifyType type, LocalizedHtmlString message)
 {
     Logger.LogInformation("Notification {0} message: {1}", type, message);
     _entries.Add(new NotifyEntry {
         Type = type, Message = message
     });
 }
Esempio n. 4
0
        public void ViewLocalizer_UseIndexer_ReturnsLocalizedHtmlString()
        {
            // Arrange
            var applicationEnvironment = new Mock<IApplicationEnvironment>();
            applicationEnvironment.Setup(a => a.ApplicationName).Returns("TestApplication");

            var localizedString = new LocalizedHtmlString("Hello", "Bonjour");

            var htmlLocalizer = new Mock<IHtmlLocalizer>();
            htmlLocalizer.Setup(h => h["Hello"]).Returns(localizedString);

            var htmlLocalizerFactory = new Mock<IHtmlLocalizerFactory>();
            htmlLocalizerFactory.Setup(h => h.Create("TestApplication.example", "TestApplication"))
                .Returns(htmlLocalizer.Object);

            var viewLocalizer = new ViewLocalizer(htmlLocalizerFactory.Object, applicationEnvironment.Object);

            var view = new Mock<IView>();
            view.Setup(v => v.Path).Returns("example");
            var viewContext = new ViewContext();
            viewContext.View = view.Object;

            viewLocalizer.Contextualize(viewContext);

            // Act
            var actualLocalizedString = viewLocalizer["Hello"];

            // Assert
            Assert.Equal(localizedString, actualLocalizedString);
        }
Esempio n. 5
0
        public void Add(NotifyType type, LocalizedHtmlString message)
        {
            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Notification '{NotificationType}' with message '{NotificationMessage}'", type, message);
            }

            _entries.Add(new NotifyEntry {
                Type = type, Message = message
            });
        }
        public static HtmlString ImageFor(this IHtmlHelper helper, string src, LocalizedHtmlString alt)
        {
            var tagBuilder = new TagBuilder("img");
            var path       = "/" + src;

            tagBuilder.TagRenderMode = TagRenderMode.SelfClosing;
            tagBuilder.Attributes.Add("src", path);
            tagBuilder.Attributes.Add("alt", alt.Value);
            using var writer = new System.IO.StringWriter();
            tagBuilder.WriteTo(writer, HtmlEncoder.Default);
            return(new HtmlString(writer.ToString()));
        }
        public static Func <int, LocalizedHtmlString> GetTextPartsFunction(this LocalizedHtmlString localizedHtmlString, params string[] splitTokens)
        {
            var originalTextParts  = localizedHtmlString.Name.Split(splitTokens, StringSplitOptions.None).ToList();
            var localizedTextParts = localizedHtmlString.Value.Split(splitTokens, StringSplitOptions.None).ToList();

            LocalizedHtmlString funcLocalizedParts(int i) =>
            i < originalTextParts.Count && i < localizedTextParts.Count
                    ? new LocalizedHtmlString(originalTextParts.ElementAt(i), localizedTextParts.ElementAt(i))
                    : new LocalizedHtmlString($"Index_{i}_OutOfRange", string.Empty);

            return(funcLocalizedParts);
        }
Esempio n. 8
0
 public SettingHtmlInfo(SettingDefinition settingDefinition,
                        LocalizedHtmlString displayName, LocalizedHtmlString description,
                        string value)
 {
     Name              = settingDefinition.Name;
     DisplayName       = displayName;
     Description       = description;
     Value             = value;
     Group1            = (string)settingDefinition.Properties[AbpSettingManagementMvcUIConst.Group1];
     Group2            = (string)settingDefinition.Properties[AbpSettingManagementMvcUIConst.Group2];
     FormName          = AbpSettingManagementMvcUIConst.FormNamePrefix + Name.DotToUnderscore();
     Type              = (string)settingDefinition.Properties[AbpSettingManagementMvcUIConst.Type];
     SettingDefinition = settingDefinition;
 }
Esempio n. 9
0
        /// <summary>
        /// Localize a string according to specified culture
        /// <para>Use in UI side, for backend text localization use GetLocalizedString instead</para>
        /// </summary>
        /// <param name="culture"></param>
        /// <param name="key"></param>
        /// <param name="args"></param>
        /// <returns>LocalizedHtmlString</returns>
        public LocalizedHtmlString GetLocalizedHtmlString(string culture, string key, params object[] args)
        {
            var curCul   = CultureInfo.CurrentCulture;
            var curUiCul = CultureInfo.CurrentUICulture;

            CultureInfo.CurrentCulture   = new CultureInfo(culture);
            CultureInfo.CurrentUICulture = new CultureInfo(culture);

            LocalizedHtmlString result = args == null ? _localizer[key] : _localizer[key, args];

            CultureInfo.CurrentCulture   = curCul;
            CultureInfo.CurrentUICulture = curUiCul;
            return(result);
            //return args == null
            //	? _localizer.WithCulture(CultureInfo.GetCultureInfo(culture))[key]
            //	: _localizer.WithCulture(CultureInfo.GetCultureInfo(culture))[key, args];
        }
Esempio n. 10
0
        public void HtmlLocalizerOfTTest_UseIndexer_ReturnsLocalizedHtmlString()
        {
            // Arrange
            var localizedString = new LocalizedHtmlString("Hello", "Bonjour");

            var htmlLocalizer = new Mock<IHtmlLocalizer>();
            htmlLocalizer.Setup(h => h["Hello"]).Returns(localizedString);

            var htmlLocalizerFactory = new Mock<IHtmlLocalizerFactory>();
            htmlLocalizerFactory.Setup(h => h.Create(typeof(TestClass)))
                .Returns(htmlLocalizer.Object);

            var htmlLocalizerOfT = new HtmlLocalizer<TestClass>(htmlLocalizerFactory.Object);

            // Act
            var actualLocalizedString = htmlLocalizerOfT["Hello"];

            // Assert
            Assert.Equal(localizedString, actualLocalizedString);
        }
Esempio n. 11
0
        public Task <IViewComponentResult> InvokeAsync(
            string id,
            string value,
            LocalizedHtmlString placeHolderText,
            string htmlName,
            bool autoFocus,
            int rows)
        {
            var model = new EditorViewModel
            {
                Id              = id,
                HtmlName        = htmlName,
                PlaceHolderText = placeHolderText?.Value ?? string.Empty,
                Value           = value,
                AutoFocus       = autoFocus,
                Rows            = rows > 0 ? rows : 10
            };

            return(Task.FromResult((IViewComponentResult)View(model)));
        }
        public void HtmlLocalizerOfTTest_UseIndexer_ReturnsLocalizedHtmlString()
        {
            // Arrange
            var localizedString = new LocalizedHtmlString("Hello", "Bonjour");

            var htmlLocalizer = new Mock <IHtmlLocalizer>();

            htmlLocalizer.Setup(h => h["Hello"]).Returns(localizedString);

            var htmlLocalizerFactory = new Mock <IHtmlLocalizerFactory>();

            htmlLocalizerFactory.Setup(h => h.Create(typeof(TestClass)))
            .Returns(htmlLocalizer.Object);

            var htmlLocalizerOfT = new HtmlLocalizer <TestClass>(htmlLocalizerFactory.Object);

            // Act
            var actualLocalizedString = htmlLocalizerOfT["Hello"];

            // Assert
            Assert.Equal(localizedString, actualLocalizedString);
        }
        /// <summary>
        /// Localized Html String
        /// </summary>
        /// <param name="localizedString"></param>
        /// <param name="output"></param>
        private async void LocalizedHtmlOutput(TagHelperOutput output)
        {
            LocalizedHtmlString localizedString = Localizers[ResourceGroup][ResourceName];

            if (!localizedString.IsResourceNotFound)
            {
                if (!string.IsNullOrWhiteSpace(localizedString.Value))
                {
                    string value     = localizedString.Value;
                    string formatted = string.Format(value, Parameter0, Parameter1, Parameter2, Parameter3, Parameter4);

                    if (Display == DisplayType.Html)
                    {
                        output.Content.SetHtmlContent(formatted);
                    }
                    else
                    {
                        output.Content.SetContent(formatted);
                    }

                    return;
                }
            }

            // If resource is not found use the original content.
            TagHelperContent childContent = await output.GetChildContentAsync();

            string originalContent = childContent.GetContent();
            string reformatted     = string.Format(originalContent, Parameter0, Parameter1, Parameter2, Parameter3, Parameter4);

            if (Display == DisplayType.Html)
            {
                output.Content.SetHtmlContent(reformatted);
            }
            else
            {
                output.Content.SetContent(reformatted);
            }
        }
Esempio n. 14
0
        public void HtmlLocalizerOfTTest_UseIndexerWithArguments_ReturnsLocalizedHtmlString()
        {
            // Arrange
            var applicationEnvironment = new Mock<IApplicationEnvironment>();
            applicationEnvironment.Setup(a => a.ApplicationName).Returns("TestApplication");

            var localizedString = new LocalizedHtmlString("Hello", "Bonjour test");

            var htmlLocalizer = new Mock<IHtmlLocalizer>();
            htmlLocalizer.Setup(h => h["Hello", "test"]).Returns(localizedString);

            var htmlLocalizerFactory = new Mock<IHtmlLocalizerFactory>();
            htmlLocalizerFactory.Setup(h => h.Create(typeof(TestClass)))
                .Returns(htmlLocalizer.Object);

            var htmlLocalizerOfT = new HtmlLocalizer<TestClass>(htmlLocalizerFactory.Object);

            // Act
            var actualLocalizedString = htmlLocalizerOfT["Hello", "test"];

            // Assert
            Assert.Equal(localizedString, actualLocalizedString);
        }
Esempio n. 15
0
 public void Add(NotifyType type, LocalizedHtmlString message)
 {
     Logger.LogInformation("Notification {0} message: {1}", type, message);
     _entries.Add(new NotifyEntry { Type = type, Message = message });
 }
Esempio n. 16
0
 /// <summary>
 /// Adds a new UI notification of type Error
 /// </summary>
 /// <seealso cref="INotifier.Add()"/>
 /// <param name="message">A localized message to display</param>
 public static void Error(this INotifier notifier, LocalizedHtmlString message)
 {
     notifier.Add(NotifyType.Error, message);
 }
Esempio n. 17
0
 /// <summary>
 /// Adds a new UI notification of type Success
 /// </summary>
 /// <seealso cref="INotifier.Add()"/>
 /// <param name="message">A localized message to display</param>
 public static void Success(this INotifier notifier, LocalizedHtmlString message)
 {
     notifier.Add(NotifyType.Success, message);
 }
Esempio n. 18
0
 /// <summary>
 /// Adds a new UI notification of type Warning
 /// </summary>
 /// <seealso cref="INotifier.AddAsync"/>
 /// <param name="notifier">The <see cref="INotifier"/></param>
 /// <param name="message">A localized message to display</param>
 public static ValueTask WarningAsync(this INotifier notifier, LocalizedHtmlString message)
 => notifier.AddAsync(NotifyType.Warning, message);
Esempio n. 19
0
 /// <summary>
 /// Adds a new UI notification of type Information
 /// </summary>
 /// <seealso cref="INotifier.AddAsync"/>
 /// <param name="notifier">The <see cref="INotifier"/></param>
 /// <param name="message">A localized message to display</param>
 public static ValueTask InformationAsync(this INotifier notifier, LocalizedHtmlString message)
 => notifier.AddAsync(NotifyType.Information, message);
 public static IHtmlContent RouteLink(this IHtmlHelper html, LocalizedHtmlString text, string routeName, object routeValues, object htmlAttributes)
 {
     return(html.RouteLink(text.Value, routeName, routeValues, htmlAttributes));
 }
Esempio n. 21
0
 /// <summary>
 /// Adds a new UI notification of type Success
 /// </summary>
 /// <seealso cref="INotifier.AddAsync"/>
 /// <param name="notifier">The <see cref="INotifier"/></param>
 /// <param name="message">A localized message to display</param>
 public static ValueTask SuccessAsync(this INotifier notifier, LocalizedHtmlString message)
 => notifier.AddAsync(NotifyType.Success, message);
Esempio n. 22
0
 /// <summary>
 /// Adds a new UI notification of type Error
 /// </summary>
 /// <seealso cref="INotifier.AddAsync"/>
 /// <param name="notifier">The <see cref="INotifier"/></param>
 /// <param name="message">A localized message to display</param>
 public static ValueTask ErrorAsync(this INotifier notifier, LocalizedHtmlString message)
 => notifier.AddAsync(NotifyType.Error, message);
Esempio n. 23
0
 public static IHtmlContent ActionLink(this IHtmlHelper html, LocalizedHtmlString text, string actionName, string controllerName, string protocol, string hostName, string fragment, object routeValues, object htmlAttributes)
 {
     return(html.ActionLink(text.Value, actionName, controllerName, protocol, hostName, fragment, routeValues, htmlAttributes));
 }
Esempio n. 24
0
 public static IHtmlContent ActionLink(this IHtmlHelper html, LocalizedHtmlString text, string actionName, string controllerName, object routeValues)
 {
     return(html.ActionLink(text.Value, actionName, controllerName, routeValues));
 }
Esempio n. 25
0
 public static IHtmlContent ActionLink(this IHtmlHelper html, LocalizedHtmlString text, string actionName)
 {
     return(html.ActionLink(text.Value, actionName));
 }
Esempio n. 26
0
 public void AddTitleSegment(LocalizedHtmlString segment, int order = 0)
 {
     Title.AddSegment(new LocalizedString(segment.Name, segment.Value), order);
 }
Esempio n. 27
0
 public static void Information(this INotifier notifier, LocalizedHtmlString message)
 {
     notifier.Add(NotifyType.Information, message);
 }
Esempio n. 28
0
 public static void Success(this IAlerter alerter, LocalizedHtmlString message)
 {
     alerter.Add(AlertType.Success, message);
 }
Esempio n. 29
0
 public static void Warning(this INotifier notifier, LocalizedHtmlString message)
 {
     notifier.Add(NotifyType.Warning, message);
 }
Esempio n. 30
0
 /// <summary>
 /// Adds a new UI notification of type Information
 /// </summary>
 /// <seealso cref="INotifier.Add()"/>
 /// <param name="message">A localized message to display</param>
 public static void Information(this INotifier notifier, LocalizedHtmlString message)
 {
     notifier.Add(NotifyType.Information, message);
 }
Esempio n. 31
0
 public static void Error(this INotifier notifier, LocalizedHtmlString message)
 {
     notifier.Add(NotifyType.Error, message);
 }
Esempio n. 32
0
 /// <summary>
 /// Adds a new UI notification of type Warning
 /// </summary>
 /// <seealso cref="INotifier.Add()"/>
 /// <param name="message">A localized message to display</param>
 public static void Warning(this INotifier notifier, LocalizedHtmlString message)
 {
     notifier.Add(NotifyType.Warning, message);
 }
Esempio n. 33
0
 public static void Success(this INotifier notifier, LocalizedHtmlString message)
 {
     notifier.Add(NotifyType.Success, message);
 }
Esempio n. 34
0
 public static void Info(this IAlerter alerter, LocalizedHtmlString message)
 {
     alerter.Add(AlertType.Info, message);
 }
 public static IHtmlContent RouteLink(this IHtmlHelper html, LocalizedHtmlString text, string routeName)
 {
     return(html.RouteLink(text.Value, routeName));
 }
Esempio n. 36
0
 public static void Warning(this IAlerter alerter, LocalizedHtmlString message)
 {
     alerter.Add(AlertType.Warning, message);
 }
 public static IHtmlContent RouteLink(this IHtmlHelper html, LocalizedHtmlString text, string routeName, string protocol, string hostname, string fragment, object routeValues, object htmlAttributes)
 {
     return(html.RouteLink(text.Value, routeName, protocol, hostname, fragment, routeValues, htmlAttributes));
 }
Esempio n. 38
0
 public static void Danger(this IAlerter alerter, LocalizedHtmlString message)
 {
     alerter.Add(AlertType.Danger, message);
 }