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

TASK: Use new translate() method if possible #3912

Open
wants to merge 15 commits into
base: 9.0
Choose a base branch
from

Conversation

mhsdesign
Copy link
Member

Followup to #3804 which deprecates the use of the component and the i18nRegistry, as this is now a global concept via the translate method.

What I did

Using various careful regex replacements and manual adjustments, commit by commit the translate() method was introduced.

As written here #3804 (comment) the new method does not handle user input gracefully, which is the reason why non static strings are still using the old translation methods to ensure nothing breaks here.

How I did it

How to verify it

Via the regex

translate\('(?!(Neos\.Neos:(Main|Inspector|Modules)|Neos\.Neos\.Ui:(Error|Main|PublishingDialog|SyncWorkspaceDialog)):[a-zA-Z._-]+')

All source files can be checked that each call to translate() now specifies the translation as fully qualified shorthand string.

Replacing the component with a direct call to translate() might not always look correct as this leads to a missing <span /> tag. Those cases have to be identified by eye.

@markusguenther
Copy link
Member

Wow, that’s a lot to take in! I’ll need some time to look into it. Thanks a bunch!

Using the regex

```
<I18n[ \n]+id="([^"]*)"[ \n]+fallback="([^"]*)"[ \n]*/>
```

and replacing it via

```
{translate('$1', '$2')}
```

To target

```
<I18n id="Neos.Neos:Main:cancel" fallback="Cancel"/>
```

And migrate it to

```
{translate('Neos.Neos:Main:cancel', 'Cancel')}
```

Manual adjustments, to adjust the imports and fix cases where the replaced code would have too many braces like here were fixed according to the linter

{someExpression && {translate(...)}}
Using the regex

```
(?<=[ {])(this.props.)?i18nRegistry\.translate\('Neos.
```

and replacing it via

```
translate('Neos.
```

To target all shorthand translations like `Neos.Neos:...` or from Neos.Neos.Ui.

Also adjusted the imports and remove the injections of i18nRegistry if now obsolete
…ss the codebase

Using the regex

```
(?<=[ {])i18nRegistry\.translate\('([^']+)'\)
```

and replacing it via

```
translate('Neos.Neos:Main:$1')
```

To target all translations like `i18nRegistry.translate('copy')` and replace them via `translate('Neos.Neos:Main:copy')`

Also adjusted the imports and remove the injections of i18nRegistry if now obsolete
…ers across the codebase

to shorthand strings

Using the regex

```
(?<=[ {])(?:this.props.)?i18nRegistry\.translate\('([^']+)'\, '([^']+)'\, \{\}, '([^']+)'\, '([^']+)'\)
```

and replacing it via

```
translate('$3:$4:$1', '$2')
```

To target all translations like `i18nRegistry.translate('contentElementsSelected', 'content elements selected', {}, 'Neos.Neos.Ui', 'Main')` and replace them via `translate('Neos.Neos.Ui:Main:contentElementsSelected', 'content elements selected')`

Also adjusted the imports and remove the injections of i18nRegistry if now obsolete
…f possible

oddly (multiline) formatted things could not be targeted via regex replace
The todo references this pr which fixed the return value of `i18nRegistry.translate` long ago:

neos#2594
…script

... and gracefully handle no fallback when used via javascript as this is not linted
Also appends Neos.Neos:Main if necessary, which was forgotten in:

05fe5f8
@mhsdesign mhsdesign force-pushed the task/improve-publishing-translations branch from 86e0b9b to 77e52c2 Compare January 27, 2025 18:35
@mhsdesign mhsdesign marked this pull request as ready for review January 27, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants