Web 应用程序中的一些字符串的翻译。
当用户想要以他的语言查看这些字符串时,如何将 Web 应用程序中的一些字符串翻译为其他语言?
How to translate a few strings in a web application to a different language when the user wants to see those strings in his language?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你熟悉 i18n 吗?它是“internationalization”的缩写,是一个 20 个字母的单词:第一个“i”,然后是 18 个字母,然后是“n”:D
有些人喜欢为此使用属性文件。您可以根据 i18n 语言名称来命名属性文件。因此,对于英语和瑞典语文本,您将拥有例如 en-us.properties 和 sw-se.properties 。在这些文件中,您将拥有一些要显示的文本的占位符名称,以及它们的实际值。请记住,占位符不能有空格!
en-us.properties 将包含
sw-se.properties 将包含
我已经编写了此功能,其中 % 符号内的内容是占位符,将在语言文本已被保留,以便会话或数据库中的数据可以放置在消息中。
请注意语言文件如何包含完全相同的键,但具有不同的值。
当您想要显示文本时,
are you familiar with i18n? it's short for "internationalization" which is a 20 letter word: first "i", then 18 letters, and then "n" :D
some people like to use properties-files for this. you name the property-file after its i18n language name. so you would have for example en-us.properties and sw-se.properties for english vs swedish texts. in these files you would then have place holder names for some texts you want to display, and what their actual values would be. remember that place holders can't have spaces!
en-us.properties would contain
sw-se.properties would contain
i've made up this functionality where things within % signs are placeholders to be replaced after the language text has been retained, so that data from the session or the database can be placed within the message.
note how the language files both contain the exact same keys, but with different values.
when you want to display text,