]> git.openstreetmap.org Git - rails.git/blob - config/initializers/i18n.rb
Merge pull request #6948 from openstreetmap/dependabot/bundler/action_text-trix-2...
[rails.git] / config / initializers / i18n.rb
1 # frozen_string_literal: true
2
3 module OpenStreetMap
4   module I18n
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
15     module NormaliseLocales
16       def store_translations(locale, data, options = {})
17         locale = ::I18n::Locale::Tag::Rfc4646.tag(locale).to_s
18
19         super
20       end
21     end
22   end
23 end
24
25 I18n::Backend::Simple.prepend(OpenStreetMap::I18n::NormaliseLocales)
26
27 I18n::Backend::Simple.include(OpenStreetMap::I18n::PluralizationFallback)
28 I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
29
30 I18n.enforce_available_locales = false
31
32 if Rails.env.test?
33   I18n.exception_handler = proc do |exception|
34     raise exception.to_exception
35   end
36 end
37
38 Rails.configuration.after_initialize do
39   require "i18n-js/listen"
40
41   # This will only run in development.
42   I18nJS.listen
43
44   I18n.available_locales
45 end
46
47 AVAILABLE_LANGUAGES = YAML.load_file(Rails.root.join("config/ui_languages.yml"))