1 module OsmCommunityIndex
3 attr_reader :id, :name, :url
5 @localised_chapters = {}
7 def initialize(id, name, url)
13 def self.local_chapters_with_locale(locale)
14 load_local_chapter_localisation
15 @localised_chapters[locale] ||= load_local_chapters(locale)
18 def self.load_local_chapter_localisation
19 community_index = OsmCommunityIndex.community_index
20 localisation_files = Dir.children(Rails.root.join("node_modules/osm-community-index/i18n/"))
21 localisation_files.each do |file|
22 locale = File.basename(file,".yaml")
23 # rails wants en-GB but osm-community-index has en_GB
24 locale_rails = locale.split("_").join("-")
25 full_path = Rails.root.join("node_modules/osm-community-index/i18n/#{file}")
26 locale_data = YAML.safe_load(File.read(full_path))[locale]
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 strings = locale_data[id] || {}
33 strings['name'] = locale_data['name'] || resource["strings"]["name"] || resource["strings"]["community"]
36 data["osm_community_index"] = {}
37 data["osm_community_index"]["local_chapter"] = {}
38 data["osm_community_index"]["local_chapter"][id] = strings
39 # data["osm_community_index.local_chapter." + id] = localisation
40 I18n.backend.store_translations locale_rails, data
43 puts locale_rails + " " + id + " " + data.to_s
51 def self.load_local_chapters(locale)
52 community_index = OsmCommunityIndex.community_index
53 localised_strings = OsmCommunityIndex.localised_strings(locale)
55 community_index["resources"].each do |id, resource|
56 resource.each do |key, value|
57 next unless key == "type" && value == "osm-lc" && id != "OSMF"
59 strings = resource["strings"]
60 name = localised_strings.dig(id, "name") || strings["name"] || strings["community"]
62 local_chapters.push(LocalChapter.new(id, name, url))