1 class OsmCommunityIndex
4 @localised_strings = {}
6 def self.community_index
7 @community_index ||= community_index_from_json
10 def self.localised_strings(locale)
11 @localised_strings[locale] ||= locale_hash_from_json(locale)
16 def self.community_index_from_json
17 json_file = Rails.root.join("node_modules/osm-community-index/dist/resources.json")
18 JSON.parse(File.read(json_file))
21 def self.locale_hash_from_json(locale_in)
22 locale = locale_in.to_s.tr("-", "_")
23 # try the passed in locale
24 json = load_locale_json(locale)
29 # now try it without it's country part (eg 'en' instead of 'en_GB')
30 shortened_locale = locale.split("_").first
31 unless shortened_locale === locale
32 json = load_locale_json(shortened_locale)
38 # if nothing else works, then return "en"
39 load_locale_json("en")
42 def self.load_locale_json(locale)
43 json_path = Rails.root.join("node_modules/osm-community-index/i18n/#{locale}.yaml")
44 if File.exist?(json_path)
45 response = YAML.safe_load(File.read(json_path))[locale]