Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Forgiving I18nRegistry.translate for strings with colons and undefined #3907

Merged
merged 3 commits into from
Jan 22, 2025

Conversation

mhsdesign
Copy link
Member

The following node type configuration

placeholder: 'ClientEval: node.properties.tagName'

currently yields an error which is caught by the error boundary for properties:

Error: TranslationAddress must adhere to format "{packageKey}:{sourceName}:{transUnitId}". Got "ClientEval: node.properties.tagName" instead.

The newly added strictness in #3804 introduces this regression here.

Previously the function getTranslationAddress would just attempt to spit a string and expect three items to be returned:

const getTranslationAddress = function (id, packageKey, sourceName) {

The deconstruction would already cause an error in PHP but not in JavaScript:

const [packageKey, sourceName, id] = 'ClientEval: node.properties.tagName'.split(':')

Returns

packageKey: "ClientEval"
sourceName: " node.properties.tagName"
id: undefined

The previous forgiveness needs to be reintroduced as its easy to create errors with strings containing colons at any position which is definitely likely for placeholders. Imagine: placeholder: "The title of the blog:".

What I did

How I did it

How to verify it

The following node type configuration

```yaml
placeholder: 'ClientEval: node.properties.tagName'
```

currently yields an error which is caught by the error boundary for properties:

> Error: TranslationAddress must adhere to format "{packageKey}:{sourceName}:{transUnitId}". Got "ClientEval: node.properties.tagName" instead.

The newly added strictness in neos#3804 introduces this regression here.

Previously the function `getTranslationAddress` would just attempt to spit a string and expect three items to be returned:

https://github.com/neos/neos-ui/blob/2cecfcf136aafcd9e3f72537f513eb81b01e993b/packages/neos-ui-i18n/src/registry/I18nRegistry.js#L7

The deconstruction would already cause an error in PHP but not in JavaScript:

```
const [packageKey, sourceName, id] = 'ClientEval: node.properties.tagName'.split(':')
```

Returns

```
packageKey: "ClientEval"
sourceName: " node.properties.tagName"
id: undefined
```

The previous forgiveness needs to be reintroduced as its easy to create errors with strings containing colons at any position which is definitely likely for placeholders. Imagine: `placeholder: "The title of the blog:"`.
@github-actions github-actions bot added Bug Label to mark the change as bugfix 9.0 labels Jan 20, 2025
…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`.
@mhsdesign mhsdesign changed the title BUGFIX: Forgiving I18nRegistry.translate for strings with colons BUGFIX: Forgiving I18nRegistry.translate for strings with colons and undefined Jan 22, 2025
@mhsdesign
Copy link
Member Author

This could also crash the whole ui in case a string contains a colon in the help message for example for the neos demo:

https://github.com/neos/Neos.Demo/blob/2f8081c3a39ff3b67e4306ff5891ef3bd8923108/NodeTypes/Content/Carousel/Carousel.yaml#L20

image

And in 5520eb4 i fixed that passing no id does not crash as well.

Ill merge this as i could not find a reviewer.

@mhsdesign mhsdesign merged commit 5e9e318 into neos:9.0 Jan 22, 2025
10 checks passed
@mhsdesign mhsdesign deleted the bugfix/forgiving-I18nRegistry-translate branch January 22, 2025 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
9.0 Bug Label to mark the change as bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant