1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

Added PreValidate endpoint on Account controller (#896)

* Added PreValidate endpoint on Account controller

* Fixed IHttpClientFactory implementation

* Core localization and org sproc fix

* Pass culture, fixed sso middleware bug
This commit is contained in:
Chad Scharf
2020-08-28 12:14:23 -04:00
committed by GitHub
parent 303b9a7875
commit db7d05b52f
15 changed files with 629 additions and 8 deletions

View File

@ -0,0 +1,38 @@
using System;
using System.Reflection;
using Bit.Core.Resources;
using Microsoft.Extensions.Localization;
namespace Bit.Core.Services
{
public class I18nService : II18nService
{
private readonly IStringLocalizer _localizer;
public I18nService(IStringLocalizerFactory factory)
{
var assemblyName = new AssemblyName(typeof(SharedResources).GetTypeInfo().Assembly.FullName);
_localizer = factory.Create("SharedResources", assemblyName.Name);
}
public LocalizedString GetLocalizedHtmlString(string key)
{
return _localizer[key];
}
public LocalizedString GetLocalizedHtmlString(string key, params object[] args)
{
return _localizer[key, args];
}
public string Translate(string key, params object[] args)
{
return string.Format(GetLocalizedHtmlString(key).ToString(), args);
}
public string T(string key, params object[] args)
{
return Translate(key, args);
}
}
}

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using Bit.Core.Resources;
using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.Extensions.Localization;
namespace Bit.Core.Services
{
public class I18nViewLocalizer : IViewLocalizer
{
private readonly IStringLocalizer _stringLocalizer;
private readonly IHtmlLocalizer _htmlLocalizer;
public I18nViewLocalizer(IStringLocalizerFactory stringFactory,
IHtmlLocalizerFactory htmlFactory)
{
var assemblyName = new AssemblyName(typeof(SharedResources).GetTypeInfo().Assembly.FullName);
_stringLocalizer = stringFactory.Create("SharedResources", assemblyName.Name);
_htmlLocalizer = htmlFactory.Create("SharedResources", assemblyName.Name);
}
public LocalizedHtmlString this[string name] => _htmlLocalizer[name];
public LocalizedHtmlString this[string name, params object[] args] => _htmlLocalizer[name, args];
public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures) =>
_stringLocalizer.GetAllStrings(includeParentCultures);
public LocalizedString GetString(string name) => _stringLocalizer[name];
public LocalizedString GetString(string name, params object[] arguments) =>
_stringLocalizer[name, arguments];
[Obsolete("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")]
public IHtmlLocalizer WithCulture(CultureInfo culture) => _htmlLocalizer.WithCulture(culture);
}
}