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