通过 MVC 实现全球化

发布于 2024-12-14 14:59:43 字数 466 浏览 4 评论 0原文

我正在尝试本地化我的网页,并完成了以下操作:

添加了带有一些示例字符串的资源文件

添加了对方法的调用,以在标志图标的单击事件上设置文化和 ui 文化:

public void SetCulture(string culture)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
    }

并且我已经引用了我的资源我的网页中的文件字符串:

@Resources.General.String1

我已经单步执行了我的代码,并且在我的 SetCulture 方法中成功更改了区域性,但该字符串在网页上没有更改。有人可以建议为什么吗?

I am trying to localize my web page, and have done the following :

Added resource files with some example strings

Added a call to a method to set culture and ui culture on the click event of flag icons :

public void SetCulture(string culture)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
    }

And I have made reference to my resource file strings in my web page :

@Resources.General.String1

I have stepped through my code and the culture is successfully changed in my SetCulture method, but the string does not change on the web page. Can anybody advise why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

予囚 2024-12-21 14:59:43

我不明白您所说的 ASP.NET MVC 应用程序中的单击事件是什么意思。我将使用路由来设置新语言。您可以在 Localization with ASP.NET MVC 中找到示例使用路由

您必须重新加载整个页面,而不是使用 Javascript 事件。

I don't understand what you mean with the click event in a ASP.NET MVC application. I would use routing to set the new language. A sample you can find at Localization with ASP.NET MVC using Routing.

Instead of using a Javascript event, you have to reload the whole page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文