You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2025/07/14 17:23:24 UTC

(superset) branch master updated: fix: frontend translation framework crashes on string errors (#34118)

This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 160917eae8 fix: frontend translation framework crashes on string errors (#34118)
160917eae8 is described below

commit 160917eae87f6710b02cc5ece71ee5ea74610694
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Mon Jul 14 10:23:18 2025 -0700

    fix: frontend translation framework crashes on string errors (#34118)
---
 .../superset-ui-core/src/translation/Translator.ts | 31 +++++++++++++++-------
 superset-frontend/scripts/po2json.sh               |  4 ++-
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/superset-frontend/packages/superset-ui-core/src/translation/Translator.ts b/superset-frontend/packages/superset-ui-core/src/translation/Translator.ts
index d4a6982c8d..bf27ec7ce4 100644
--- a/superset-frontend/packages/superset-ui-core/src/translation/Translator.ts
+++ b/superset-frontend/packages/superset-ui-core/src/translation/Translator.ts
@@ -86,20 +86,33 @@ export default class Translator {
   }
 
   translate(input: string, ...args: unknown[]): string {
-    return this.i18n.translate(input).fetch(...args);
+    try {
+      return this.i18n.translate(input).fetch(...args);
+    } catch (err) {
+      logging.warn(`Translation failed for key "${input}" with args:`, args);
+      return input;
+    }
   }
 
   translateWithNumber(key: string, ...args: unknown[]): string {
-    const [plural, num, ...rest] = args;
-    if (typeof plural === 'number') {
+    try {
+      const [plural, num, ...rest] = args;
+      if (typeof plural === 'number') {
+        return this.i18n
+          .translate(key)
+          .ifPlural(plural, key)
+          .fetch(plural, num, ...rest);
+      }
       return this.i18n
         .translate(key)
-        .ifPlural(plural, key)
-        .fetch(plural, num, ...args);
+        .ifPlural(num as number, plural as string)
+        .fetch(...rest);
+    } catch (err) {
+      logging.warn(
+        `Plural translation failed for key "${key}" with args:`,
+        args,
+      );
     }
-    return this.i18n
-      .translate(key)
-      .ifPlural(num as number, plural as string)
-      .fetch(...rest);
+    return key;
   }
 }
diff --git a/superset-frontend/scripts/po2json.sh b/superset-frontend/scripts/po2json.sh
index 445da0e44c..7ea151fa36 100755
--- a/superset-frontend/scripts/po2json.sh
+++ b/superset-frontend/scripts/po2json.sh
@@ -22,6 +22,8 @@
 
 set -e
 
+export NODE_NO_WARNINGS=1
+
 for file in $( find ../superset/translations/** -name '*.po' );
 do
   extension=${file##*.}
@@ -29,7 +31,7 @@ do
   if [ $extension == "po" ]
   then
     echo "po2json --domain superset --format jed1.x $file $filename.json"
-    po2json --domain superset --format jed1.x $file $filename.json
+    po2json --domain superset --format jed1.x --fuzzy $file $filename.json
     prettier --write $filename.json
   fi
 done