1

:動的は、翻訳の配列をソートする3宝石をグローバル化::私が達成したい何

  1. ループアウト小文字ユニークにする私が必要であることを行うには、私のGallery.tag

    からisotope.jsを使用して、カテゴリソーターを作成します私は012を使用することはできません(翻訳のための3グローバル化使用)タグアウト

  2. ループの.class私のHTMLのタグは<h2>

に表示しますどちらの場合もとなります。スイッチ言語では、ソーターを破壊するmy .classに中国語の文字が出力されるためです。したがって、私は2つの配列を作成し、それらをzipで結合し、それぞれをループします。

アルファベット順でソートしようとしていますが、対応する中国語のタグが英語の順番通りではありません。カテゴリエン

ギャラリー/ index.html.erb

<% @uniq_test = [] %> 
    <% @galleries_order.each do |gallery| %> 
     <% next if @uniq_test.include?(gallery.tag) %> 
    <% @uniq_test << gallery.tag %> 
<% end %> 
<% @sorters = @sorters.map(&:downcase).sort! %> 
<% @uniq_test = @uniq_test.map(&:downcase).sort! %> 
<% @uniq_sorters = @uniq_test.zip(@sorters) %> 
<div class="main"> 
    <div class="gallery-select-wrapper"> 
     <div class="sort-gallery-buttons animated slideInLeft text-center"> 
      <h2 id="recent"class="recent"><%= t"galleries.sorter.recent"%></h2> 
    <% @uniq_sorters.each do |uniq, sorter| %> 
     <% if sorter != nil %> 
      <% str = "<h2 class='" + sorter + "'" + "id='"+ sorter + "'>"%> 
      <%= str.html_safe + uniq + "</h2>".html_safe %> 
     <% end %> 
    <% end %> 
     </div> 
    </div> 
</div> 

コントローラ/ galleries.rb

def index 
    @galleries = Gallery.all.order("created_at DESC") 
    @galleries_order = Gallery.all.order("title ASC") 
    @sorters = Gallery.uniq.pluck(:tag) 
    gon.tags = Gallery.uniq.pluck(:tag) 
end 

[国、テーマ、プロジェクト、戦争] ZHカテゴリは、[主題されている國家、戰爭、項目] < - 現在(en =テーマ、国、戦争、プロジェクト) 私のカテゴリは[國家、主題、項目、戰爭] < - 目的(同じen)

一言で言えば、私の英語のアルファベット順に中国語の翻訳をしたいです。

enter image description here

enter image description here

+0

う作る私の配列が仕事をハッシュ? – Rex

答えて

0

はそれを解決します!一言で言えば、globalize3 :: translationモデルで何かをソートするには、:idまたは私のケースでは:created_atをソートするのではなく、中国語の文字をソートする方法を見つけ出すのがベストです。用語がアルファベット順であるかどうかは特に気にしないので、同期している限り、私は満足しています。

私はそれを間違いなく思っていました。

ギャラリー/ index.htmlを

<% @array = [] %> 
<% @test.each do |test| %> 
    <% next if @array.include?(test.tag) %> 
    <% @array << test.tag %> 
<% end %> 

<% @array_en = [] %> 
<% @test.each do |test| %> 
    <% next if @array_en.include?(test.tag_en) %> 
    <% @array_en << test.tag_en %> 
<% end %> 

<% @combined_array = @array.zip(@array_en) %> 

<div class="main"> 
    <div class="gallery-select-wrapper"> 
     <div class="sort-gallery-buttons animated slideInLeft text-center"> 
      <h2 id="recent"class="recent"><%= t"galleries.sorter.recent"%></h2> 
    <% @combined_array.each do |uniq, sorter| %> 
     <% if sorter != nil %> 
      <% str = "<h2 class='" + sorter + "'" + "id='"+ sorter + "'>"%> 
      <%= str.html_safe + uniq + "</h2>".html_safe %> 
     <% end %> 
    <% end %> 
     </div> 
    </div> 
</div> 

コントローラ/ galleries.rb

@test = Gallery.all.sort { |p1, p2| p1.created_at <=> p2.created_at } 
関連する問題