简体   繁体   English

语言环境Ruby on Rails问题

[英]Locales Ruby on Rails issue

I have a issue with Locales. 我的语言环境有问题。 In rails app /config/locales/ I have two files: cs.rb & en.yml. 在Rails应用程序/ config / locales /中,我有两个文件:cs.rb和en.yml。 At the end, the output of price is in $. 最后,价格的输出为美元。 Why is this? 为什么是这样?

my index.html.erb looks 我的index.html.erb看起来

<% if notice %>
<p id="notice" ><%= notice %></p>
<% end %> 

<h1>Zoznam produktov</h1>

<% @products.each do |product| %>
  <div class="entry" >
    <%= image_tag(product.image_url) %>
    <h3><%= product.title %></h3>
    <%= sanitize(product.description) %>
    <div class="price_line" > 
      <span class="price">
        <%= number_to_currency(product.price, :locale => :cs) %>
 %>
      </span>       
    </div>
  </div>
<% end %>

@Зелёный @Зелёный

First is cs.rb and second is en.yml 第一个是cs.rb,第二个是en.yml

# Czech translations for Ruby on Rails
# by Karel Minařík (karmi@karmi.cz)
# contributors:
#  - Vít Krchov - http://github.com/vita - Rails 3 update

unless defined?(CzechLocaleI18n::ERROR_MESSAGES)
  module CzechLocaleI18n
    ERROR_MESSAGES = {
      :inclusion           => "není v seznamu povolených hodnot",
      :exclusion           => "je vyhrazeno pro jiný účel",
      :invalid             => "není platná hodnota",
      :confirmation        => "nebylo potvrzeno",
      :accepted            => "musí být potvrzeno",
      :empty               => "nesmí být prázdný/á/é",
      :blank               => "je povinná položka", # alternate formulation: "is required"
      :too_long            => "je příliš dlouhý/á/é (max. %{count} znaků)",
      :too_short           => "je příliš krátký/á/é (min. %{count} znaků)",
      :wrong_length        => "nemá správnou délku (očekáváno %{count} znaků)",
      :not_a_number        => "není číslo",
      :greater_than        => "musí být větší než %{count}",
      :greater_than_or_equal_to => "musí být větší nebo rovno %{count}",
      :equal_to            => "musí být rovno %{count}",
      :less_than           => "musí být méně než %{count}",
      :less_than_or_equal_to    => "musí být méně nebo rovno %{count}",
      :odd                 => "musí být liché číslo",
      :even                => "musí být sudé číslo",
      :not_an_integer       => "musí být celé číslo"
    }
  end
end

