Skip to content

Commit

Permalink
Set particular locales for application (kslazarev#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
seniorihor committed Dec 16, 2016
1 parent c24a2ed commit d5146ac
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Features
* Your contribution here.
* Set particular locales for application. \[[#135](https://github.com/kslazarev/numbers_and_words/issues/135)\] \([@seniorihor](https://github.com/seniorihor)\) \(assignee: [@seniorihor](https://github.com/seniorihor)\)

* Add option `precision` to `to_words`. \[[#134](https://github.com/kslazarev/numbers_and_words/issues/134)\] \([@neodelf](https://github.com/neodelf)\) \(assignee: [@neodelf](https://github.com/neodelf)\)

### Bugs
Expand Down
17 changes: 17 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ I18n kütüphanesi ile sayıları yazıya çevirir.
I18n.with_locale(:ru) { 0.1.to_words precision: 3 }
=> ноль целых и десять сотых

== Locales configuration / Конфигурация локалей

You may optionally set locales you want to work with in your application.

First, add to your Gemfile ("require: false" needed for config to take effect)

gem 'numbers_and_words', require: false

Then create your configuration in config/initializers/numbers_and_words.rb

module NumbersAndWords
module I18n
APP_LOCALES = ["en", "ru"]
end
end
require "numbers_and_words"

== Requirements / Требования / Configuration Requise

* 1.9.3 <= Ruby (compatible with/совместимость с/compatible avec Ruby 1.9, JRuby and/и/et Rubinius);
Expand Down
15 changes: 14 additions & 1 deletion lib/numbers_and_words/i18n/initialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,22 @@ module Initialization
extend self

def init
I18n.locale_files.each { |locale_file| ::I18n.load_path << locale_file}
I18n.locale_files.each { |locale_file| ::I18n.load_path << locale_file if app_locale?(locale_file) }
NumbersAndWords::I18n::Pluralization.init
end

private

def app_locale?(file)
return true unless app_locales

locale = file.split('.')[-2]
app_locales.include?(locale)
end

def app_locales
@app_locales ||= (I18n::APP_LOCALES if I18n.const_defined?(:APP_LOCALES))
end
end
end
end

0 comments on commit d5146ac

Please sign in to comment.