IdentityServer3
IdentityServer3 copied to clipboard
Support for localization of strings in HTML templates
Consider adding support for localization of HTML templates.
Currently, strings like "Username", "Password", "Local Login", etc are hard coded inside of HTML templates. Only way to add translations
<div class="form-group">
<label for="username">Username</label>
<input required ... placeholder="Username" ...>
</div>
Can placeholders be added and fed from Resource file(s)? Something like:
<div class="form-group">
<label for="username">{resources.Username}</label>
<input required ... placeholder="{resources.Username}" ...>
</div>
...so that we don't have to override HTML templates for translations only?
+1 for that. The only reason we override the viewservice is to add localization
In the CustomViewService class, LoadHtmlMethod : you can add your code for localization like this : private string LoadHtml(string name) { SetCulture(); var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"content\app"); if (System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToLower() == "tr") { file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"content\app\tr"); } file = Path.Combine(file, name + ".html"); return File.ReadAllText(file); }
private void SetCulture()
{
string langName = "tr-TR";
if (HttpContext.Current.Request.Cookies["ln"] == null)
{
if (HttpContext.Current.Request.UserLanguages != null &&
HttpContext.Current.Request.UserLanguages.Length != 0)
{
langName = HttpContext.Current.Request.UserLanguages[0].Substring(0, 2);
}
HttpContext.Current.Response.Cookies.Add(new HttpCookie("ln", langName));
}
else
{
langName = HttpContext.Current.Request.Cookies["ln"].Value;
}
CultureInfo ci = new CultureInfo(langName);
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
}
Do not forget Global.asax
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
string langName = "tr-TR";
if (HttpContext.Current.Request.Cookies["ln"] == null)
{
if (HttpContext.Current.Request.UserLanguages != null &&
HttpContext.Current.Request.UserLanguages.Length != 0)
{
langName = HttpContext.Current.Request.UserLanguages[0].Substring(0, 2);
}
HttpContext.Current.Response.Cookies.Add(new HttpCookie("ln", langName));
}
else
{
langName = HttpContext.Current.Request.Cookies["ln"].Value;
}
CultureInfo ci = new CultureInfo(langName);
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
}
in the Content/app folder add a new folder like "tr" for turkish for example and take your localized views there