Add localization support for Talker Flutter package#463
Add localization support for Talker Flutter package#463f-ever wants to merge 1 commit intoFrezyx:masterfrom
Conversation
Reviewer's GuideAdds a full localization layer to the Talker Flutter package, replacing hard-coded UI strings with generated localization classes, exposing localization helpers to consumers, wiring delegates/locales into the example app, and documenting how to use the new localization support. Sequence diagram for localized string lookup via BuildContext.l10nsequenceDiagram
actor User
participant Device as DeviceLocale
participant MaterialApp
participant Delegate as TalkerFlutterLocalizationsDelegate
participant L10nEn as TalkerFlutterLocalizationsEn
participant L10nZh as TalkerFlutterLocalizationsZh
participant Widget as TalkerMonitor
participant Ctx as BuildContext
participant Ext as BuildContextL10n
User->>Device: Set preferred language (en or zh)
User->>MaterialApp: Launch app
MaterialApp->>Delegate: load(locale)
alt locale.languageCode == en
Delegate-->>MaterialApp: L10nEn instance
else locale.languageCode == zh
Delegate-->>MaterialApp: L10nZh instance
end
User->>Widget: Open TalkerMonitor screen
Widget->>Ctx: access context
Widget->>Ext: context.l10n
Ext->>TalkerFlutterLocalizations: TalkerFlutterLocalizations.of(context)
alt localization instance found
TalkerFlutterLocalizations-->>Ext: current L10nEn or L10nZh
Ext-->>Widget: localized instance
else no instance (fallback)
TalkerFlutterLocalizations-->>Ext: null
Ext-->>Widget: new L10nEn()
end
Widget->>Widget: read l10n.talkerMonitor, l10n.httpRequests, etc.
Widget-->>User: Render UI with localized strings
Class diagram for TalkerFlutter localization layerclassDiagram
direction LR
class TalkerFlutterLocalizations {
<<abstract>>
+String localeName
+TalkerFlutterLocalizations(locale)
+static TalkerFlutterLocalizations? of(context)
+static List~LocalizationsDelegate~ localizationsDelegates
+static List~Locale~ supportedLocales
+String get talkerMonitor
+String talkerMonitorType(typeName)
+String get settings
+String get talkerSettings
+String get packagesSettings
+String get enabled
+String get useConsoleLogs
+String get useHistory
+String get reverseLogs
+String get copyAllLogs
+String get copyFilteredLogs
+String get expandLogs
+String get collapseLogs
+String get cleanHistory
+String get shareLogsFile
+String get logItemCopied
+String get allLogsCopied
+String get filteredLogsCopied
+String get undo
+String get errors
+String get exceptions
+String get warnings
+String get infos
+String get verboseDebug
+String get httpRequests
+String httpRequestsExecuted(count)
+String successfulResponses(count)
+String get responsesReceived
+String failureResponses(count)
+String unresolvedErrors(count)
+String unresolvedExceptions(count)
+String warningsCount(count)
+String infoLogsCount(count)
+String verboseDebugLogsCount(count)
+String get talkerActions
+String get errorOccurred
+String get data
+String get type
+String get search
}
class TalkerFlutterLocalizationsEn {
+TalkerFlutterLocalizationsEn(locale)
+String talkerMonitor
+String talkerMonitorType(typeName)
+String settings
+String talkerSettings
+String packagesSettings
+String enabled
+String useConsoleLogs
+String useHistory
+String reverseLogs
+String copyAllLogs
+String copyFilteredLogs
+String expandLogs
+String collapseLogs
+String cleanHistory
+String shareLogsFile
+String logItemCopied
+String allLogsCopied
+String filteredLogsCopied
+String undo
+String errors
+String exceptions
+String warnings
+String infos
+String verboseDebug
+String httpRequests
+String httpRequestsExecuted(count)
+String successfulResponses(count)
+String responsesReceived
+String failureResponses(count)
+String unresolvedErrors(count)
+String unresolvedExceptions(count)
+String warningsCount(count)
+String infoLogsCount(count)
+String verboseDebugLogsCount(count)
+String talkerActions
+String errorOccurred
+String data
+String type
+String search
}
class TalkerFlutterLocalizationsZh {
+TalkerFlutterLocalizationsZh(locale)
+String talkerMonitor
+String talkerMonitorType(typeName)
+String settings
+String talkerSettings
+String packagesSettings
+String enabled
+String useConsoleLogs
+String useHistory
+String reverseLogs
+String copyAllLogs
+String copyFilteredLogs
+String expandLogs
+String collapseLogs
+String cleanHistory
+String shareLogsFile
+String logItemCopied
+String allLogsCopied
+String filteredLogsCopied
+String undo
+String errors
+String exceptions
+String warnings
+String infos
+String verboseDebug
+String httpRequests
+String httpRequestsExecuted(count)
+String successfulResponses(count)
+String responsesReceived
+String failureResponses(count)
+String unresolvedErrors(count)
+String unresolvedExceptions(count)
+String warningsCount(count)
+String infoLogsCount(count)
+String verboseDebugLogsCount(count)
+String talkerActions
+String errorOccurred
+String data
+String type
+String search
}
class _TalkerFlutterLocalizationsDelegate {
+Future~TalkerFlutterLocalizations~ load(locale)
+bool isSupported(locale)
+bool shouldReload(old)
}
class BuildContextL10n {
+TalkerFlutterLocalizations l10n
}
class TalkerWrapperOptions {
-String~null~ _exceptionTitle
-String~null~ _errorTitle
+TalkerWrapperOptions(exceptionTitle,errorTitle,exceptionAlertBuilder,errorAlertBuilder,enableErrorAlerts,enableExceptionAlerts)
+String exceptionTitle(context)
+String errorTitle(context)
+TalkerExceptionBuilder~null~ exceptionAlertBuilder
+TalkerErrorBuilder~null~ errorAlertBuilder
+bool enableErrorAlerts
+bool enableExceptionAlerts
}
class TalkerWrapper {
+TalkerWrapperOptions options
+Widget build(context)
}
class SnackbarContent {
+SnackbarContent(message,title,dismissButton,dismissButtonText,messageTextStyle)
+Widget build(context)
}
TalkerFlutterLocalizations <|-- TalkerFlutterLocalizationsEn
TalkerFlutterLocalizations <|-- TalkerFlutterLocalizationsZh
TalkerFlutterLocalizations ..> _TalkerFlutterLocalizationsDelegate
_TalkerFlutterLocalizationsDelegate ..> TalkerFlutterLocalizationsEn
_TalkerFlutterLocalizationsDelegate ..> TalkerFlutterLocalizationsZh
BuildContextL10n ..> TalkerFlutterLocalizations : returns
BuildContextL10n ..> TalkerFlutterLocalizationsEn : fallback
TalkerWrapperOptions ..> BuildContextL10n : uses
TalkerWrapper ..> TalkerWrapperOptions : has
TalkerWrapper ..> SnackbarContent : creates
SnackbarContent ..> BuildContextL10n : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues, and left some high level feedback:
- The HTTP response summary strings are built by concatenating
successfulResponses/failureResponseswith a separateresponsesReceivedsuffix, which makes it hard to localize languages with different word order; consider making the full sentence (including count and “responses received”) a single interpolated localization string instead. - You’ve added
l10n.yamland empty ARB files while also checking in a hand-writtentalker_flutter_localizations.dart; it would be clearer to either remove the unused gen-l10n config or switch fully to ARB-based generation so the source of truth for strings is unambiguous.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The HTTP response summary strings are built by concatenating `successfulResponses`/`failureResponses` with a separate `responsesReceived` suffix, which makes it hard to localize languages with different word order; consider making the full sentence (including count and “responses received”) a single interpolated localization string instead.
- You’ve added `l10n.yaml` and empty ARB files while also checking in a hand-written `talker_flutter_localizations.dart`; it would be clearer to either remove the unused gen-l10n config or switch fully to ARB-based generation so the source of truth for strings is unambiguous.
## Individual Comments
### Comment 1
<location> `packages/talker_flutter/lib/l10n/talker_flutter_localizations_zh.dart:94-102` </location>
<code_context>
+ }
+
+ @override
+ String successfulResponses(int count) {
+ return '$count successful';
+ }
+
+ @override
+ String get responsesReceived => ' responses received';
+
+ @override
+ String failureResponses(int count) {
+ return '$count failure';
+ }
</code_context>
<issue_to_address>
**issue:** Splitting the Chinese messages into `successfulResponses` + `responsesReceived` leads to awkward phrasing like “N 个成功 个响应已接收”.
This composition works in English (“N successful responses received”) but produces unnatural Chinese:
- `successfulResponses`: `'$count 个成功'`
- `responsesReceived`: `' 个响应已接收'`
⇒ “$count 个成功 个响应已接收”, which is grammatically off, and the same applies to `failureResponses`.
To support natural Chinese, consider localizing the full sentence instead of concatenating fragments, e.g.:
```dart
String successfulResponsesSummary(int count); // '$count 个成功响应已接收'
String failureResponsesSummary(int count); // '$count 个失败响应已接收'
```
If you can’t change the API, another option is to special‑case Chinese so `successfulResponses` returns the full phrase and `responsesReceived` isn’t appended for that locale.
</issue_to_address>
### Comment 2
<location> `packages/talker_flutter/l10n.yaml:3-4` </location>
<code_context>
+arb-dir: lib/l10n
+template-arb-file: app_en.arb
+output-localization-file: talker_flutter_localizations.dart
+output-class: TalkerFlutterLocalizations
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `l10n.yaml` with effectively empty ARB files may cause `gen-l10n` to overwrite the hand-maintained localization classes.
`l10n.yaml` currently directs `flutter gen-l10n` to overwrite `talker_flutter_localizations.dart`, but the ARB files are empty and the Dart file appears hand-edited. If `gen-l10n` is run, it will likely replace the existing implementation with an almost empty generated file.
To avoid accidental clobbering, either:
- Move the existing messages into the ARBs and treat the Dart file as generated, or
- Change/remove this `output-localization-file` target, or
- Add a clear guard (comment or tooling) that `gen-l10n` should not be run here.
This will keep localization behavior aligned with the actual implementation and safer to maintain.
</issue_to_address>
### Comment 3
<location> `README.md:421` </location>
<code_context>
+locale: const Locale('zh')
+```
+
+All TalkerScreen UI elements, including error messages, action buttons, settings labels, and monitor information will be automatically translated based on the device locale or your specified locale.
+
### ❗️ Log messages integrity
</code_context>
<issue_to_address>
**suggestion (typo):** Add a comma to close the non-restrictive "including" clause for correct grammar.
Specifically, add a comma after "monitor information" so the sentence reads: "All TalkerScreen UI elements, including error messages, action buttons, settings labels, and monitor information, will be automatically translated based on the device locale or your specified locale."
```suggestion
All TalkerScreen UI elements, including error messages, action buttons, settings labels, and monitor information, will be automatically translated based on the device locale or your specified locale.
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| String successfulResponses(int count) { | ||
| return '$count 个成功'; | ||
| } | ||
|
|
||
| @override | ||
| String get responsesReceived => ' 个响应已接收'; | ||
|
|
||
| @override | ||
| String failureResponses(int count) { |
There was a problem hiding this comment.
issue: Splitting the Chinese messages into successfulResponses + responsesReceived leads to awkward phrasing like “N 个成功 个响应已接收”.
This composition works in English (“N successful responses received”) but produces unnatural Chinese:
successfulResponses:'$count 个成功'responsesReceived:' 个响应已接收'
⇒ “$count 个成功 个响应已接收”, which is grammatically off, and the same applies to failureResponses.
To support natural Chinese, consider localizing the full sentence instead of concatenating fragments, e.g.:
String successfulResponsesSummary(int count); // '$count 个成功响应已接收'
String failureResponsesSummary(int count); // '$count 个失败响应已接收'If you can’t change the API, another option is to special‑case Chinese so successfulResponses returns the full phrase and responsesReceived isn’t appended for that locale.
| output-localization-file: talker_flutter_localizations.dart | ||
| output-class: TalkerFlutterLocalizations |
There was a problem hiding this comment.
issue (bug_risk): Using l10n.yaml with effectively empty ARB files may cause gen-l10n to overwrite the hand-maintained localization classes.
l10n.yaml currently directs flutter gen-l10n to overwrite talker_flutter_localizations.dart, but the ARB files are empty and the Dart file appears hand-edited. If gen-l10n is run, it will likely replace the existing implementation with an almost empty generated file.
To avoid accidental clobbering, either:
- Move the existing messages into the ARBs and treat the Dart file as generated, or
- Change/remove this
output-localization-filetarget, or - Add a clear guard (comment or tooling) that
gen-l10nshould not be run here.
This will keep localization behavior aligned with the actual implementation and safer to maintain.
| locale: const Locale('zh') | ||
| ``` | ||
|
|
||
| All TalkerScreen UI elements, including error messages, action buttons, settings labels, and monitor information will be automatically translated based on the device locale or your specified locale. |
There was a problem hiding this comment.
suggestion (typo): Add a comma to close the non-restrictive "including" clause for correct grammar.
Specifically, add a comma after "monitor information" so the sentence reads: "All TalkerScreen UI elements, including error messages, action buttons, settings labels, and monitor information, will be automatically translated based on the device locale or your specified locale."
| All TalkerScreen UI elements, including error messages, action buttons, settings labels, and monitor information will be automatically translated based on the device locale or your specified locale. | |
| All TalkerScreen UI elements, including error messages, action buttons, settings labels, and monitor information, will be automatically translated based on the device locale or your specified locale. |
Add Localization Support
Summary
Added internationalization support to Talker Flutter package, allowing the UI to display in multiple languages.
Key Changes
l10n.yamlconfigurationSupported Languages
Usage
The package now automatically adapts to the user's device language settings. See README for integration details.
Summary by Sourcery
Add localization support to the Talker Flutter UI components and expose localization utilities for package consumers.
New Features:
Build:
Documentation:
Summary by Sourcery
Add localization infrastructure for Talker Flutter UI components and wire it into the example app.
New Features:
Enhancements:
Build:
Documentation: