1 module OsmCommunityIndex
3 # Filter the communities here to avoid loading excessive numbers of translations
4 communities = Community.where(:type => "osm-lc").where.not(:id => "OSMF")
6 files = Rails.root.glob("node_modules/osm-community-index/i18n/*.yaml")
8 locale = File.basename(file, ".yaml")
9 community_locale_yaml = YAML.safe_load(File.read(file))[locale]
10 # rails wants language-COUNTRY but osm-community-index uses underscores
11 locale_rails = locale.tr("_", "-")
13 data = communities.each_with_object({}) do |community, obj|
16 strings = community_locale_yaml[id] || {}
17 # if the name isn't defined then fall back on community,
18 # as per discussion here: https://github.com/osmlab/osm-community-index/issues/483
19 strings["name"] = strings["name"] || community.strings["name"] || community.strings["community"]
21 obj.deep_merge!("osm_community_index" => { "communities" => { id => strings } })
24 I18n.backend.store_translations locale_rails, data