Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

README: link the Vietnamese translation from the front page

xbsheng2687dccbf6c5
diff --git a/README.md b/README.md
index 1c318c310..7e1423c3e 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,7 @@
<a href="https://github.com/Gathin23/cleanyourtv/network/members"><img src="https://img.shields.io/github/forks/Gathin23/cleanyourtv?style=flat&cacheSeconds=1800&color=cfffcf&labelColor=15181e" alt="Forks"></a>
<a href="https://github.com/Gathin23/cleanyourtv/graphs/contributors"><img src="https://img.shields.io/github/contributors/Gathin23/cleanyourtv?style=flat&cacheSeconds=1800&color=cfffcf&labelColor=15181e" alt="Contributors"></a>
<a href="README.zh-CN.md"><img src="https://img.shields.io/badge/README-%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87-cfffcf?style=flat&labelColor=15181e" alt="简体中文"></a>
+ <a href="README.vi.md"><img src="https://img.shields.io/badge/README-Ti%E1%BA%BFng%20Vi%E1%BB%87t-cfffcf?style=flat&labelColor=15181e" alt="Tiếng Việt"></a>
<a href="README.ja.md"><img src="https://img.shields.io/badge/README-%E6%97%A5%E6%9C%AC%E8%AA%9E-cfffcf?style=flat&labelColor=15181e" alt="日本語"></a>
<a href="https://buymeacoffee.com/gathint"><img src="https://img.shields.io/badge/support-%E2%9D%A4-ff5e8a?style=flat&labelColor=15181e" alt="Support, buy me a coffee"></a>
<a href="https://www.producthunt.com/products/cleanyourtv"><img src="https://img.shields.io/badge/Product%20Hunt-upvote%20%E2%96%B2-da552f?style=flat&logo=producthunt&logoColor=white&labelColor=15181e" alt="CleanYourTV on Product Hunt"></a>
diff --git a/tests/test_readme_translations.py b/tests/test_readme_translations.py
new file mode 100644
index 000000000..138136982
--- /dev/null
+++ b/tests/test_readme_translations.py
@@ -0,0 +1,97 @@
+"""The front page and its translations link each other.
+
+A translation is only useful if a reader can reach it. README.md is the page everyone lands on, and
+each translation opens with a line that offers the other languages, so a language added to one of
+them and not to the rest leaves readers of that language without a way through. Nothing read those
+links before: README.vi.md was linked from the two other translations and from nowhere on
+README.md.
+
+Every translation is found by its file name, so a fourth one is covered without touching this test.
+Nothing here reads the prose, so translating or rewording any page stays free.
+
+Run from the repository root: python3 -m unittest discover -s tests -v
+"""
+import re
+from pathlib import Path
+import unittest
+
+
+ROOT = Path(__file__).resolve().parents[1]
+FRONT = "README.md"
+TRANSLATION = re.compile(r"^README\.[A-Za-z][A-Za-z-]*\.md$")
+# `[text](target)` and `href="target"`, the two shapes the language rows use.
+LINK = re.compile(r"\]\(([^)\s]+)\)|href=\"([^\"]+)\"")
+
+
+def translations():
+ return sorted(p.name for p in ROOT.iterdir() if p.is_file() and TRANSLATION.match(p.name))
+
+
+def links(text):
+ """The local files a page links to, without anchors or query strings."""
+ found = set()
+ for inline, href in LINK.findall(text):
+ target = (inline or href).split("#")[0].split("?")[0].strip()
+ for prefix in ("https://github.com/Gathin23/cleanyourtv/blob/main/", "blob/main/"):
+ if target.startswith(prefix):
+ target = target[len(prefix):]
+ if target.startswith("./"):
+ target = target[2:]
+ if target and "/" not in target and not target.startswith(("http", "mailto", "data:")):
+ found.add(target)
+ return found
+
+
+def missing(needed, text):
+ """The names in `needed` a page does not link to."""
+ found = links(text)
+ return [name for name in needed if name not in found]
+
+
+class ReadmeTranslationsTest(unittest.TestCase):
+ def test_every_translation_is_found(self):
+ # A regex that matches nothing would make the checks below pass for any set of pages.
+ self.assertGreaterEqual(len(translations()), 3, "no README.<language>.md files were found")
+ self.assertIn("README.vi.md", translations())
+
+ def test_the_front_page_links_every_translation(self):
+ text = (ROOT / FRONT).read_text(encoding="utf-8")
+ self.assertEqual([], missing(translations(), text),
+ "README.md does not link every translation its readers can open")
+
+ def test_every_translation_links_the_front_page_and_the_others(self):
+ every = [FRONT] + translations()
+ for name in translations():
+ with self.subTest(page=name):
+ text = (ROOT / name).read_text(encoding="utf-8")
+ needed = [other for other in every if other != name]
+ self.assertEqual([], missing(needed, text), f"{name} does not link {needed}")
+
+
+class LinkReaderTest(unittest.TestCase):
+ """The reader above has to see the shapes the pages really use, and nothing else."""
+
+ def test_markdown_and_html_links_are_both_read(self):
+ text = "[中文](README.zh-CN.md) · <a href=\"README.ja.md\">日本語</a>"
+ self.assertEqual({"README.zh-CN.md", "README.ja.md"}, links(text))
+
+ def test_an_anchor_and_a_leading_dot_slash_are_dropped(self):
+ self.assertEqual({"README.vi.md"}, links("[vi](./README.vi.md#start)"))
+
+ def test_an_absolute_repository_link_counts(self):
+ text = "[ja](https://github.com/Gathin23/cleanyourtv/blob/main/README.ja.md)"
+ self.assertEqual({"README.ja.md"}, links(text))
+
+ def test_external_links_are_not_files(self):
+ self.assertEqual(set(), links("[site](https://cleanyour.tv) [mail](mailto:a@b) [#top](#top)"))
+
+ def test_a_missing_language_is_reported(self):
+ text = "[English](README.md) · [日本語](README.ja.md)"
+ self.assertEqual(["README.vi.md"], missing([FRONT, "README.ja.md", "README.vi.md"], text))
+
+ def test_a_page_that_links_nothing_reports_everything(self):
+ self.assertEqual([FRONT, "README.vi.md"], missing([FRONT, "README.vi.md"], "no links here"))
+
+
+if __name__ == "__main__":
+ unittest.main()