3 class CountryTest < ActiveSupport::TestCase
4 def test_community_name_fallback
5 # If there is no translations and no name for the chapter, use the community name
6 community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name" } })
7 community_locale_yaml = {}
10 name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
11 assert_equal("Community Name", name)
14 def test_resource_name_fallback
15 # If there is a name for the chapter, prefer that to the community name
16 community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "name" => "Chapter Name" } })
17 community_locale_yaml = {}
18 community_en_yaml = {}
20 name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
21 assert_equal("Chapter Name", name)
24 def test_i18n_explicit_name
25 # If there is an explicitly translated name for the chapter, use that
26 community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "name" => "Chapter Name" } })
27 community_locale_yaml = { "foo-chapter" => { "name" => "Translated Chapter Name" } }
28 community_en_yaml = {}
30 name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
31 assert_equal("Translated Chapter Name", name)
34 def test_i18n_fallback_name
35 # If there's no explicitly translated name for the chapter, use the default name and interpolate the community name if required.
36 community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "communityID" => "communityname" } })
37 community_locale_yaml = { "_communities" => { "communityname" => "Translated Community" }, "_defaults" => { "osm-lc" => { "name" => "{community} Chapter" } } }
38 community_en_yaml = {}
40 name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
41 assert_equal("Translated Community Chapter", name)
44 def test_i18n_invalid_replacement_token
45 # Ignore invalid replacement tokens in OCI data provided. This might happen if translators were mistakenly translating the predefined token ids.
46 community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "communityID" => "communityname" } })
47 community_locale_yaml = { "_communities" => { "communityname" => "Translated Community" }, "_defaults" => { "osm-lc" => { "name" => "{comminauté} Chapter" } } }
48 community_en_yaml = {}
50 name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
51 assert_equal("Community Name", name)