From eed271897f903d65891bf6ebd69c13501c2afc31 Mon Sep 17 00:00:00 2001 From: Malte Juergens Date: Wed, 18 Sep 2024 01:44:57 +0200 Subject: [PATCH] Make lw translations work --- assets/mozconfig.new | 2 +- l10n/README.md | 0 .../{preferences.ftl => preferences.inc.ftl} | 0 .../{preferences.ftl => preferences.inc.ftl} | 0 ...{translations.ftl => translations.inc.ftl} | 0 .../chrome/overrides/appstrings.properties | 0 .../{preferences.ftl => preferences.inc.ftl} | 0 ...{translations.ftl => translations.inc.ftl} | 0 ...{translations.ftl => translations.inc.ftl} | 0 scripts/generate-locales.sh | 20 ---------- scripts/librewolf-patches.py | 38 +++++++++++++++++-- 11 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 l10n/README.md rename l10n/de/browser/preferences/{preferences.ftl => preferences.inc.ftl} (100%) rename l10n/en-US/browser/preferences/{preferences.ftl => preferences.inc.ftl} (100%) rename l10n/en-US/browser/{translations.ftl => translations.inc.ftl} (100%) rename {themes/browser/locales => l10n}/en-US/chrome/overrides/appstrings.properties (100%) rename l10n/fr/browser/preferences/{preferences.ftl => preferences.inc.ftl} (100%) rename l10n/fr/browser/{translations.ftl => translations.inc.ftl} (100%) rename l10n/nb_NO/browser/{translations.ftl => translations.inc.ftl} (100%) delete mode 100755 scripts/generate-locales.sh diff --git a/assets/mozconfig.new b/assets/mozconfig.new index 1952f10..2bee00b 100644 --- a/assets/mozconfig.new +++ b/assets/mozconfig.new @@ -17,7 +17,7 @@ ac_add_options --with-branding=browser/branding/librewolf ac_add_options --with-unsigned-addon-scopes=app,system -ac_add_options --with-l10n-base=$PWD/browser/locales/l10n +ac_add_options --with-l10n-base=$PWD/browser/locales ac_add_options --enable-bootstrap diff --git a/l10n/README.md b/l10n/README.md new file mode 100644 index 0000000..e69de29 diff --git a/l10n/de/browser/preferences/preferences.ftl b/l10n/de/browser/preferences/preferences.inc.ftl similarity index 100% rename from l10n/de/browser/preferences/preferences.ftl rename to l10n/de/browser/preferences/preferences.inc.ftl diff --git a/l10n/en-US/browser/preferences/preferences.ftl b/l10n/en-US/browser/preferences/preferences.inc.ftl similarity index 100% rename from l10n/en-US/browser/preferences/preferences.ftl rename to l10n/en-US/browser/preferences/preferences.inc.ftl diff --git a/l10n/en-US/browser/translations.ftl b/l10n/en-US/browser/translations.inc.ftl similarity index 100% rename from l10n/en-US/browser/translations.ftl rename to l10n/en-US/browser/translations.inc.ftl diff --git a/themes/browser/locales/en-US/chrome/overrides/appstrings.properties b/l10n/en-US/chrome/overrides/appstrings.properties similarity index 100% rename from themes/browser/locales/en-US/chrome/overrides/appstrings.properties rename to l10n/en-US/chrome/overrides/appstrings.properties diff --git a/l10n/fr/browser/preferences/preferences.ftl b/l10n/fr/browser/preferences/preferences.inc.ftl similarity index 100% rename from l10n/fr/browser/preferences/preferences.ftl rename to l10n/fr/browser/preferences/preferences.inc.ftl diff --git a/l10n/fr/browser/translations.ftl b/l10n/fr/browser/translations.inc.ftl similarity index 100% rename from l10n/fr/browser/translations.ftl rename to l10n/fr/browser/translations.inc.ftl diff --git a/l10n/nb_NO/browser/translations.ftl b/l10n/nb_NO/browser/translations.inc.ftl similarity index 100% rename from l10n/nb_NO/browser/translations.ftl rename to l10n/nb_NO/browser/translations.inc.ftl diff --git a/scripts/generate-locales.sh b/scripts/generate-locales.sh deleted file mode 100755 index 92294ed..0000000 --- a/scripts/generate-locales.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/bash - -if [ ! -f browser/locales/shipped-locales ]; then - echo "ERROR: Run this script from the root of the LibreWolf source code" - exit 1 -fi - -echo "-> Downloading locales" -rm -rf browser/locales/l10n -curl -o browser/locales/l10n.zip "https://codeload.github.com/mozilla-l10n/firefox-l10n/zip/refs/heads/main" -unzip -qo browser/locales/l10n.zip -d browser/locales/ -mv browser/locales/firefox-l10n-main browser/locales/l10n -rm -f browser/locales/l10n.zip - -sourcedir="$(pwd)" -set -x -cd "../l10n/en-US" -find . -name '*.ftl' -exec sh -c "mkdir -p \$(dirname $sourcedir/{}) && cat {} >> $sourcedir/{}" \; -cd .. -find . -name '*.ftl' -path en-US -prune -exec sh -c "mkdir -p \$(dirname $sourcedir/browser/locales/l10n/{}) && cat {} >> $sourcedir/browser/locales/l10n/{}" \; diff --git a/scripts/librewolf-patches.py b/scripts/librewolf-patches.py index e925caf..ffd2c5d 100755 --- a/scripts/librewolf-patches.py +++ b/scripts/librewolf-patches.py @@ -9,6 +9,8 @@ import os import sys import optparse import time +from pathlib import Path +from tempfile import TemporaryDirectory # @@ -145,9 +147,39 @@ def librewolf_patches(): with open(file, "w") as f: f.write("{}-{}".format(version,release)) - # generate locales - exec("bash ../scripts/generate-locales.sh") - + print("-> Downloading locales from https://github.com/mozilla-l10n/firefox-l10n") + with TemporaryDirectory() as tmpdir: + exec(f"curl -o {tmpdir}/l10n.zip 'https://codeload.github.com/mozilla-l10n/firefox-l10n/zip/refs/heads/main'") + exec(f"unzip -qo {tmpdir}/l10n.zip -d {tmpdir}/l10n") + exec(f"mv {tmpdir}/l10n/firefox-l10n-main/* browser/locales") + + print("-> Applying LibreWolf locales") + l10n_dir = Path("..", "l10n") + for source_path in l10n_dir.rglob("*"): + if source_path.is_dir() or source_path.name.endswith(".md"): + continue + + + + rel_path = source_path.relative_to(l10n_dir) + target_path = Path( + "browser", "locales", + rel_path.parts[0], + *([] if rel_path.parts[0] == "en-US" else ["browser"]) , + *rel_path.parts[1:]) + target_path.parent.mkdir(parents=True, exist_ok=True) + + write_mode = "w" + if ".inc" in target_path.name: + target_path = target_path.with_name(target_path.name.replace(".inc", "")) + write_mode = "a" + + print(f"{source_path} {">" if write_mode == "w" else ">>"} {target_path}") + + with open(target_path, write_mode) as target_file: + with open(source_path, "r") as source_file: + target_file.write(("\n\n" if write_mode == "a" else "") + source_file.read()) + leave_srcdir()