8 def self.local_chapters(locale)
9 puts "locale is "+ locale.to_s
10 @local_chapters[locale] = self.local_chapter_for(locale)
15 def self.local_chapter_for(locale)
17 @local_chapters_index = self.load_local_chapters
19 locale_dict = self.locale_dict_for(locale)
21 localised_chapters = []
22 @local_chapters_index.each do |chapter|
24 name = locale_dict.dig(id,"name") || chapter[:name]
26 localised_chapters.push({ id: id, name: name, url: url })
28 puts localised_chapters
32 def self.load_local_chapters
34 json_file = File.expand_path("node_modules/osm-community-index/dist/resources.json", Dir.pwd);
35 community_index = JSON.parse(File.read(json_file))
38 community_index['resources'].each do |id, resource|
39 resource.each do |key, value|
40 if key == "type" and value == "osm-lc" and id != "OSMF"
41 strings = resource['strings']
42 chapter_name = strings['community'] ||strings['name']
44 local_chapters.push({ id: id, name: chapter_name, url: url})
52 def self.locale_dict_for(localeIn)
53 locale = localeIn.to_s.gsub("-","_")
54 full_local_path = File.expand_path("node_modules/osm-community-index/i18n/"+locale+".yaml", Dir.pwd)
56 if File.exists?(full_local_path)
57 locale_dict = YAML.load(File.read(full_local_path))[locale]
59 shortened_locale = locale.split("_").first
60 if shortened_locale != locale
61 shortened_local_path = File.expand_path("node_modules/osm-community-index/i18n/"+shortened_locale+".yaml", Dir.pwd)
62 if File.exists?(shortened_local_path)
63 locale_dict = YAML.load(File.read(shortened_local_path))[shortened_locale]