Sco*_*wis 5 c# resx azure azure-functions
我正在 Azure 中创建一个新的 webhook C# 函数,我希望根据传入的 lang 查询参数或 Accept-Language 标头以不同的翻译返回固定内容。
为了存储不同的翻译,我自然会想到 .resx 文件。有没有办法在 Azure Function Apps 中使用 .resx 文件?
我通过将嵌入的资源文件读入资源集中来解决这个问题。
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)
| 归档时间: |
|
| 查看次数: |
3024 次 |
| 最近记录: |