Il n'y a rien que vous puissiez dire immédiatement en consultant le site officiel, Comme un blog ou Qiita Je n'ai trouvé aucune information non primaire mettant l'accent sur la clarté.
Lorsque j'exécutais la section ** Monetize example ** de Metaprogramming Ruby. Pour un tel affichage.
ruby $ ruby 202010270014.rb
[WARNING] The default rounding mode will change from `ROUND_HALF_EVEN` to `ROUND_HALF_UP` in the next major release. Set it explicitly using `Money.rounding_mode=` to avoid potential problems.
[DEPRECATION] You are using the default localization behaviour that will change in the next major release. Find out more - https://github.com/RubyMoney/money#deprecation
Traceback (most recent call last):
10: from 202010270014.rb:5:in `<main>'
9: from /Users/username/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/money-6.13.8/lib/money/money.rb:600:in `format'
8: from /Users/username/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/money-6.13.8/lib/money/money/formatter.rb:232:in `to_s'
7: from /Users/username/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/money-6.13.8/lib/money/money/formatter.rb:257:in `format_number'
6: from /Users/username/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/money-6.13.8/lib/money/money/formatter.rb:333:in `format_whole_part'
5: from /Users/username/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/money-6.13.8/lib/money/money/formatter.rb:238:in `thousands_separator'
4: from /Users/username/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/money-6.13.8/lib/money/money/formatter.rb:366:in `lookup'
3: from /Users/username/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/money-6.13.8/lib/money/locale_backend/legacy.rb:15:in `lookup'
2: from /Users/username/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/money-6.13.8/lib/money/locale_backend/i18n.rb:19:in `lookup'
1: from /Users/username/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/i18n-1.6.0/lib/i18n.rb:182:in `translate'
/Users/username/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/i18n-1.6.0/lib/i18n.rb:326:in `enforce_available_locales!': :en is not a valid locale (I18n::InvalidLocale)
error.rb
require "monetize"
bargain_price = Monetize.from_numeric(99, "USD")
p bargain_price.format
success.rb
require "monetize"
I18n.load_path << Dir[File.expand_path("config/locales") + "/*.yml"]
I18n.default_locale = :en # (note that `en` is already the default!)
bargain_price = Monetize.from_numeric(99, "USD")
p bargain_price.format
J'ai emprunté les 2ème et 3ème lignes au README de Official Repository. Réécrivez la source ci-dessus + Placez le fichier yml dans config / locales / en.yml. Le contenu est le suivant comme LISEZ-MOI du référentiel officiel.
en.yml
en:
test: "This is a test"
ruby $ ruby 202010270014.rb
[WARNING] The default rounding mode will change from `ROUND_HALF_EVEN` to `ROUND_HALF_UP` in the next major release. Set it explicitly using `Money.rounding_mode=` to avoid potential problems.
[DEPRECATION] You are using the default localization behaviour that will change in the next major release. Find out more - https://github.com/RubyMoney/money#deprecation
[DEPRECATION] You are using the default localization behaviour that will change in the next major release. Find out more - https://github.com/RubyMoney/money#deprecation
"$99.00"
ATTENTION est sorti, mais cela a fonctionné pour le moment.
Rubis de métaprogrammation Dépôt officiel i18n
Recommended Posts