-
Notifications
You must be signed in to change notification settings - Fork 11
Add proper translation support for all UI strings including data structure patterns #592
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
base: main
Are you sure you want to change the base?
Conversation
…n methods Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Apollon77
left a comment
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.
@copilot This is a great start. Please also check other places.
When we build UI relevant data structs then we have constructs like in
ioBroker.matter/src/matter/GeneralMatterNode.ts
Lines 1204 to 1205 in 06dbbdc
| result.rootEndpointClusters[`__header__${client.name}`] = decamelize(client.name); | |
| result.rootEndpointClusters[`${client.name}__Features`] = activeFeatures.length |
So label__TEXT is shown as label with "*" being the text ... the second line with whateverId__TEXT is also such amn example where TEXT is used in the UI.
So the pattern to look for is like object structures with "" in it in methods called from getNodeDetails() calls.
Other such examples are handled by the code in
ioBroker.matter/src/lib/JsonConfigUtils.ts
Lines 27 to 47 in 06dbbdc
| if (tabItem.startsWith('__header__')) { | |
| tabItems[flatKey] = { | |
| type: 'header', | |
| text: String(data[tab][tabItem]), | |
| noTranslation: true, | |
| }; | |
| continue; | |
| } | |
| if (tabItem.startsWith('__text__')) { | |
| tabItems[flatKey] = { | |
| type: 'staticText', | |
| text: String(data[tab][tabItem]), | |
| }; | |
| continue; | |
| } | |
| if (tabItem.startsWith('__smalltext__')) { | |
| tabItems[flatKey] = { | |
| type: 'staticText', | |
| text: String(data[tab][tabItem]), | |
| style: { fontSize: 10, fontStyle: 'italic', marginTop: -8 }, | |
| }; |
So the "getText" or t() call should go in these tooling classes but all relevant texts themself for the "en" file with the base texts need to be found in all code
…data structures Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
I've updated the code to handle translations for JsonConfigUtils.ts:
Updated files:
Examples:
All data structure texts that appear in UIs are now properly translated. Commit: a323407 |
Overview
This PR addresses the issue of hardcoded English strings in the adapter by implementing proper translation support using ioBroker's
t()andgetText()methods. All user-facing strings that appear in the UI are now externalized to the translation system, making the adapter ready for multi-language support.This includes both direct UI strings (dialog titles, messages, labels) and strings embedded in data structures using
__header__,__text__, and__smalltext__patterns.Changes
Translation Keys Added
Added 37 new translation keys to
src/lib/i18n/en.json:Code Updates
JsonConfigUtils.ts (New)
convertDataToJsonConfig()to accept optionaladapterparameter__header__,__text__, and__smalltext__values are translated usingadapter.getText()noTranslation: truewhen adapter not providedDeviceManagement.ts
getText()ioBroker.StringOrTranslatedtype for proper type safetyt()methodconvertDataToJsonConfig()main.ts
getText()callst()with proper string keysconvertDataToJsonConfig()GeneralMatterNode.ts
t('Own')for proper translationt()with parameters:Interface %s "%s"t()BaseServerNode.ts
getText()t()methodconvertDataToJsonConfig()BridgedDevicesNode.ts (New)
t()with parametersUtilityOnlyToIoBroker.ts (New)
t()with device type parameterGenericDeviceToMatter.ts (New)
t()with endpoint number parameterTranslation Method Usage
Following ioBroker best practices:
getText(): Used for titles and descriptions where the frontend needs the full language objectt(): Used for error messages and single strings where the backend determines the languaget()with parameters: Used for dynamic strings with placeholders (e.g.,'Interface %s "%s"','Endpoint %s')__header__,__text__,__smalltext__now translated viaJsonConfigUtilsTesting
Next Steps
The translation keys are currently only in English (
en.json). Other language files will be populated with translations in a follow-up task as per project workflow.Fixes the issue by ensuring all UI-visible strings use the proper translation infrastructure, including those embedded in data structures.
Fixes #349
Original prompt
Fixes #349
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.