mistercrunch commented on code in PR #34118:
URL: https://github.com/apache/superset/pull/34118#discussion_r2201831457
##########
superset-frontend/packages/superset-ui-core/src/translation/Translator.ts:
##########
@@ -86,20 +86,35 @@ 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);
+ logging.warn(err);
+ 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, ...args);
Review Comment:
oh right, good catch, though it looks like it was wrong before too (!?)
Grepping through the repo, it appears `translateWithNumber` is only tied to
`tn('...')` calls, which are not used anywhere except in a few unit tests ...
Not sure what to do:
- delete unused code and references to it?
- fix/improve the function and write unit tests for it?
- [not for this PR], start using `tn()` in more places? Guessing it's meant
to be used in strings like "You saved {num} dashboards(s)"
--
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]