Skip to content

Commit 3fa226d

Browse files
committed
RHIDP-8635-1-1-8 - Comprehensive documentation for developers on adding localization support to custom plugins
1 parent b1a47fe commit 3fa226d

18 files changed

+817
-1
lines changed

assemblies/assembly-configuring-a-floating-action-button.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ You can use the floating action button plugin to configure any action as a float
88

99
include::modules/configuring-a-floating-action-button/proc-configuring-floating-action-button-as-a-dynamic-plugin.adoc[leveloffset=+1]
1010

11+
// Localization
12+
include::modules/configuring-a-floating-action-button/con-localization-support-for-the-floating-action-button.adoc[leveloffset=+1]
13+
// END Localization
14+
1115
include::modules/configuring-a-floating-action-button/ref-floating-action-button-parameters.adoc[leveloffset=+1]

assemblies/assembly-configuring-the-quickstarts.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ include::modules/configuring-the-quickstarts/proc-disabling-rhdh-quickstart.adoc
1212

1313
include::modules/configuring-the-quickstarts/proc-starting-and-completing-modules-in-quickstarts.adoc[leveloffset=+1]
1414

15-
include::modules/configuring-the-quickstarts/con-using-rbac-with-quickstarts.adoc[leveloffset=+1]
15+
include::modules/customizing-the-appearance/proc-enabling-localization-in-quickstarts.adoc[leveloffset=+1]

assemblies/assembly-customizing-the-appearance.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ include::modules/customizing-the-appearance/con-about-rhdh-sidebar-menuitems.ado
3232

3333
include::modules/customizing-the-appearance/proc-customize-rhdh-sidebar-menuitems.adoc[leveloffset=+2]
3434

35+
include::modules/customizing-the-appearance/proc-enabling-localization-in-sidebar-items.adoc[leveloffset=+2]
36+
3537
include::modules/customizing-the-appearance/proc-configuring-dynamic-plugin-menuitem.adoc[leveloffset=+2]
3638

3739
include::modules/customizing-the-appearance/proc-modifying-or-adding-rhdh-custom-menuitem.adoc[leveloffset=+2]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
:_mod-docs-content-type: ASSEMBLY
2+
:context: assembly-localization-in-rhdh
3+
4+
[id="assembly-localization-in-rhdh_{context}"]
5+
= Localization in {product}
6+
7+
include::modules/customizing-the-appearance/proc-enabling-localization-in-rhdh.adoc[leveloffset=+1]
8+
9+
include::modules/customizing-the-appearance/proc-select-rhdh-language.adoc[leveloffset=+1]
10+
11+
include::modules/customizing-the-appearance/con-language-persistence.adoc[leveloffset=+2]
12+
13+
// include::modules/customizing-the-appearance/proc-enabling-localization-in-quickstarts.adoc[leveloffset=+1]
14+
15+
// include::modules/customizing-the-appearance/proc-enabling-localization-in-sidebar-items.adoc[leveloffset=+1]
16+
17+
//include::modules/customizing-the-appearance/proc-enabling-localization-in-floating-action-button.adoc[leveloffset=+1]
18+
19+
== Localization support for plugins
20+
21+
include::modules/customizing-the-appearance/proc-overriding-translations.adoc[leveloffset=+2]
22+
23+
include::modules/customizing-the-appearance/ref-best-practices-for-localization.adoc[leveloffset=+2]
24+
25+
include::modules/customizing-the-appearance/proc-adding-localization-to-custom-plugins.adoc[leveloffset=+2]
26+
50.5 KB
Loading
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[id="proc-enabling-localization-in-floating-action-button_{context}"]
2+
= Enabling floating action button localization in {product-very-short}
3+
4+
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.
5+
6+
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.
7+
8+
The plugin provides the following built-in translation keys organized under the `fab` namespace:
9+
10+
* `fab.create.label` - "Create"
11+
* `fab.create.tooltip` - "Create entity"
12+
* `fab.docs.label` - "Docs"
13+
* `fab.docs.tooltip` - "Documentation"
14+
* `fab.apis.label` - "APIs"
15+
* `fab.apis.tooltip` - "API Documentation"
16+
* `fab.github.label` - "GitHub"
17+
* `fab.github.tooltip` - "GitHub Repository"
18+
* `fab.bulkImport.label` - "Bulk Import"
19+
* `fab.bulkImport.tooltip` - "Register multiple repositories in bulk"
20+
* `fab.quay.label` - "Quay"
21+
* `fab.quay.tooltip` - "Quay Container Registry"
22+
23+
The plugin includes translations for the following supported languages:
24+
25+
* English (default)
26+
// * German (de)
27+
* French (fr)
28+
// * Spanish (es)
29+
30+
// [NOTE]
31+
// ====
32+
// To add localization support for a new floating action button item, you can add any arbitrary key name for the `labelKey` and `toolTipKey` properties and provide corresponding translations for those keys.
33+
34+
// If you add a new floating action button item, you can add localization support by adding an arbitary label key and tool tip key
35+
36+
// ====
37+
38+
To ensure backward compatibility while providing translation support when available, the following order is used to resolve string translations:
39+
40+
. If the `labelKey` is provided, the plugin will attempt to resolve the translation key
41+
. If the translation key is found, it will be used as the label
42+
. If the translation key is not found, the plugin will fall back to the label property
43+
44+
[NOTE]
45+
====
46+
The same logic applies to `toolTipKey` and `toolTip`.
47+
====
48+
49+
== Internal translation implementation
50+
The plugin uses a centralized translation system where:
51+
52+
* The `useTranslation()` hook is called in components that render floating action buttons to ensure proper translation context initialization
53+
* The translation function (`t`) is passed down to child components that need to resolve translation keys
54+
* This internal architecture prevents infinite re-render loops and ensures stable component rendering
55+
* All components that use `CustomFab` must provide the translation function as a prop
56+
57+
[NOTE]
58+
====
59+
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.
60+
====

