1 # frozen_string_literal: true
 
   5 class CountryTest < ActiveSupport::TestCase
 
   6   def test_community_name_fallback
 
   7     # If there is no translations and no name for the chapter, use the community name
 
   8     community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name" } })
 
   9     community_locale_yaml = {}
 
  10     community_en_yaml = {}
 
  12     name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
 
  13     assert_equal("Community Name", name)
 
  16   def test_resource_name_fallback
 
  17     # If there is a name for the chapter, prefer that to the community name
 
  18     community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "name" => "Chapter Name" } })
 
  19     community_locale_yaml = {}
 
  20     community_en_yaml = {}
 
  22     name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
 
  23     assert_equal("Chapter Name", name)
 
  26   def test_i18n_explicit_name
 
  27     # If there is an explicitly translated name for the chapter, use that
 
  28     community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "name" => "Chapter Name" } })
 
  29     community_locale_yaml = { "foo-chapter" => { "name" => "Translated Chapter Name" } }
 
  30     community_en_yaml = {}
 
  32     name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
 
  33     assert_equal("Translated Chapter Name", name)
 
  36   def test_i18n_fallback_name
 
  37     # If there's no explicitly translated name for the chapter, use the default name and interpolate the community name if required.
 
  38     community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "communityID" => "communityname" } })
 
  39     community_locale_yaml = { "_communities" => { "communityname" => "Translated Community" }, "_defaults" => { "osm-lc" => { "name" => "{community} Chapter" } } }
 
  40     community_en_yaml = {}
 
  42     name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
 
  43     assert_equal("Translated Community Chapter", name)
 
  46   def test_i18n_invalid_replacement_token
 
  47     # Ignore invalid replacement tokens in OCI data provided. This might happen if translators were mistakenly translating the predefined token ids.
 
  48     community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "communityID" => "communityname" } })
 
  49     community_locale_yaml = { "_communities" => { "communityname" => "Translated Community" }, "_defaults" => { "osm-lc" => { "name" => "{comminauté} Chapter" } } }
 
  50     community_en_yaml = {}
 
  52     name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
 
  53     assert_equal("Community Name", name)