{ :'cs' => {

    # ActiveSupport
    :support => {
      :array => {
    :two_words_connector => ' a ',
    :last_word_connector => ' a ',
    :words_connector => ', '
      },
      :select => {
    :prompt => 'Prosím vyberte si',
      }
    },

    # Date
    :date => {
      :formats => {
    :default => "%d. %m. %Y",
    :short   => "%d %b",
    :long    => "%d. %B %Y",
      },
      :day_names         => %w{Neděle Pondělí Úterý Středa Čtvrtek Pátek Sobota},
      :abbr_day_names    => %w{Ne Po Út St Čt Pá So},
      :month_names       => %w{~ Leden Únor Březen Duben Květen Červen Červenec Srpen Září Říjen Listopad Prosinec},
      :abbr_month_names  => %w{~ Led Úno Bře Dub Kvě Čvn Čvc Srp Zář Říj Lis Pro},
      :order             => [:day, :month, :year]
    },

    # Time
    :time => {
      :formats => {
    :default => "%a %d. %B %Y %H:%M %z",
    :short   => "%d. %m. %H:%M",
    :long    => "%A %d. %B %Y %H:%M",
      },
      :am => 'am',
      :pm => 'pm'
    },

    # Numbers
    :number => {
      :format => {
    :precision => 3,
    :separator => '.',
    :delimiter => ',',
    :significant => false,
    :strip_insignificant_zeros => false
      },
      :currency => {
    :format => {
      :unit => 'Kč',
      :precision => 2,
      :format    => '%n %u',
      :separator => ",",
      :delimiter => " ",
      :significant => false,
      :strip_insignificant_zeros => false
    }
      },
      :human => {
    :format => {
      :precision => 1,
      :delimiter => '',
      :significant => false,
      :strip_insignificant_zeros => false
    },
       :storage_units => {
     :format => "%n %u",
     :units => {
       :byte => "B",
       :kb   => "KB",
       :mb   => "MB",
       :gb   => "GB",
       :tb   => "TB",
     }
       },
       :decimal_units => {
     :format => "%n %u",
     :units => {
       :unit => "",
       :thousand => "Tisíc",
       :million => "Milion",
       :billion => "Miliarda",
       :trillion => "Bilion",
       :quadrillion => "Kvadrilion"
     }
       }
      },
      :percentage => {
    :format => {
      :delimiter => ''
    }
      },
      :precision => {
    :format => {
      :delimiter => ''
    }
      }
    },

    # Distance of time ... helper
    # NOTE: In Czech language, these values are different for the past and for the future. Preference has been given to past here.
    :datetime => {
      :prompts => {
    :second => "Sekunda",
    :minute => "Minuta",
    :hour => "Hodina",
    :day => "Den",
    :month => "Měsíc",
    :year => "Rok"
      },
      :distance_in_words => {
    :half_a_minute => 'půl minutou',
    :less_than_x_seconds => {
      :one => 'necelou sekundou',
      :other => 'ani ne %{count} sekundami'
    },
    :x_seconds => {
      :one => 'sekundou',
      :other => '%{count} sekundami'
    },
    :less_than_x_minutes => {
      :one => 'necelou minutou',
      :other => 'ani ne %{count} minutami'
    },
    :x_minutes => {
      :one => 'minutou',
      :other => '%{count} minutami'
    },
    :about_x_hours => {
      :one => 'asi hodinou',
      :other => 'asi %{count} hodinami'
    },
    :x_days => {
      :one => '24 hodinami',
      :other => '%{count} dny'
    },
    :about_x_months => {
      :one => 'asi měsícem',
      :other => 'asi %{count} měsíci'
    },
    :x_months => {
      :one => 'měsícem',
      :other => '%{count} měsíci'
    },
    :about_x_years => {
      :one => 'asi rokem',
      :other => 'asi %{count} roky'
    },
    :over_x_years => {
      :one => 'více než rokem',
      :other => 'více než %{count} roky'
    },
    :almost_x_years => {
      :one => 'téměř rokem',
      :other => 'téměř %{count} roky'
    }
      }
    },

    :helpers => {
      :select => {
    :prompt => "Prosím vyberte si"
      },

      :submit => {
    :create => "Vytvořit %{model}",
    :update => "Aktualizovat %{model}",
    :submit => "Uložit %{model}"
      }
    },

    :errors => {
      :format => "%{attribute} %{message}",
      :messages => CzechLocaleI18n::ERROR_MESSAGES
    },

    # ActiveRecord validation messages
    :activerecord => {
      :errors => {
    :messages => {
      :taken               => "již databáze obsahuje",
      :record_invalid      => "Validace je neúspešná: %{errors}"
    }.merge(CzechLocaleI18n::ERROR_MESSAGES),
    :template => {
      :header   => {
        :one => "Při ukládání objektu %{model} došlo k chybám a nebylo jej možné uložit",
        :other => "Při ukládání objektu %{model} došlo ke %{count} chybám a nebylo možné jej uložit"
      },
      :body  => "Následující pole obsahují chybně vyplněné údaje:"
    },
    :full_messages => {
      :format => "%{attribute} %{message}"
    }
      }
    }
  }
}

#

# Sample localization file for English. Add more files in   this      directory for other locales.
# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
  hello: "Hello world"

I think, you have not defined cs.yml in locale directory that's why, it is taking default as en locale. 我认为,您尚未在语言环境目录中定义cs.yml,这就是原因,它默认使用en语言环境。

please define cs.yml instead of cs.rb 请定义cs.yml而不是cs.rb

For this to work you need to have a locale file at config/locales/fr.yml for this to work. 为此,您需要在config / locales / fr.yml中有一个语言环境文件才能起作用。

The :locale option only declares to Rails what locale you want it to be. :locale选项仅向Rails声明您想要的语言环境。 Rails does not have all the translations for every language in the project, and so you must include these translation files yourself. Rails没有项目中每种语言的所有翻译,因此您必须自己包括这些翻译文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM