diff --git a/scripts/generate_site.py b/scripts/generate_site.py index 5fbadd18f..79d23238c 100644 --- a/scripts/generate_site.py +++ b/scripts/generate_site.py @@ -7750,20 +7750,17 @@ def _distinct_spellings(names: list) -> list[str]: return list(seen.values()) -# Region slugs whose words are not the slug title-cased. -_REGION_WORDS = { - "uk": "UK", - "asia-ntsc": "Asia (NTSC)", - "asia-pal": "Asia (PAL)", - "world": "every region", -} +# Region slugs whose words are not the slug title-cased, beyond region.LABELS. +_REGION_WORDS = {"world": "every region"} def _region_words(value: object, most: int = 0) -> str: """A region: value in words. ``most`` caps the regions named, the rest counted: one Saturn BIOS serves seven.""" raw = value if isinstance(value, list) else [value] if value else [] - words = [_REGION_WORDS.get(str(r), str(r).replace("-", " ").title()) for r in raw] + from region import label # noqa: PLC0415 + + words = [_REGION_WORDS.get(str(r)) or label(str(r)) for r in raw] if most and len(words) > most: words = words[:most] + [f"{len(words) - most} more"] return _said_as_list(words) diff --git a/scripts/packreadme.py b/scripts/packreadme.py index 720f46104..06ee483a3 100644 --- a/scripts/packreadme.py +++ b/scripts/packreadme.py @@ -5,6 +5,7 @@ goes, and which ones the user has to rename.""" from __future__ import annotations +from region import label as region_label from siteguides import INSTALL_PS1, INSTALL_SH, pack_manual def _detect_systems(detect: list[dict]) -> list[str]: @@ -290,9 +291,7 @@ def _build_readme( region_info = "" if regions: - pretty = ", ".join( - " ".join(w.title() for w in slug.split("-")) for slug in regions - ) + pretty = ", ".join(region_label(slug) for slug in regions) region_info = ( "PACK TYPE: Region Filtered\n\n" f" Region priority: {pretty}\n\n" diff --git a/scripts/region.py b/scripts/region.py index bb7cfaf90..52e726d81 100644 --- a/scripts/region.py +++ b/scripts/region.py @@ -107,6 +107,19 @@ ALIASES: dict[str, str] = { } +# Slugs a person does not write title-cased: "Asia Ntsc" read as machine text. +LABELS: dict[str, str] = { + "uk": "UK", + "asia-ntsc": "Asia (NTSC)", + "asia-pal": "Asia (PAL)", +} + + +def label(slug: str) -> str: + """A region slug in words: north-america as North America.""" + return LABELS.get(slug) or " ".join(word.title() for word in slug.split("-")) + + def unknown_region_message(raw: str, aliases: dict[str, str], regions: frozenset[str]) -> str: """What to type instead: the closest spellings, then every short form. diff --git a/tests/test_region.py b/tests/test_region.py index 0d7fb7e72..d0611a975 100644 --- a/tests/test_region.py +++ b/tests/test_region.py @@ -1452,5 +1452,23 @@ class UsaRegionServesTheAmericas(unittest.TestCase): self.assertEqual(region.rank(jpn, requested), 1) +class RegionWordsInAPackReadme(unittest.TestCase): + """The pack README title-cased each slug: asia-ntsc read "Asia Ntsc".""" + + def test_the_priority_line_reads_as_written(self): + from packreadme import _build_readme # noqa: PLC0415 + + readme = _build_readme( + "retroarch", "RetroArch", "system", 1, 1, + regions=region.parse_requested("us,asia-ntsc,jp"), + ) + self.assertIn("Region priority: North America, Asia (NTSC), Japan", readme) + + def test_every_region_has_a_label(self): + for slug in region.REGIONS: + with self.subTest(slug=slug): + self.assertNotRegex(region.label(slug), r"\bNtsc\b|\bPal\b|\bUk\b") + + if __name__ == "__main__": unittest.main()