lang: Run the generated www patch on every boot

install_lang.py generated lang_patch_www.sh, uploaded it and removed it again
right away. Nothing ever referenced the file, so the full install mode only
ever shipped the .lmo catalogue and every string hardcoded in the templates
stayed Chinese.

Keep the script: lang_install.sh moves it into /etc/crontabs/patches next to
lang_patch.sh, and lang_patch.sh runs it on every boot - after the bind mount
and before luci-reload, because the templates live in a tmpfs mirror that is
rebuilt from the read-only squashfs each time. Its output goes to
/tmp/lang_patch_www.log, which lang_uninstall.sh already tried to delete.

lang_uninstall.sh drops the script as well. The <%: %> wrapping itself is not
undone: it disappears with the next reboot, and until then LuCI simply prints
the original text for entries the catalogue does not translate.
pull/175/head
Axel173 2 months ago
parent 1e74a7708e
commit 573a601b6a

@ -65,6 +65,10 @@ fi
mv -f /tmp/base.*.lmo $DIR_PATCH/
mv -f /tmp/lang_patch.sh $DIR_PATCH/
chmod +x $DIR_PATCH/lang_patch.sh
if [ -f /tmp/lang_patch_www.sh ]; then
mv -f /tmp/lang_patch_www.sh $DIR_PATCH/
chmod +x $DIR_PATCH/lang_patch_www.sh
fi
INSTALL_METHOD=2
if [ ! -e "/usr/lib/os-release" ]; then

@ -70,6 +70,12 @@ sed -i 's/ and features\["system"\]\["i18n"\] == "1" //' /usr/lib/lua/luci/view/
rm -rf $SYNCOBJECT2
# Wrap the hardcoded Chinese of the www templates in <%: %> so the LMO can
# translate it. The templates live in the tmpfs mirror mounted above, which is
# rebuilt from the read-only squashfs on every boot, so this has to run here on
# every boot - after the bind mount and before luci-reload.
[ -x $DIR_PATCH/lang_patch_www.sh ] && sh $DIR_PATCH/lang_patch_www.sh > /tmp/lang_patch_www.log 2>&1
echo "lang patched" > $INST_FLAG_FN
MAIN_LANG=$( uci -q get luci.main.lang )

@ -37,8 +37,15 @@ uci commit firewall
rm -rf $DIR_BACKUP
rm -f $DIR_PATCH/lang_patch.sh
rm -f $DIR_PATCH/lang_patch_www.sh
rm -f $DIR_PATCH/base.*.lmo
rm -f $INST_FLAG_FN
rm -f /tmp/lang_patch_www.log
# The <%: %> wrapping applied by lang_patch_www.sh is not undone here: the
# templates under /usr/lib/lua/luci/view live in a tmpfs mirror that is rebuilt
# from the read-only squashfs on every boot, so it disappears by itself. Until
# then the wrapping is harmless - LuCI prints the original text when the
# catalogue holds no translation for it.
rm -f $SYNCOBJECT1
rm -f $SYNCOBJECT2

@ -242,8 +242,9 @@ gw.run_cmd(f"chmod +x {run_script} ; {run_script}", timeout = 17)
time.sleep(1.5)
gw.run_cmd(f"rm -f {fn_remote} ; rm -f {fn_remote_i} ; rm -f {fn_remote_u}")
if full_install:
gw.run_cmd(f"rm -f {fn_www_remote}")
# lang_patch_www.sh is deliberately not removed here: lang_install.sh moves it
# into /etc/crontabs/patches, and should that move not have happened this is the
# only copy left. It lives in tmpfs, so a stale one is gone after a reboot.
prefix = '' if action == 'install' else 'un'
print(f"Ready! The language files are {prefix}installed.")

Loading…
Cancel
Save