sadpandajoe commented on code in PR #39724:
URL: https://github.com/apache/superset/pull/39724#discussion_r3875488107


##########
scripts/compile_po.py:
##########
@@ -0,0 +1,203 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# This script is a cross-platform Python equivalent of po2json.sh.
+# It generates .json files from .po translation files used by the frontend.
+
+from __future__ import annotations
+
+import glob
+import os
+import shutil
+import subprocess
+import sys
+from concurrent.futures import as_completed, ThreadPoolExecutor
+
+_SHELL = os.name == "nt"
+
+
+def run_command(command: list[str], cwd: str | None = None, timeout: int = 
120) -> int:
+    try:
+        result = subprocess.run(  # noqa: S603
+            command, text=True, shell=_SHELL, check=False, cwd=cwd, 
timeout=timeout
+        )
+        return result.returncode
+    except (subprocess.TimeoutExpired, FileNotFoundError, OSError):
+        return 1
+
+
+def find_command(names: list[str]) -> str | None:
+    for name in names:
+        if path := shutil.which(name):
+            return path
+    return None
+
+
+def find_node_bin(root_dir: str, bin_name: str) -> str | None:
+    for base in [
+        os.path.join(root_dir, "superset-frontend", "node_modules", ".bin"),
+        os.path.join(root_dir, "node_modules", ".bin"),
+    ]:
+        for ext in ["", ".cmd", ".ps1"]:
+            candidate = os.path.join(base, f"{bin_name}{ext}")
+            if os.path.isfile(candidate):
+                return candidate
+    return None
+
+
+def install_npm_packages(npm_cmd: str, root_dir: str, packages: list[str]) -> 
bool:
+    rc = run_command(
+        [npm_cmd, "install", "--no-save", "--prefer-offline", *packages],
+        cwd=root_dir,
+    )
+    return rc == 0
+
+
+def convert_po_file(po_file: str, po2json_cmd: list[str]) -> tuple[bool, str, 
str]:
+    json_dest = f"{os.path.splitext(po_file)[0]}.json"
+    os.makedirs(os.path.dirname(json_dest), exist_ok=True)
+
+    cmd = [
+        *po2json_cmd,
+        "--domain",
+        "superset",
+        "--format",
+        "jed1.x",
+        "--fuzzy",
+        po_file,
+        json_dest,
+    ]
+    if (rc := run_command(cmd, timeout=60)) != 0:
+        return False, po_file, f"po2json failed (rc={rc})"
+    return True, po_file, ""
+
+
+def compile_translations() -> int:  # noqa: C901
+    root_dir = os.path.abspath(
+        os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+    )
+    translations_dir = os.path.join(root_dir, "superset", "translations")
+    frontend_dir = os.path.join(root_dir, "superset-frontend")
+
+    try:
+        import babel  # noqa: F401
+    except ImportError:
+        print("ERROR: Babel is not installed. Run: pip install babel", 
file=sys.stderr)
+        return 1
+
+    npm_cmd = find_command(["npm"])
+    npx_cmd = find_command(["npx"])
+    if not npm_cmd or not npx_cmd:
+        print("ERROR: Node.js/npm/npx not found in PATH.", file=sys.stderr)
+        return 1
+
+    if not os.path.isdir(translations_dir):
+        print(
+            f"ERROR: translations directory not found: {translations_dir}",
+            file=sys.stderr,
+        )
+        return 1
+
+    print("Step 1: Compiling .po files with pybabel...")
+    rc = run_command(
+        [
+            sys.executable,
+            "-m",
+            "babel.messages.frontend",
+            "compile",
+            "-d",

Review Comment:
   This command omits `--use-fuzzy` even though the project intentionally 
serves fuzzy translations. Running this pipeline overwrites the backend `.mo` 
files without those entries while its JSON output includes them, so backend 
text falls back to English. Should this pass `--use-fuzzy`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to