【发布时间】:2021-06-19 01:06:38
【问题描述】:
当使用I18n.t 在 Rails 中嵌入链接时,可以在 ERB 中执行类似的操作:
<% link_destination = link_to(I18n.t(".link destination", "https://destination.url")) %>
<%= I18n.t(".translated text with %{link}", link: link_destination) %>
但是当我在 Phoenix / Elixir EEX 中做这样的事情时:
<% link_destination = link(gettext("link destination"), to: "https://destination.url")
<%= raw(gettext("translated text with %{link}", link: link_destination)) %>
我得到错误:
(Protocol.UndefinedError) 协议 String.Chars 未实现 {:safe, [60, "a", [[32, "href", 61, 34, "https://destination.url", 34]], 62, "link destination", 60, 47, "a", 62]} 元组类型。
那么如何在 Gettext 翻译中嵌入 URL?
【问题讨论】: