在我从本地环境运行的浏览器中,字符串按预期进行了翻译。当我上传到Azure时,它仍然有效。但是,当我切换到Edge时(除了下载FireFox外,我从不用于其他任何用途),字符串不再翻译。我已通过各种浏览器与外部用户进行了验证,这似乎是平台无关的问题。
我所有的翻译都放在一个全局文件中,该文件位于根目录中,并且我有一个虚拟文件,因此可以按照文档的建议将其注入视图和控制器中。不知何故,似乎找不到RESX文件,因此我将其放在始终上传中。不过,行为没有任何变化。
我不确定如何进一步诊断它,或者不确定RESX文件是否已编译到DLL中或直接上传到服务器并可以即时读取。是否可以通过某种方式验证文件位于“那里”?
我的配置是这样的。
RequestLocalizationOptions options = app.ApplicationServices
.GetService<IOptions<RequestLocalizationOptions>>().Value;
app.UseRequestLocalization(options);
修改
我注意到当我有这些行时,它就可以在Chrome浏览器中工作。
//RequestLocalizationOptions options = app.ApplicationServices
// .GetService<IOptions<RequestLocalizationOptions>>().Value;
app.UseRequestLocalization();
当我有了它们时,它将停止工作。
onEvent("SubmitButtonFreeClothingScreen", "click", function(event)
{
{
setScreen("Screen2");
readRecords("FreeClothing",{ZipCodes: getText("text_input1")},
function(records)
{
var names="";
if (records.length>0)
{
for(var i =0; i < records.length; i++)
{
var number= i+1;
names=names+ number + ") " + records[i].Name+"" +"\n\n"+"Address: "+ records[i].Address+"\n\n"+"Phone Number: "+ records[i].PhoneNumber+"\n\n"+"Description: "+ records[i].Description+"\n\n";
}
setText("display_info",""+names);
}
/*Display Furniture Store information located in database*/
else
{
setText ("display_info", "This Zipcode unfortunately has no Furniture Store locations. Please try another one");
/*If no information is found, the string above is printed*/
}
}
);
}
});
在IE中这两种情况均不起作用。
答案 0 :(得分:2)
Couple words about culture configuration. I guess you wanted to specify only Swedish locale so you have these line of code
CultureInfo[] supportedCultures = {
new CultureInfo("sv-SE"),
new CultureInfo("se")
};
It turns out that sv-SE
is definitely Swedish culture, but se
is Northern Sami culture. If your intention is only Swedish culture you need to set sv
instead of se
CultureInfo[] supportedCultures = {
new CultureInfo("sv-SE"),
new CultureInfo("sv")
};
a.DefaultRequestCulture = new RequestCulture("sv");
Back to the main problem. By default there are 3 ways to set request culture, via query string, cookies or Accept-Language
header. It looks like you don't specify a culture in request cookies or query string, but your browser sends Accept-Language
header from which ASP.NET Core reads request culture. If a browser sends en-US
, en
, and sv
cultures, none of them matches to supportedCultures
(which are sv-SE
and se
) the framework falls back to DefaultRequestCulture
(which is se
) and reads resources from Lingo.se.resx
and everything is fine. But it looks like Edge (on any other browser but on another computer) sent different set of cultures within Accept-Language
header which included sv-SE
containing in supportedCultures
. So resource reader searched for Lingo.sv-se.resx
or Lingo.sv.resx
file but with no luck and thus no translation were provided.
If my assumption is right changing se
to sv
in your code and renaming Lingo.se.resx
to Lingo.sv.resx
will fix the problem.