mirror of
https://github.com/apache/superset.git
synced 2026-04-07 18:35:15 +00:00
fix: frontend translation framework crashes on string errors (#34118)
This commit is contained in:
committed by
GitHub
parent
68b84acd93
commit
160917eae8
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user