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
17 raw_local_chapters.each do |chapter|
19 url = chapter[:resource]["strings"]["url"]
20 local_chapters.push(LocalChapter.new(id, url))
25 def self.load_raw_local_chapters
26 community_index = OsmCommunityIndex.community_index
27 raw_local_chapters = []
28 community_index["resources"].each do |id, resource|
29 resource.each do |key, value|
30 next unless key == "type" && value == "osm-lc" && id != "OSMF"
32 raw_local_chapters.push({ :id => id, :resource => resource })
39 raw_local_chapters = load_raw_local_chapters
40 files = Dir.glob(Rails.root.join("node_modules/osm-community-index/i18n/*"))
42 locale = File.basename(file, ".yaml")
43 community_index_yaml = YAML.safe_load(File.read(file))[locale]
44 # rails wants en-GB but osm-community-index has en_GB
45 locale_rails = locale.tr("_", "-")
48 raw_local_chapters.each do |chapter|
50 resource = chapter[:resource]
52 strings = community_index_yaml[id] || {}
53 # if the name isn't defined then fall back on community,
54 # as per discussion here: https://github.com/osmlab/osm-community-index/issues/483
55 strings["name"] = strings["name"] || resource["strings"]["name"] || resource["strings"]["community"]
57 data.deep_merge!({ "osm_community_index" => { "local_chapter" => { id => strings } } })
60 I18n.backend.store_translations locale_rails, data