Last active
January 14, 2022 02:49
-
-
Save georgeOsdDev/fa4c6fe22faa4927c841b53baa741604 to your computer and use it in GitHub Desktop.
Use resx from Azure Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Globalization; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.Azure.WebJobs; | |
using Microsoft.Azure.WebJobs.Extensions.Http; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.Extensions.Logging; | |
public class HttpTrigger1 | |
{ | |
[FunctionName("HttpTrigger1")] | |
public async Task<IActionResult> Run( | |
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, | |
ILogger log) | |
{ | |
log.LogInformation("C# HTTP trigger function processed a request."); | |
if (req.Query["lang"] == "en") { | |
var specifiedCulture = new CultureInfo("en"); | |
CultureInfo.CurrentCulture = specifiedCulture; | |
CultureInfo.CurrentUICulture = specifiedCulture; | |
} else { | |
var specifiedCulture = new CultureInfo("ja"); | |
CultureInfo.CurrentCulture = specifiedCulture; | |
CultureInfo.CurrentUICulture = specifiedCulture; | |
} | |
string resourceName = "Resources.SharedResource"; | |
string assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; | |
System.Resources.ResourceManager rm = new System.Resources.ResourceManager($"_{assemblyName}.{resourceName}", System.Reflection.Assembly.GetExecutingAssembly()); | |
log.LogInformation(rm.GetString("Str_Hello")); | |
return new OkObjectResult($"{rm.GetString("Str_Hello")} World"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
├── bin | |
├── host.json | |
├── HttpTrigger1.cs | |
├── local.settings.json | |
├── MyFunctionApp.csproj | |
├── obj | |
└── Resources | |
├── SharedResource.en.resx | |
└── SharedResource.ja.resx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment