1
0
Fork 1
mirror of https://github.com/zen-browser/desktop.git synced 2025-07-07 21:49:58 +02:00

Refactor language pack scripts: replace shell scripts with Python equivalents for improved maintainability and functionality; remove obsolete scripts and update surfer.json formatting.

This commit is contained in:
mr. M 2025-01-13 23:15:37 +01:00
parent 2aaf3f82e6
commit a512948eb0
No known key found for this signature in database
GPG key ID: CBD57A2AEDBDA1FB
8 changed files with 93 additions and 26 deletions

View file

@ -7,6 +7,7 @@ from typing import Optional
METADATA_FILENAME = "surfer.json"
TAGS_API_URL = "https://hg.mozilla.org/releases/mozilla-release/json-tags"
def get_current_version() -> Optional[str]:
"""Retrieve the current version from the metadata file."""
try:
@ -17,6 +18,7 @@ def get_current_version() -> Optional[str]:
print(f"Error reading current version: {e}")
return None
def get_repo_data() -> Optional[str]:
"""Retrieve the repository data from the API."""
try:
@ -28,6 +30,7 @@ def get_repo_data() -> Optional[str]:
print(f"Error retrieving repository data: {e}")
return None
def get_rc_response() -> Optional[str]:
"""Get the release candidate response from the response file."""
try:
@ -68,9 +71,11 @@ def send_webhook(rc: str) -> None:
else:
print("Webhook URL not set.")
def rc_should_be_updated(rc_response: str, current_version: str) -> bool:
return rc_response and rc_response != current_version
def main() -> int:
current_version = get_current_version()
rc_response = get_rc_response()

View file

@ -1,18 +0,0 @@
browser_locales=engine/browser/locales
copy_browser_locales() {
langId=$1
mkdir -p $browser_locales/$langId
if [ "$langId" = "en-US" ]; then
find $browser_locales/$langId -type f -name "zen*" -delete
rsync -av --exclude=.git ./l10n/en-US/browser/ $browser_locales/$langId/
return
fi
rm -rf $browser_locales/$langId/
# TODO: Copy the rest of the l10n directories to their respective locations
rsync -av --exclude=.git ./l10n/$langId/ $browser_locales/$langId/
}
LANG=$1
echo "Copying language pack for $LANG"
copy_browser_locales $LANG

View file

@ -0,0 +1,78 @@
import os
import shutil
import sys
# Define the path for browser locales
BROWSER_LOCALES = "engine/browser/locales"
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)
# Create the directory for the language pack if it doesn't exist
os.makedirs(lang_path, exist_ok=True)
print(f"Creating directory: {lang_path}")
# If the language is 'en-US', handle special processing
if lang_id == "en-US":
# Remove files starting with "zen" in the 'en-US' directory
for root, _, files in os.walk(lang_path):
for file in files:
if file.startswith("zen"):
os.remove(os.path.join(root, file))
# Copy files from the source directory
source_path = "./l10n/en-US/browser/"
copy_files(source_path, lang_path)
return
# For other languages, delete the existing directory and copy files anew
if os.path.exists(lang_path):
shutil.rmtree(lang_path) # Remove existing directory
source_path = f"./l10n/{lang_id}/"
copy_files(source_path, lang_path)
def copy_files(source: str, destination: str):
"""
Copies files and directories from the source to the destination.
:param source: Source directory path
:param destination: Destination directory path
"""
if not os.path.exists(source):
raise FileNotFoundError(f"Source path '{source}' does not exist.")
# Recursively copy all files and directories
for root, dirs, files in os.walk(source):
# Determine relative path to preserve directory structure
relative_path = os.path.relpath(root, source)
destination_root = os.path.join(destination, relative_path)
os.makedirs(destination_root, exist_ok=True)
# Copy files
for file in files:
src_file = os.path.join(root, file)
dest_file = os.path.join(destination_root, file)
print(f"\tCopying {src_file} to {dest_file}")
shutil.copy2(src_file, dest_file) # Copy file with metadata
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script.py <LANG>")
sys.exit(1)
lang = sys.argv[1]
print(f"Copying language pack for {lang}")
try:
copy_browser_locales(lang)
except Exception as e:
print(f"Error: {e}")
sys.exit(1)

View file

@ -31,9 +31,9 @@ cd $CURRENT_DIR
# Move all the files to the correct location
sh scripts/copy-language-pack.sh en-US
python3 scripts/copy-language-pack.sh en-US
for lang in $(cat ./l10n/supported-languages); do
sh scripts/copy-language-pack.sh $lang
python3 scripts/copy-language-pack.sh $lang
done
wait

View file

@ -1 +0,0 @@
sh ./scripts/copy-language-pack.sh en-US

View file

@ -0,0 +1,4 @@
from copy_language_pack import copy_browser_locales
if __name__ == "__main__":
copy_browser_locales("en-US")

View file

@ -5,6 +5,7 @@ import shutil
from check_rc_response import get_rc_response, rc_should_be_updated
def update_rc(last_version: str):
rc_version = get_rc_response()
if rc_should_be_updated(rc_version, last_version):
@ -42,7 +43,7 @@ def get_version_from_file(filename, is_rc):
raise RuntimeError(f"Error reading version from {filename}: {e}")
def update_readme(last_version, new_version, is_rc = False):
def update_readme(last_version, new_version, is_rc=False):
"""Updates the README.md file to reflect the new version."""
prefix = "RC " if is_rc else ""
try:

View file

@ -47,10 +47,8 @@
}
},
"license": {
"ignoredFiles": [
".*\\.json"
],
"ignoredFiles": [".*\\.json"],
"licenseType": "MPL-2.0"
},
"updateHostname": "updates.zen-browser.app"
}
}