6 def self.local_chapters(locale)
7 @local_chapters[locale] = local_chapter_for(locale)
13 def local_chapter_for(locale)
14 @local_chapters_index = load_local_chapters
15 locale_dict = locale_dict_for(locale)
16 localised_chapters = []
17 @local_chapters_index.each do |chapter|
19 name = locale_dict.dig(id, "name") || chapter[:name]
21 localised_chapters.push({ :id => id, :name => name, :url => url })
26 def load_local_chapters
27 json_file = File.expand_path("node_modules/osm-community-index/dist/resources.json", Dir.pwd)
28 community_index = JSON.parse(File.read(json_file))
30 community_index["resources"].each do |id, resource|
31 resource.each do |key, value|
32 next unless key == "type" && value == "osm-lc" && id != "OSMF"
34 strings = resource["strings"]
35 chapter_name = strings["community"] || strings["name"]
37 local_chapters.push({ :id => id, :name => chapter_name, :url => url })
43 def locale_dict_for(locale_in)
44 locale = locale_in.to_s.tr("-", "_")
45 full_local_path = File.expand_path("node_modules/osm-community-index/i18n/#{locale}.yaml", Dir.pwd)
47 if File.exist?(full_local_path)
48 locale_dict = YAML.safe_load(File.read(full_local_path))[locale]
50 shortened_locale = locale.split("_").first
51 if shortened_locale != locale
52 shortened_local_path = File.expand_path("node_modules/osm-community-index/i18n/#{shortened_locale}.yaml", Dir.pwd)
53 locale_dict = YAML.safe_load(File.read(shortened_local_path))[shortened_locale] if File.exist?(shortened_local_path)