Spree_i18n 前端自定义语言环境

Spree_i18n front-end custom locale

我正在尝试自定义 Spree_i18n 前端导航栏语言环境,但在将其从 select_tag 更改为 link_to 时遇到了一些问题。我试图让它只显示两个语言环境选择 EN/CN。最好的解决方案是什么?

locale.js

load = function() {
  return $('#locale-select select').change(function() {
    return $.ajax({
      type: 'POST',
      url: $(this).data('href'),
      data: {
        locale: $(this).val()
      }
    }).done(function() {
      return window.location.reload();
    });
  });
};

navbar.html.erb

<li id="locale-select" data-hook>
  <%= form_tag set_locale_path, class: 'navbar-form' do %>
    <div class="form-group">
      <label for="locale" class="sr-only"><%= t(:'i18n.language') %></label>
      <%= select_tag(:locale, options_for_select(supported_locales_options, I18n.locale), class: 'form-control', data: { href: set_locale_path }) %>
      <noscript><%= submit_tag %></noscript>
    </div>
  <% end %>
</li>

我的自定义变体

<%= link_to 'en', spree.set_locale_path(switch_to_locale: :en), method: :post %>