modules/configuring-a-floating-action-button/proc-configuring-floating-action-button-as-a-dynamic-plugin.adoc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,43 @@ To configure a floating action button as a dynamic plugin, complete any of the f
203203
text: Bulk import
204204
----
205205
`frontend:mountPoints:importName`:: Enter the import name with an associated component to the mount point.
206+
207+
= Translation support
208+
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.
209+
210+
Example for using translation keys in dynamic configuration:
211+
[source,yaml]
212+
----
213+
- package: ./dynamic-plugins/dist/red-hat-developer-hub-backstage-plugin-global-floating-action-button
214+
disabled: false
215+
pluginConfig:
216+
dynamicPlugins:
217+
frontend:
218+
red-hat-developer-hub.backstage-plugin-global-floating-action-button:
219+
translationResources:
220+
- importName: globalFloatingActionButtonTranslations
221+
ref: globalFloatingActionButtonTranslationRef
222+
mountPoints:
223+
- mountPoint: application/listener
224+
importName: DynamicGlobalFloatingActionButton
225+
- mountPoint: global.floatingactionbutton/config
226+
importName: NullComponent
227+
config:
228+
icon: github
229+
label: 'GitHub' # Fallback text
230+
labelKey: 'fab.github.label' # Translation key
231+
toolTip: 'GitHub Repository' # Fallback text
232+
toolTipKey: 'fab.github.tooltip' # Translation key
233+
to: https://github.com/redhat-developer/rhdh-plugins
234+
- mountPoint: global.floatingactionbutton/config
235+
importName: NullComponent
236+
config:
237+
color: 'success'
238+
icon: search
239+
label: 'Create' # Fallback text
240+
labelKey: 'fab.create.label' # Translation key
241+
toolTip: 'Create entity' # Fallback text
242+
toolTipKey: 'fab.create.tooltip' # Translation key
243+
to: '/create'
244+
showLabel: true
245+
----

modules/configuring-a-floating-action-button/ref-floating-action-button-parameters.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Use the parameters as shown in the following table to configure your floating ac
2121
| Not applicable
2222
| Yes
2323

24+
| `labelKey`
25+
| Translation key for the label. If provided, will be used instead of label when translations are available.
26+
| `String`
27+
| Not applicable
28+
| No
29+
2430
| `icon`
2531
| Icon of the floating action button. Recommended to use filled icons from the link:https://fonts.google.com/icons[Material Design library]. You can also use an svg icon. For example: `<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#e8eaed"><g><rect fill="none" height="24" width="24"/></g><g><path d="M11,7L9.6,8.4l2.6,2.6H2v2h10.2l-2.6,2.6L11,17l5-5L11,7z M20,19h-8v2h8c1.1,0,2-0.9,2-2V5c0-1.1-0.9-2-2-2h-8v2h8V19z"/></g></svg>`
2632
| `String`, `React.ReactElement`, `SVG image icon`, `HTML image icon`
@@ -63,6 +69,12 @@ Use the parameters as shown in the following table to configure your floating ac
6369
| Not applicable
6470
| No
6571

72+
| `toolTipKey`
73+
| Translation key for the tooltip. If provided, will be used instead of toolTip when translations are available.
74+
| `String`
75+
| Not applicable
76+
| No
77+
6678
| `priority`
6779
| Order of the floating action buttons displayed in the submenu. A larger value means higher priority.
6880
| `number`
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
:_mod-docs-content-type: CONCEPT
2+
3+
[id="con-language-persistence_{context}"]
4+
= Language persistence
5+
6+
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.
7+
8+
Default language selection uses the following priority order:
9+
10+
. *Browser language priority*: The system first checks the user's browser language preferences to provide a personalized experience.
11+
12+
. *Configuration priority*: If no browser language matches the supported locales, the `defaultLocale` from the `i18n` configuration is used as a fallback.
13+
14+
. *Fallback priority*: If neither browser preferences nor configuration provide a match, defaults to `en`.
15+
16+
{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:
17+
[source,yaml,subs="+quotes"]
18+
----
19+
userSettings:
20+
persistence: browser
21+
----
22+
23+
where:
24+
25+
userSettings:persistence::
26+
Enter `browser` to opt-out and use browser local storage. Optionally, set this value to `database` to persist across browsers and devices. This is the default setting and does not require this configuration to be set.
27+

0 commit comments

Comments
 (0)