diff --git a/locales/language-maps b/locales/language-maps new file mode 100644 index 000000000..e12f62b15 --- /dev/null +++ b/locales/language-maps @@ -0,0 +1 @@ +nb:nb-NO \ No newline at end of file diff --git a/package.json b/package.json index 963e0b0b2..43347ed83 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "sync:raw": "surfer update", "sync:rc": "python3 scripts/update_ff.py --rc", "sync:l10n": "python3 scripts/update_ff.py --just-l10n", - "pretty": "prettier . --write --cache && autopep8 -r --in-place scripts/ src/", + "pretty": "prettier . --write --cache && autopep8 -r --in-place scripts/ src/ --exclude */tests/*", "lint": "npx eslint src/ && prettier . --check --cache", "lint:fix": "npm run pretty && npx eslint src/ --fix", "prepare": "husky", diff --git a/scripts/copy_language_pack.py b/scripts/copy_language_pack.py index eb471b0bf..857cc55d8 100644 --- a/scripts/copy_language_pack.py +++ b/scripts/copy_language_pack.py @@ -10,13 +10,32 @@ import sys BROWSER_LOCALES = "engine/browser/locales" +def get_language_code(lang_id: str) -> str: + """ + Retrieves the language code from the language-maps file. + + :param lang_id: Language identifier (e.g., 'nb', 'fr', etc.) + :return: Corresponding language code (e.g., 'nb-NO', 'fr-FR', etc.) + """ + language_maps_path = os.path.join("locales", "language-maps") + if not os.path.exists(language_maps_path): + return lang_id # Return the original if the file doesn't exist + + with open(language_maps_path, "r", encoding="utf-8") as f: + for line in f: + if line.startswith(f"{lang_id}:"): + return line.split(":", 1)[1].strip() + return lang_id # Return the original if no mapping is found + + def copy_browser_locales(lang_id: str): """ Copies language pack files to the specified browser locale directory. :param lang_id: Language identifier (e.g., 'en-US', 'fr', etc.) """ - lang_path = os.path.join(BROWSER_LOCALES, lang_id) + lang_code = get_language_code(lang_id) + lang_path = os.path.join(BROWSER_LOCALES, lang_code) # Create the directory for the language pack if it doesn't exist os.makedirs(lang_path, exist_ok=True) diff --git a/scripts/download-language-packs.sh b/scripts/download-language-packs.sh index d14b78164..aa4633ef7 100644 --- a/scripts/download-language-packs.sh +++ b/scripts/download-language-packs.sh @@ -39,10 +39,20 @@ fi set -e -update_language() { +get_code_for_language() { + # Get the language code from locales/language-maps langId=$1 + code=$(grep "^$langId:" ./locales/language-maps | cut -d':' -f2) + if [ -z "$code" ]; then + code=$langId + fi + echo $code +} + +update_language() { + langId=$(get_code_for_language $1) cd ./locales - cd $langId + cd $1 echo "Updating $langId" # move the contents from ../firefox-l10n/$langId to ./locales/$langId