1 module OsmCommunityIndex
5 def initialize(id, url)
10 def self.local_chapters
11 @chapters = init_local_chapters
14 def self.init_local_chapters
15 raw_local_chapters = load_raw_local_chapters
16 raw_local_chapters.map do |chapter|
18 url = chapter[:resource]["strings"]["url"]
19 LocalChapter.new(id, url)
23 def self.load_raw_local_chapters
24 community_index = OsmCommunityIndex.community_index
25 raw_local_chapters = []
26 community_index["resources"].each do |id, resource|
27 resource.each do |key, value|
28 next unless key == "type" && value == "osm-lc" && id != "OSMF"
30 raw_local_chapters.push({ :id => id, :resource => resource })
37 raw_local_chapters = load_raw_local_chapters
38 files = Dir.glob(Rails.root.join("node_modules/osm-community-index/i18n/*"))
40 locale = File.basename(file, ".yaml")
41 community_index_yaml = YAML.safe_load(File.read(file))[locale]
42 # rails wants en-GB but osm-community-index has en_GB
43 locale_rails = locale.tr("_", "-")
46 raw_local_chapters.each do |chapter|
48 resource = chapter[:resource]
50 strings = community_index_yaml[id] || {}
51 # if the name isn't defined then fall back on community,
52 # as per discussion here: https://github.com/osmlab/osm-community-index/issues/483
53 strings["name"] = strings["name"] || resource["strings"]["name"] || resource["strings"]["community"]
55 data.deep_merge!({ "osm_community_index" => { "local_chapter" => { id => strings } } })
58 I18n.backend.store_translations locale_rails, data