-
Notifications
You must be signed in to change notification settings - Fork 55
RHIDP-8635-1 - Comprehensive documentation for developers on adding localization support to custom plugins #1443
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
Changes from 34 commits
19e7af3
9a243fa
d902569
348bc29
2822628
fe7f1d5
a0336d1
31ea439
4a64905
fead28b
0ac0c53
7128efc
9e9d9b6
8a80b35
c27782c
a357528
851d313
863e698
a854520
1d2299b
f80edec
b4acbb6
27f76d4
c2d345e
744683b
a32ba21
0285a12
77316ca
7bc89c6
c7461be
064d75b
91c380a
63b8069
b8fa956
a6cde1f
cac8ecd
b433927
5467d90
fb5e8a4
8d43fec
fab4990
0ed67ed
6d9b857
7e76a5f
7e26249
4afcc34
5550874
959a988
629fd9f
f0cb2d3
eee8f7f
1784af9
ad0722c
4e5f01e
5908549
20814c7
1cdf284
2b31419
a9120d4
3b42cd3
6ef43d3
57f79de
a2be32a
2aa55fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| :_mod-docs-content-type: ASSEMBLY | ||
|
|
||
| [id="assembly-localization-in-rhdh_{context}"] | ||
| = Localization in {product} | ||
|
|
||
| include::modules/customizing-the-appearance/proc-enabling-localization-in-rhdh.adoc[leveloffset=+1] | ||
|
|
||
| include::modules/customizing-the-appearance/proc-overriding-translations.adoc[leveloffset=+2] | ||
|
|
||
| include::modules/customizing-the-appearance/proc-select-rhdh-language.adoc[leveloffset=+1] | ||
|
|
||
| include::modules/customizing-the-appearance/con-language-persistence.adoc[leveloffset=+2] | ||
|
|
||
| // include::modules/customizing-the-appearance/proc-enabling-localization-in-quickstarts.adoc[leveloffset=+1] | ||
|
|
||
| // include::modules/customizing-the-appearance/proc-enabling-localization-in-sidebar-items.adoc[leveloffset=+1] | ||
|
|
||
| //include::modules/customizing-the-appearance/proc-enabling-localization-in-floating-action-button.adoc[leveloffset=+1] | ||
|
|
||
| == Localization support for custom plugins | ||
|
|
||
| include::modules/customizing-the-appearance/ref-best-practices-for-localization.adoc[leveloffset=+2] | ||
|
|
||
| include::modules/customizing-the-appearance/proc-adding-localization-to-custom-plugins.adoc[leveloffset=+2] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| [id="proc-enabling-localization-in-floating-action-button_{context}"] | ||
| = Enabling floating action button localization in {product-very-short} | ||
|
|
||
| You can enable translation key support for floating action buttons, so that users can onboard in their preferred language. In {product-short}, all existing and newly created floating action buttons support localization using dedicated translation keys. | ||
|
|
||
| The Global Floating Action Button plugin supports internationalization (i18n) through translation keys. You can use `labelKey` and `toolTipKey` properties to provide translation keys instead of static text. | ||
Gerry-Forde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| == Built-in translation keys | ||
| The plugin provides built-in translation keys organized under the `fab` namespace: | ||
Gerry-Forde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| * `fab.create.label` - "Create" | ||
| * `fab.create.tooltip` - "Create entity" | ||
| * `fab.docs.label` - "Docs" | ||
| * `fab.docs.tooltip` - "Documentation" | ||
| * `fab.apis.label` - "APIs" | ||
| * `fab.apis.tooltip` - "API Documentation" | ||
| * `fab.github.label` - "GitHub" | ||
| * `fab.github.tooltip` - "GitHub Repository" | ||
| * `fab.bulkImport.label` - "Bulk Import" | ||
| * `fab.bulkImport.tooltip` - "Register multiple repositories in bulk" | ||
| * `fab.quay.label` - "Quay" | ||
| * `fab.quay.tooltip` - "Quay Container Registry" | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should also be mentioned that if users want to support localization for a new FAB item, add any arbitrary keys for labelKey and toolTipKey, they must also provide corresponding translations for those keys. This process is similar to what’s described in the Quickstart documentation: |
||
| == Supported languages | ||
| The plugin includes translations for: | ||
Gerry-Forde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| * English (default) | ||
| // * German (de) | ||
| * French (fr) | ||
| // * Spanish (es) | ||
|
|
||
| == Ensuring backward compatibility when providing translation support | ||
Gerry-Forde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| To ensure backward compatibility while providing translation support when available, the following order is used to resolve string translations: | ||
|
|
||
| . If the `labelKey` is provided, the plugin will attempt to resolve the translation key | ||
| . If the translation key is found, it will be used as the label | ||
| . If the translation key is not found, the plugin will fall back to the label property | ||
|
|
||
| [NOTE] | ||
| The same logic applies to `toolTipKey` and `toolTip`. | ||
Gerry-Forde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| == Internal translation implementation | ||
| The plugin uses a centralized translation system where: | ||
|
|
||
| * The `useTranslation()` hook is called in components that render floating action buttons to ensure proper translation context initialization | ||
| * The translation function (`t`) is passed down to child components that need to resolve translation keys | ||
| * This internal architecture prevents infinite re-render loops and ensures stable component rendering | ||
| * All components that use `CustomFab` must provide the translation function as a prop | ||
|
|
||
| [NOTE] | ||
| When extending or modifying the plugin components, ensure that the `useTranslation()` hook is called in parent components and the `t` prop is passed to `CustomFab` instances to maintain proper translation functionality and prevent rendering issues. | ||
Gerry-Forde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -203,3 +203,40 @@ To configure a floating action button as a dynamic plugin, complete any of the f | |
| text: Bulk import | ||
| ---- | ||
| `frontend:mountPoints:importName`:: Enter the import name with an associated component to the mount point. | ||
|
|
||
| = Translation support | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @its-mitesh-kumar Could you please provide a technical review of this section of the guide. |
||
| The Global Floating Action Button plugin supports internationalization (i18n) through translation keys. You can use `labelKey` and `toolTipKey` properties to provide translation keys instead of static text. | ||
Gerry-Forde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| .Example using translation keys in dynamic configuration | ||
Gerry-Forde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [source,yaml] | ||
| ---- | ||
| - package: ./dynamic-plugins/dist/red-hat-developer-hub-backstage-plugin-global-floating-action-button | ||
| disabled: false | ||
| pluginConfig: | ||
| dynamicPlugins: | ||
| frontend: | ||
| red-hat-developer-hub.backstage-plugin-global-floating-action-button: | ||
| mountPoints: | ||
| - mountPoint: application/listener | ||
| importName: DynamicGlobalFloatingActionButton | ||
Gerry-Forde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - mountPoint: global.floatingactionbutton/config | ||
| importName: NullComponent | ||
| config: | ||
| icon: github | ||
| label: 'GitHub' # Fallback text | ||
| labelKey: 'fab.github.label' # Translation key | ||
| toolTip: 'GitHub Repository' # Fallback text | ||
| toolTipKey: 'fab.github.tooltip' # Translation key | ||
| to: https://github.com/redhat-developer/rhdh-plugins | ||
| - mountPoint: global.floatingactionbutton/config | ||
| importName: NullComponent | ||
| config: | ||
| color: 'success' | ||
| icon: search | ||
| label: 'Create' # Fallback text | ||
| labelKey: 'fab.create.label' # Translation key | ||
| toolTip: 'Create entity' # Fallback text | ||
| toolTipKey: 'fab.create.tooltip' # Translation key | ||
| to: '/create' | ||
| showLabel: true | ||
| ---- | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| :_mod-docs-content-type: CONCEPT | ||
|
|
||
| [id="con-language-persistence_{context}"] | ||
| = Language persistence | ||
|
|
||
| When you change the language in the UI, your preference is saved to storage. On next login or refresh, your chosen language setting is restored. Guest users cannot persist language preferences. | ||
|
|
||
| Default language selection uses the following priority order: | ||
|
|
||
| . *Browser language priority*: The system first checks the user's browser language preferences to provide a personalized experience. | ||
|
|
||
| . *Configuration priority*: If no browser language matches the supported locales, the `defaultLocale` from the `i18n` configuration is used as a fallback. | ||
|
|
||
| . *Fallback priority*: If neither browser preferences nor configuration provide a match, defaults to `en`. | ||
|
|
||
| {product} automatically saves and restores user language settings across browser sessions. This feature is enabled by default and uses database storage. To opt-out and use browser storage instead, add the following to your `{my-app-config-file}` configuration file: | ||
| [source,yaml,subs="+quotes"] | ||
| ---- | ||
| userSettings: | ||
| persistence: browser # <1> | ||
| ---- | ||
| <1> To opt-out and use browser local storage, set this value to `browser`. Optionally, set this value to `database` to persist across browsers and devices. This the default setting and does not require this configuration to be set. | ||
Gerry-Forde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest creating a separate assembly,
Localization Support for Custom Plugins, for these modules, unless we’re fine keeping them in the same assembly. Otherwise, we can address this after the release.”