Skip to content

Commit

Permalink
BUGFIX: Reintroduce graceful handling of empty parameter in `translat…
Browse files Browse the repository at this point in the history
…e()`

the use of

```
i18nRegistry.translate(ui?.help?.message)
```

in

https://github.com/neos/neos-ui/blob/a60961417e7ad49a22b75d48dbe4b2542a25ae5b/packages/neos-ui/src/Containers/Modals/SelectNodeType/nodeTypeItem.js#L60

brings the Ui currently to a fatal crash:

> Message: undefined is not an object (evaluating 'string5.split')

This change reintroduces the old behaviour by returning a possible fallback instead or `undefined`.
  • Loading branch information
mhsdesign committed Jan 22, 2025
1 parent 82219fb commit 5520eb4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/neos-ui-i18n/src/registry/I18nRegistry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,11 @@ test(`

expect(actual).toBe('Singular Translation');
});

test(`
Host > Containers > I18n: Returns undefined if no id is specified`, () => {
const registry = new I18nRegistry('');
const actual = registry.translate(undefined);

expect(actual).toBe(undefined);
});
11 changes: 10 additions & 1 deletion packages/neos-ui-i18n/src/registry/I18nRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const errorCache: Record<string, boolean> = {};
* @deprecated Use `import {translate} from '@neos-project/neos-ui-i18n'` instead
*/
export class I18nRegistry extends SynchronousRegistry<unknown> {
/**
* @deprecated Use `import {translate} from '@neos-project/neos-ui-i18n'` instead
*/
translate(emptyAddress: undefined): undefined;

/**
* Retrieves the translation string that is identified by the given
* identifier. If it is a fully qualified translation address (a string
Expand Down Expand Up @@ -176,13 +181,17 @@ export class I18nRegistry extends SynchronousRegistry<unknown> {
): string;

translate(

Check warning on line 183 in packages/neos-ui-i18n/src/registry/I18nRegistry.ts

View workflow job for this annotation

GitHub Actions / Code style

Method 'translate' has too many parameters (6). Maximum allowed is 5
transUnitIdOrFullyQualifiedTranslationAddress: string,
transUnitIdOrFullyQualifiedTranslationAddress?: string,
explicitlyProvidedFallback?: string,
parameters?: LegacyParameters,
explicitlyProvidedPackageKey: string = 'Neos.Neos',
explicitlyProvidedSourceName: string = 'Main',
quantity: number = 0
) {
if (typeof transUnitIdOrFullyQualifiedTranslationAddress !== 'string' || transUnitIdOrFullyQualifiedTranslationAddress === '') {
// legacy behaviour to guard against undefined
return explicitlyProvidedFallback;
}
const fallback = explicitlyProvidedFallback || transUnitIdOrFullyQualifiedTranslationAddress;
const translationAddress = getTranslationAddress(transUnitIdOrFullyQualifiedTranslationAddress, explicitlyProvidedPackageKey, explicitlyProvidedSourceName);
const translation = this.getTranslation(translationAddress);
Expand Down

0 comments on commit 5520eb4

Please sign in to comment.