webrecorder / pywb

Core Python Web Archiving Toolkit for replay and recording of web archives
https://pypi.python.org/pypi/pywb
GNU General Public License v3.0
1.34k stars 207 forks source link

switch_locale not adding locale if missing from URL #870

Closed Quirinus closed 7 months ago

Quirinus commented 8 months ago

Describe the bug

If switch_locale(locale) is used and the URI doesn't have the language code in it, it will produce URLs without it. That means if the URL is e.g. https://localhost:8080/test/ and switch_locale("hr") or switch_locale("en") is used, it will give https://localhost:8080/test/ instead of https://localhost:8080/hr/test/. It works fine if the language code is in the URI - https://localhost:8080/hr/test/ and switch_locale("en") produces https://localhost:8080/en/test/.

Steps to reproduce the bug

Install pywb and i18n package, add two languages for translations, open a pywb page without the language code in the URI. I have "en" and "hr", with "hr" set as default in the config.yaml. The language switch links produced using {{ switch_locale(locale) }} in the template in the top right will point to the same URI (for "hr" and "en" both), without the language codes - so it won't switch the language.

Expected behavior

If switch_locale(locale) is used with a URI that doesn't have the language code, it should produce URLs that contain the language code. That means the language switch links in the top right of pages should contain the correct URLs and switch languages accordingly.

Screenshots

image

Notice the current URL for a collection named "test" (not containing any language code in the URL). I hovered the mouse over the link to change the locale to "hr" (top right), and the URL that is in that link is shown on bottom left - it doesn't contain "hr". Same happens when I hover over "en".

Environment

Additional context

None.