gpt4 book ai didi

ruby-on-rails - 设置本地化文件中文本的样式 - 粗体、斜体等

转载 作者:行者123 更新时间:2023-12-03 03:36:02 25 4
gpt4 key购买 nike

有哪些技术/方法可以处理本地化字符串中的强调或风格化文本?

例如,像下面这样的简短标题(4-8 个单词)如何变为斜体?

Welcome to the Machine, John.

有没有比 3 次查找加上一个变量来定义结构更有效的方法?

最佳答案

查看documentation它说:

Third, it'll mark the translation as safe HTML if the key has the suffix “_html” or the last element of the key is the word “html”. For example, calling translate(“footer_html”) or translate(“footer.html”) will return a safe HTML string that won't be escaped by other HTML helper methods. This naming convention helps to identify translations that include HTML tags so that you know what kind of output to expect when you call translate in a template.

因此您需要将后缀 _html 附加到您的 key ,现在您可以在您的语言环境中使用 html。

例如,这是您的区域设置文件:

en:
welcome:
html: '<b>Hello!</b> This is first way to style your locales!'
welcome_html: '<b>Hi again!</b> This is second way to style your locales!'

现在只需在 View 中设置 I18n.t 'en.welcome.html'I18n.t 'en.welcome_html' 即可。就这样! :)

关于ruby-on-rails - 设置本地化文件中文本的样式 - 粗体、斜体等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34778181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com