1 module OsmCommunityIndex
3 communities = Community.all
4 files = Dir.glob(Rails.root.join("node_modules/osm-community-index/i18n/*.yaml"))
6 locale = File.basename(file, ".yaml")
7 community_locale_yaml = YAML.safe_load(File.read(file))[locale]
8 # rails wants en-GB but osm-community-index has en_GB
9 locale_rails = locale.tr("_", "-")
11 data = communities.each_with_object({}) do |community, obj|
14 strings = community_locale_yaml[id] || {}
15 # if the name isn't defined then fall back on community,
16 # as per discussion here: https://github.com/osmlab/osm-community-index/issues/483
17 strings["name"] = strings["name"] || community.strings["name"] || community.strings["community"]
19 obj.deep_merge!("osm_community_index" => { "communities" => { id => strings } })
22 I18n.backend.store_translations locale_rails, data