在软件或网站中切换语言的最佳方法?
我想知道在软件或网站中切换语言的最佳编程技术。那么有人可以给我一些建议吗?谢谢!
I want to know the best programming technique to switch languages in the software or website. So anyone can give me some suggestions? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有标准。但我在网站中使用了以下技术。
There is no standard. But I used the following technique in websites.
en_GB
locale, find strings in en_GB folder or inlang_en_GB
table. Naming format is in your hand.这取决于您使用的语言。许多人都对此表示支持。例如,在 android 中,您所做的是将所有字符串存储到根据区域命名的 xml 文件中。并且操作系统会根据手机区域自动使用适当的资源。
查看您的语言/平台包含哪些支持。您需要将所有字符串常量(例如“按菜单按钮”)外部化到外部文件中。然后只需将此文件翻译为您想要支持的每种语言,并使用操作系统自动使用正确的资源文件。或者,如果平台/操作系统不支持这样的事情,请编写一些代码来确定自己使用哪个资源文件。
It depends on the language you are using. Many have built in support for it. In android for example what you do is store all strings into an xml file that is named based on the region. And the operating system will automatically use the appropriate resources based on the phones region.
Look into what support your language/platform includes. You will want to externalize all your string constants such as "Press the menu button" into an external file. Then just get this file translated to each language you want to support, and use the OS to automatically use the correct resource file. Or if the platform/OS does not support such a thing write some code to determine which resource file to use yourself.