luci-base: dispatcher.uc: ensure usage of dashes in language tags
authorJo-Philipp Wich <jo@mein.io>
Tue, 25 Oct 2022 11:01:31 +0000 (13:01 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 25 Oct 2022 11:01:31 +0000 (13:01 +0200)
The LuCI uci configuration requires language tags with underscores due
limitations of uci option names but the language catalogs themselves
are designated with dash separated language tags.

Make sure to substitute underscores with dashes when determining the
desired request language in order to fix loading of languages such as
`pt-br` or `zh-cn`.

Ref: https://github.com/openwrt/luci/pull/5976#issuecomment-1290352951
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/ucode/dispatcher.uc

index 50c1a7d0f20cddecf2f0f8970933084657b111e7..1d10d7876d17c63eb2f3b9a6d32df31faafe35be 100644 (file)
@@ -103,6 +103,8 @@ function determine_request_language() {
 
        if (lang == 'auto')
                lang = 'en';
+       else
+               lang = replace(lang, '_', '-');
 
        if (load_catalog(lang, '/usr/lib/lua/luci/i18n'))
                change_catalog(lang);