6 def self.local_chapters(locale)
7 @local_chapters[locale] ||= local_chapter_for(locale)
10 def self.local_chapter_for(locale)
11 @local_chapters_index ||= load_local_chapters
12 locale_dict = locale_dict_for(locale)
13 localised_chapters = []
14 @local_chapters_index.each do |chapter|
16 name = locale_dict.dig(id, "name") || chapter[:name]
18 localised_chapters.push({ :id => id, :name => name, :url => url })
23 def self.load_local_chapters
24 json_file = File.expand_path("node_modules/osm-community-index/dist/resources.json", Dir.pwd)
25 community_index = JSON.parse(File.read(json_file))
27 community_index["resources"].each do |id, resource|
28 resource.each do |key, value|
29 next unless key == "type" && value == "osm-lc" && id != "OSMF"
31 strings = resource["strings"]
32 chapter_name = strings["name"] || "!! " + strings["community"]
34 local_chapters.push({ :id => id, :name => chapter_name, :url => url })
40 def self.locale_dict_for(locale_in)
41 locale = locale_in.to_s.tr("-", "_")
42 full_local_path = File.expand_path("node_modules/osm-community-index/i18n/#{locale}.yaml", Dir.pwd)
44 if File.exist?(full_local_path)
45 locale_dict = YAML.safe_load(File.read(full_local_path))[locale]
47 shortened_locale = locale.split("_").first
48 if shortened_locale != locale
49 shortened_local_path = File.expand_path("node_modules/osm-community-index/i18n/#{shortened_locale}.yaml", Dir.pwd)
50 locale_dict = YAML.safe_load(File.read(shortened_local_path))[shortened_locale] if File.exist?(shortened_local_path)