1 module OsmCommunityIndex
5 def initialize(id, url)
10 def self.local_chapters
11 @chapters = load_local_chapters
14 def self.load_local_chapters
15 community_index = OsmCommunityIndex.community_index
17 community_index["resources"].each do |id, resource|
18 resource.each do |key, value|
19 next unless key == "type" && value == "osm-lc" && id != "OSMF"
22 url = resource["strings"]["url"]
23 local_chapters.push(LocalChapter.new(id, url))
30 community_index = OsmCommunityIndex.community_index
31 files = Dir.children(Rails.root.join("node_modules/osm-community-index/i18n/"))
33 path = Rails.root.join("node_modules/osm-community-index/i18n/#{file}")
34 locale = File.basename(file,".yaml")
35 community_index_yaml = YAML.safe_load(File.read(path))[locale]
36 # rails wants en-GB but osm-community-index has en_GB
37 locale_rails = locale.split("_").join("-")
39 community_index["resources"].each do |id, resource|
40 resource.each do |key, value|
41 next unless key == "type" && value == "osm-lc" && id != "OSMF"
43 strings = community_index_yaml[id] || {}
44 # if the name isn't defined then fall back on community,
45 # as per discussion here: https://github.com/osmlab/osm-community-index/issues/483
46 strings['name'] = strings['name'] || resource["strings"]["name"] || resource["strings"]["community"]
49 data["osm_community_index"] = {}
50 data["osm_community_index"]["local_chapter"] = {}
51 data["osm_community_index"]["local_chapter"][id] = strings
52 I18n.backend.store_translations locale_rails, data