在<%= link ..%>中使用gettext

时间:2016-04-28 09:34:03

标签: elixir phoenix-framework

我想在应用程序中使用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" %>

1 个答案:

答案 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" %>