在 Azure Function App 中使用 .resx 文件

Sco*_*wis 5 c# resx azure azure-functions

我正在 Azure 中创建一个新的 webhook C# 函数,我希望根据传入的 lang 查询参数或 Accept-Language 标头以不同的翻译返回固定内容。

为了存储不同的翻译,我自然会想到 .resx 文件。有没有办法在 Azure Function Apps 中使用 .resx 文件?

des*_*des 3

看起来资源文件还没有得到正确的支持

我通过将嵌入的资源文件读入资源集中来解决这个问题。

var culture = CultureInfo.CurrentUICulture;
var resourceName = $"FunctionApp.Properties.Resources.{culture.TwoLetterISOLanguageName}.resources";
var cultureResourceSet = new ResourceSet(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName));
var localizedString = cultureResourceSet.GetString(resourceKey);
// fallback to default language if not found
Run Code Online (Sandbox Code Playgroud)