Skip to content

Commit 5c2d7db

Browse files
authored
Merge pull request BlackPythonDevs#69 from oleksis/oleksis/issue68
[js] loadLanguage function refactoring
2 parents 7e4869f + 7adcc43 commit 5c2d7db

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

assets/js/bpd.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ if (menuToggle) {
1919

2020
function loadLanguage(lang) {
2121
let base_pathname = window.location.pathname;
22-
let lang_path_regex = /^\/[a-z]+([_-][a-z]+)?\//;
22+
// ISO 639-1 language codes are two-letter codes
23+
// ISO 3166-1 alpha-2 country codes are two-letter codes
24+
let lang_path_regex = /^\/[a-z]{2}([_-][A-Z]{2})?\//;
2325

2426
// Check if the URL path is more than just /path/ and starts with a language code
2527
let path_parts = base_pathname.split("/");

tests/test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ def test_headers_in_language(page: Page, title: str, url: str) -> None:
4242
expect(page).to_have_url(f"{live_server_url}{url}")
4343
lang = page.evaluate("document.documentElement.lang")
4444
assert lang == "es"
45+
46+
47+
def test_switching_lang_es_about(page: Page):
48+
about_path = "/about/"
49+
page.goto(f"{live_server_url}{about_path}")
50+
page.get_by_label("Language").select_option("es")
51+
# http://127.0.0.1:4000/es/about/
52+
expect(page).to_have_url(f"{live_server_url}/es{about_path}")

0 commit comments

Comments
 (0)