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

!!!FEATURE: Reform i18n mechanism #3804

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

!!!FEATURE: Reform i18n mechanism #3804

wants to merge 38 commits into from

Conversation

grebaldi
Copy link
Contributor

@grebaldi grebaldi commented Jun 14, 2024

prelude to: #3773
refs: #3119

This PR reforms the UI's i18n mechanism by exposing a new function translate directly from the @neos-project/neos-ui-i18n package.

The function looks as follows:

function translate(
    fullyQualifiedTranslationAddressAsString: string,
    fallback: string | [string, string],
    parameters: Parameters = [],
    quantity: number = 0
): string;

And can be used like this:

translate(
  'Neos.Neos:Main:workspaces.allChangesInWorkspaceHaveBeenDiscarded',
  'All changes from workspace "{0}" have been discarded.',
  ['user-admin']
);

// output (en): All changes from workspace "user-admin" have been discarded.

The new mechanism is completely independent from registries. There's no longer a need for injecting the I18nRegistry to use translations, instead translate can be used directly.

translate will only work after the translations have been loaded during the bootstrapping process of @neos-project/neos-ui. If it is used too early, it throws an exception.

The function now also properly supports plural rules (via Intl Web API). Tha I18nRegistry had only supported English plurals, but with broken rules (quantity=0 yielded singular instead of plural).

Other changes included in this PR are:

  • Everything in @neos-project/neos-ui-i18n is now TypeScript (save manifest.js)
  • The <I18n/>-component was deprecated
  • The I18nRegistry is now properly documented, but was also deprecated
  • The xliff.json endpoint is now discovered via <link>-tag, instead of initial data
    • The <link>-tag is marked with prefetch to slightly speed up the fetch request
  • The @neos-project/neos-ui-i18n now has a comprehensive README.md

This change is breaking, because translations may have relied on the broken plural rules. It is also breaking, because the signature for substitution parameters has changed slightly - although this should be non-breaking at runtime.

@grebaldi grebaldi changed the title WIP: Centralize i18n WIP: Reform i18n mechanism Jun 28, 2024
@grebaldi grebaldi changed the title WIP: Reform i18n mechanism !!!FEATURE: Reform i18n mechanism Jun 28, 2024
@grebaldi grebaldi marked this pull request as ready for review June 28, 2024 13:46
@kitsunet kitsunet self-requested a review July 2, 2024 16:55
@kitsunet
Copy link
Member

kitsunet commented Jul 2, 2024

I like this, but wow it's also A LOT. Thanks for digging in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants