Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DbResourceConfiguration.json
backup/
SqLiteLocalizations.db-*
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
using System.Globalization;
using System.Threading;
//using AppResources;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.Extensions.Localization;

namespace WestWind.Globalization.Sample.AspNetCore.Controllers
{
[Route("api/Localization")]
public class LocalizationController : Controller
{
private readonly IStringLocalizer _localizer;
private readonly IHtmlLocalizer _htmlLocalizer;

public LocalizationController(IStringLocalizer<LocalizationController> localizer,
IHtmlLocalizer<LocalizationController> htmlLocalizer)
{
_localizer = localizer;
_htmlLocalizer = htmlLocalizer;
}

[HttpGet]
[Route("Localizer")]
public string Localizer(string languageId)
{
return _localizer["HelloWorld"];
}

[HttpGet]
[Route("HtmlLocalizer")]
public LocalizedHtmlString HtmlLocalizer(string languageId)
{
return _htmlLocalizer["HelloWorld"];
}


[HttpGet]
[Route("StronglyTypedResource")]
public string StronglyTypedResource(string languageId)
{
return AppResources.Resources.HelloWorld;
}

[HttpGet]
[Route("GetAllLocalizerStrings")]
public object GetAllLocalizerStrings()
{
return _localizer.GetAllStrings();
}


[HttpGet]
[Route("DbRes")]
public string DbRes(string id)
{
//return Westwind.Globalization.DbRes.T("HelloWorld","Resources","de-DE");
return Westwind.Globalization.DbRes.T("HelloWorld", "Controllers.LocalizationController");
}

/// <summary>
/// This gets Resx Resources
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("StrongDbResResources")]
public string StrongDbResResources()
{
return AppResources.Resources.HelloWorld;
//return WestWind.Globalization.Sample.AspNetCore.Properties.Resources.HelloWorld;
}


/// <summary>
/// This gets generated strongly typed resources using DbRes or Resx depending
/// on configuration
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("StrongDesignerResources")]
public string StrongDesignerResources()
{
return AppResources.Resources.HelloWorld;
}

[HttpGet]
[Route("Test")]
public ActionResult Test()
{
return View("Test","Testing");
}

/// <summary>
/// Sets the culture and UI culture to a specific culture. Allows overriding of currency
/// and optionally disallows setting the UI culture.
///
/// You can also limit the locales that are allowed in order to minimize
/// resource access for locales that aren't implemented at all.
/// </summary>
/// <param name="culture">
/// 2 or 5 letter ietf string code for the Culture to set.
/// Examples: en-US or en</param>
/// <param name="uiCulture">ietf string code for UiCulture to set</param>
/// <param name="currencySymbol">Override the currency symbol on the culture</param>
/// <param name="setUiCulture">
/// if uiCulture is not set but setUiCulture is true
/// it's set to the same as main culture
/// </param>
/// <param name="allowedLocales">
/// Names of 2 or 5 letter ietf locale codes you want to allow
/// separated by commas. If two letter codes are used any
/// specific version (ie. en-US, en-GB for en) are accepted.
/// Any other locales revert to the machine's default locale.
/// Useful reducing overhead in looking up resource sets that
/// don't exist and using unsupported culture settings .
/// Example: de,fr,it,en-US
/// </param>
public void SetUserLocale(string culture = null,
string uiCulture = null,
string currencySymbol = null,
bool setUiCulture = true,
string allowedLocales = null,
HttpContext httpContext = null)
{
// Use browser detection in ASP.NET
if (string.IsNullOrEmpty(culture) && httpContext != null)
{
HttpRequest Request = httpContext.Request;

var langs = Request.Headers.GetCommaSeparatedValues("accept-language");


// if no user lang leave existing but make writable
if (langs == null || langs.Length == 0)
{
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentCulture.Clone() as CultureInfo;
if (setUiCulture)
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture.Clone() as CultureInfo;
return;
}
culture = langs[0];
}
else
culture = culture?.ToLower();

if (!string.IsNullOrEmpty(uiCulture))
setUiCulture = true;

if (!string.IsNullOrEmpty(culture) && !string.IsNullOrEmpty(allowedLocales))
{
allowedLocales = "," + allowedLocales.ToLower() + ",";
if (!allowedLocales.Contains("," + culture + ","))
{
int i = culture.IndexOf('-');
if (i > 0)
{
culture = culture.Substring(0, i);
if (!allowedLocales.Contains("," + culture + ","))
{
// Always create writable CultureInfo
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentCulture.Clone() as CultureInfo;
if (setUiCulture)
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture.Clone() as CultureInfo;

return;
}
}
}
}

if (string.IsNullOrEmpty(culture))
culture = CultureInfo.InstalledUICulture.IetfLanguageTag;

if (string.IsNullOrEmpty(uiCulture))
uiCulture = culture;

try
{
CultureInfo Culture = new CultureInfo(culture);

if (currencySymbol != null && currencySymbol != "")
Culture.NumberFormat.CurrencySymbol = currencySymbol;

Thread.CurrentThread.CurrentCulture = Culture;

if (setUiCulture)
{
var UICulture = new CultureInfo(uiCulture);
Thread.CurrentThread.CurrentUICulture = UICulture;
}
}
catch { }
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.db-journal
/SqLiteLocalizations.db
/_data.txt
17 changes: 17 additions & 0 deletions src/NetCore/WestWind.Globalization.Sample.AspNetCore31/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM microsoft/aspnetcore:2.0.0

MAINTAINER Rick Strahl

ENV ASPNETCORE_URLS=http://*:80
ENV ASPNETCORE_ENVIRONMENT=Production

# Allow 1433 for SQL Server Access
EXPOSE 1433

WORKDIR /var/www/WestwindGlobalization

# copy publish folder contents to web root
COPY ./bin/Release/netcoreapp2.0/publish .

# Run out of Publish Folder
CMD ["/bin/sh", "-c", "dotnet 'WestWind.Globalization.Sample.AspNetCore.dll'"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
GET http://localhost:5000/api/LocalizationAdministration/GetResourceSets HTTP/1.1
Accept: application/json, text/plain, */*
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
Referer: http://localhost:5000/LocalizationAdmin/
Accept-Encoding: gzip, deflate, br
Accept-Language: en

------------------------------------------------------------------


----- Start WebSurge Options -----

{
"NoProgressEvents": false,
"DelayTimeMs": 0,
"NoContentDecompression": false,
"CaptureMinimalResponseData": false,
"MaxResponseSize": 0,
"ReplaceQueryStringValuePairs": null,
"ReplaceDomain": null,
"ReplaceCookieValue": null,
"ReplaceAuthorization": null,
"Username": null,
"Password": null,
"Users": [],
"RandomizeRequests": false,
"RequestTimeoutMs": 15000,
"WarmupSeconds": 2,
"ReloadTemplates": false,
"FormattedPreviewTheme": "visualstudio",
"LastThreads": 2,
"IgnoreCertificateErrors": false,
"TrackPerSessionCookies": false,
"LastSecondsToRun": 10
}

// This file was generated by West Wind WebSurge
// Get your free copy at http://websurge.west-wind.com
// to easily test or load test the requests in this file.

----- End WebSurge Options -----

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
GET http://localhost:5000/api/Localization/StronglyTypedResource?languageId=de HTTP/1.1
Accept-Encoding: gzip,deflate
Accept-Language: de-DE,de;q=0.8,de;q=0.6
Websurge-Request-Name: StronglyTypedResource

------------------------------------------------------------------

GET http://localhost:5000/api/Localization/Localizer?languageId=de HTTP/1.1
Accept-Encoding: gzip,deflate
Accept-Language: de-DE,de;q=0.8,de;q=0.6
Websurge-Request-Name: Localizer

------------------------------------------------------------------

GET http://localhost:5000/api/Localization/DbRes HTTP/1.1
Accept-Encoding: gzip,deflate
Accept-Language: de-DE,de;q=0.8,de;q=0.6
Websurge-Request-Name: DbRes

------------------------------------------------------------------

GET http://localhost:5000/api/LocalizationAdmin/GetResourceList?resourceSet=Resources HTTP/1.1
Accept-Encoding: gzip,deflate
Websurge-Request-Name: GetResourceList

------------------------------------------------------------------

GET http://localhost:5000/api/LocalizationAdmin/GetAllResourcesForResourceGrid?resourceSet=Resources HTTP/1.1
Accept-Encoding: gzip,deflate
Websurge-Request-Name: GetAllResourcesForResourceGrid

------------------------------------------------------------------

GET http://localhost:5000/api/Localization/StrongDbResResources HTTP/1.1
Accept-Encoding: gzip,deflate
Accept-Language: de-DE,de;q=0.8,de;q=0.6
Websurge-Request-Name: StronglyTypedDbRes

------------------------------------------------------------------


----- Start WebSurge Options -----

{
"NoProgressEvents": false,
"DelayTimeMs": 0,
"NoContentDecompression": false,
"CaptureMinimalResponseData": false,
"MaxResponseSize": 0,
"ReplaceQueryStringValuePairs": null,
"ReplaceDomain": null,
"ReplaceCookieValue": null,
"ReplaceAuthorization": null,
"Username": null,
"Password": null,
"Users": [],
"RandomizeRequests": false,
"RequestTimeoutMs": 15000,
"WarmupSeconds": 2,
"ReloadTemplates": false,
"FormattedPreviewTheme": "visualstudio",
"LastThreads": 2,
"IgnoreCertificateErrors": false,
"TrackPerSessionCookies": true,
"LastSecondsToRun": 10
}

// This file was generated by West Wind WebSurge
// Get your free copy at http://websurge.west-wind.com
// to easily test or load test the requests in this file.

----- End WebSurge Options -----

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@page
@{
}
<div class="container" style="margin-top: 30px;">
<header class="page-header-text">
<i class="fa fa-share-alt"></i>
API Links
</header>


<div class="panel panel-default">
<div class="panel-heading"><h4>Api Links</h4></div>

<a href="~/api/Localization/Localizer" class="list-group-item">String Localizer</a>
<a href="~/api/Localization/HtmlLocalizer" class="list-group-item">Html Localizer</a>
<a href="~/api/localization/Test" class="list-group-item">View Localizer on Test MVC Page</a>

<a href="~/api/localization/StronglyTypedResource" class="list-group-item">Strongly Typed Resource</a>
<a href="~/api/localization/DbRes" class="list-group-item">Direct DbRes Access</a>
</div>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@page
@model ErrorModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
</p>
Loading