我想在应用程序中使用gettext
。我还不知道如何在link
内使用它。我怎样才能翻译" Show"链接文字和[confirm: "Are you sure?"]
部分?
<%= link "Show", to: user_path(@conn, :show, user), class: "btn btn-default btn-xs" %>
<%= link "Edit", to: user_path(@conn, :edit, user), class: "btn btn-default btn-xs" %>
<%= link "Delete", to: user_path(@conn, :delete, user),
method: :delete, data: [confirm: "Are you sure?"],
class: "btn btn-danger btn-xs" %>
答案 0 :(得分:4)
假设import YourApp.Gettext
中有YourApp.Web.view/0
,只需在调用gettext/1
时打包您要翻译的每段文字:
<%= link gettext("Show"), to: user_path(@conn, :show, user), class: "btn btn-default btn-xs" %>
<%= link gettext("Edit"), to: user_path(@conn, :edit, user), class: "btn btn-default btn-xs" %>
<%= link gettext("Delete"), to: user_path(@conn, :delete, user),
method: :delete, data: [confirm: gettext("Are you sure?")],
class: "btn btn-danger btn-xs" %>