]> git.openstreetmap.org Git - rails.git/blob - config/initializers/i18n.rb
Merge pull request #6394 from openstreetmap/dependabot/github_actions/ruby/setup...
[rails.git] / config / initializers / i18n.rb
1 # frozen_string_literal: true
2
3 module I18n
4   module Backend
5     module PluralizationFallback
6       def pluralize(locale, entry, count)
7         super
8       rescue InvalidPluralizationData => e
9         raise e unless e.entry.key?(:other)
10
11         e.entry[:other]
12       end
13     end
14   end
15 end
16
17 module OpenStreetMap
18   module I18n
19     module NormaliseLocales
20       def store_translations(locale, data, options = {})
21         locale = ::I18n::Locale::Tag::Rfc4646.tag(locale).to_s
22
23         super
24       end
25     end
26   end
27 end
28
29 I18n::Backend::Simple.prepend(OpenStreetMap::I18n::NormaliseLocales)
30
31 I18n::Backend::Simple.include(I18n::Backend::PluralizationFallback)
32 I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
33
34 I18n.enforce_available_locales = false
35
36 if Rails.env.test?
37   I18n.exception_handler = proc do |exception|
38     raise exception.to_exception
39   end
40 end
41
42 Rails.configuration.after_initialize do
43   require "i18n-js/listen"
44
45   # This will only run in development.
46   I18nJS.listen
47
48   I18n.available_locales
49 end
50
51 AVAILABLE_LANGUAGES = YAML.load_file(Rails.root.join("config/ui_languages.yml"))