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

Add i18n doc #1904

Merged
merged 29 commits into from
Aug 28, 2023
Merged

Add i18n doc #1904

merged 29 commits into from
Aug 28, 2023

Conversation

gund
Copy link
Contributor

@gund gund commented Jun 5, 2023

Closes HRZ-2942

tolerants
tolerants previously approved these changes Jul 25, 2023

## Translation resources

In order to translate text in Oryx, you can provide translation data in a TS module. You can also integrate those in data provided by a 3rd party translation engine.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by those in this context?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about: "You can also load the text from a 3rd party translation engine."


## Resolve translations from translation resources

The localization of labels is driven by the current language and the translation key. Translations are supposed to be provided as additional lazy loaded resources next to the component implementation, although they can be added as part of the static resources that are loaded in Oryx as well. If the resources are loaded as external resource, they can be provided by an API (e.g. 3rd party service) or by static JSON files.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supposed by whom?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by me...

What about: "Translations are typically provided as lazy loaded resources next to the component implementation"
Or: "Translations can be lazy loaded as separate resources, but can also be part of the component code."


The localization of labels is driven by the current language and the translation key. Translations are supposed to be provided as additional lazy loaded resources next to the component implementation, although they can be added as part of the static resources that are loaded in Oryx as well. If the resources are loaded as external resource, they can be provided by an API (e.g. 3rd party service) or by static JSON files.

Oryx uses the "current" language to "lookup" the available labels. When the language is `en`, the locales for English are being resolved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do the quotation marks imply?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dunno. current can refer to different things. I mean the active language that is used in the frontend.

what about: "Oryx uses the active application language to lookup the available labels."


If a translation key does not match any of the translations, or if the i18n feature is not installed (which is a default behavior), the translation key is auto-converted to a human readable message.

For example, if you have a token that contains multiple parts (e.g. `cart.increase`), you can provide a global translation for just the `increase` part or provide a translation for `cart.increase`. This mechanism allows for a single global translation of `increase` that might affect multiple components throughout multiple components. This provides a consistent and convenient translation mechanism, while remaining flexible to add very specific localizations for some components.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

affect multiple components throughout multiple components Is it possible to avoid the repetition?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about: "This mechanism allows for a single translation of increase that might affect multiple components."

@andriitserkovnyi andriitserkovnyi self-assigned this Aug 14, 2023
@andriitserkovnyi andriitserkovnyi requested a review from a team as a code owner August 14, 2023 08:00
};
```

The translation engine is based on the standardized [ICU message expressions](https://unicode-org.github.io/icu/userguide/format_parse/messages/). The ICU message format defines a standard syntax to handle common translation cases:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which translation engine are talking about?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"order.<count>-items":
"Products ({count, plural, one {{count} item} other {{count} items}})",
};
{% endraw %}```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if it will be an issue in published docs, maybe not,.but in GitHub markdown preview it breaks rendering (code block is not closed)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andriitserkovnyi can you please check? Isn't it because of {% raw %}? But I'm nit really sure.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the updated version, it will look as expected


If a translation key doesn't match any of the translations, or if the i18n feature is not installed (which is the default behavior), the translation key is converted into a human-readable message.

For example, if a token contains multiple parts, like `cart.increase`, you can provide a global translation for just the `increase` part or for `cart.increase`. This mechanism allows for a single translation of `increase` that might affect multiple components. This provides a consistent and convenient translation mechanism while remaining flexible to add specific localizations for some components.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph doesn't fit here, should be in previous point?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It explains exactly auto-conversion logic, doesn't it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for me. it's about providing translations and how translation works, not about auto-conversion of translation tokens?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you have a point here... I'd it fits both sections, but it's better to put it to the previous one. @andriitserkovnyi can you please move it?

dunqan
dunqan previously approved these changes Aug 23, 2023
@VadymSachenko VadymSachenko added in TW review PR is in review by a technical writer new PR contains a new document labels Aug 23, 2023

To support such fine-grained reactivity, a framework specific implementation is required. Oryx provides an `i18n` Lit directive that's used inside components. Using this directive ensures that the DOM is aligned with the localizations in an efficient way. This requires the `@signalAware()` decorator on the component class. To simplify the integration, you can use `I18nMixin` in your component implementation. `I18nMixin` adds `@signalAware()` and exposes the `i18n` function as a method on the component.

<!-- TODO: add link to signal documentation once it's available so users can read about signals and @signalAware decorator -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to resolve this TODO after publishing this PR?

@andriitserkovnyi andriitserkovnyi merged commit 021c590 into master Aug 28, 2023
@andriitserkovnyi andriitserkovnyi deleted the feat-hrz-2942-i18n branch August 28, 2023 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in TW review PR is in review by a technical writer new PR contains a new document
Development

Successfully merging this pull request may close these issues.

8 participants