neos-ui
neos-ui copied to clipboard
!!!FEATURE: Reform i18n mechanism
prelude to: https://github.com/neos/neos-ui/pull/3773 refs: https://github.com/neos/neos-ui/issues/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-i18nis now TypeScript (savemanifest.js) - The
<I18n/>-component was deprecated - The
I18nRegistryis now properly documented, but was also deprecated - The
xliff.jsonendpoint is now discovered via<link>-tag, instead of initial data- The
<link>-tag is marked withprefetchto slightly speed up the fetch request
- The
- The
@neos-project/neos-ui-i18nnow 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.