Skip to content

Comments

Add localization support for Talker Flutter package#463

Open
f-ever wants to merge 1 commit intoFrezyx:masterfrom
f-ever:localization
Open

Add localization support for Talker Flutter package#463
f-ever wants to merge 1 commit intoFrezyx:masterfrom
f-ever:localization

Conversation

@f-ever
Copy link

@f-ever f-ever commented Dec 31, 2025

Add Localization Support

Summary

Added internationalization support to Talker Flutter package, allowing the UI to display in multiple languages.

Key Changes

  • Added localization infrastructure with l10n.yaml configuration
  • Created translation files for English and Chinese
  • Updated all UI components to use localized strings
  • Generated Flutter localization classes

Supported Languages

  • English
  • Chinese

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:

  • Introduce TalkerFlutterLocalizations with English and Chinese translations and a BuildContext extension for easy access to localized strings.
  • Expose localization delegates and supported locales from the package and wire them into the example app.
  • Add localization configuration via l10n.yaml for generating localization classes.

Build:

  • Enable Flutter localization code generation and add flutter_localizations and intl dependencies for the package and example app.

Documentation:

  • Document localization capabilities and setup steps in the README, including supported languages and integration examples.

Summary by Sourcery

Add localization infrastructure for Talker Flutter UI components and wire it into the example app.

New Features:

  • Introduce TalkerFlutterLocalizations with English and Chinese localizations, plus a BuildContext extension for safe access to localized strings.
  • Expose localization delegates and supported locales from the package and configure them in the example app.
  • Add l10n.yaml configuration and generated localization files for Talker Flutter.

Enhancements:

  • Replace hard-coded user-facing strings across Talker Flutter UI (monitor, settings, actions, wrappers, snackbars, and app bar) with localized text and parameterized messages for counts and statuses.

Build:

  • Enable Flutter localization code generation and add flutter_localizations and intl dependencies for the package and example app.

Documentation:

  • Document localization capabilities, usage, and supported locales in the README, including setup example for MaterialApp.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 31, 2025

Reviewer's Guide

Adds 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.l10n

sequenceDiagram
  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
Loading

Class diagram for TalkerFlutter localization layer

classDiagram
  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
Loading

File-Level Changes

Change Details Files
Introduce TalkerFlutter localization infrastructure and public API for consumers.
  • Add l10n.yaml and ARB scaffolding for English and Chinese to drive gen-l10n code generation.
  • Add TalkerFlutterLocalizations base class, English and Chinese implementations, and a BuildContext extension providing a safe l10n accessor with English fallback.
  • Expose TalkerFlutterLocalizations and localization helpers through the package’s main export and define supportedLocales and localizationsDelegates for host apps.
packages/talker_flutter/l10n.yaml
packages/talker_flutter/lib/l10n/app_en.arb
packages/talker_flutter/lib/l10n/app_zh.arb
packages/talker_flutter/lib/l10n/talker_flutter_localizations.dart
packages/talker_flutter/lib/l10n/talker_flutter_localizations_en.dart
packages/talker_flutter/lib/l10n/talker_flutter_localizations_zh.dart
packages/talker_flutter/lib/l10n/l10n.dart
packages/talker_flutter/lib/talker_flutter.dart
Refactor Talker Flutter UI components to use localized strings instead of hard-coded English text.
  • Update TalkerMonitor and TalkerMonitorTypedLogsScreen titles, HTTP stats labels, and counts messages to use context.l10n getters and pluralized methods.
  • Localize TalkerView action labels, snackbar messages, and search hint using context.l10n.
  • Localize settings bottom sheet labels, section titles, and bottom-sheet titles, plus Talker actions bottom sheet title and snackbar dismiss button text with context.l10n values.
packages/talker_flutter/lib/src/ui/talker_monitor/talker_monitor.dart
packages/talker_flutter/lib/src/ui/talker_monitor/talker_monitor_typed_logs_screen.dart
packages/talker_flutter/lib/src/ui/talker_view.dart
packages/talker_flutter/lib/src/ui/talker_settings/talker_settings_bottom_sheet.dart
packages/talker_flutter/lib/src/ui/talker_actions/talker_actions_bottom_sheet.dart
packages/talker_flutter/lib/src/ui/widgets/talker_view_appbar.dart
packages/talker_flutter/lib/src/ui/widgets/snackbar.dart
Make TalkerWrapper error/exception alerts localization-aware with configurable overrides.
  • Change TalkerWrapperOptions to accept optional error/exception titles, store them privately, and add context-aware getters that fall back to localized errorOccurred.
  • Update TalkerWrapper snackbar construction to call the new context-based title getters instead of static strings.
packages/talker_flutter/lib/src/ui/talker_wrapper/talker_wrapper_options.dart
packages/talker_flutter/lib/src/ui/talker_wrapper/talker_wrapper.dart
Wire localization support into the package build configuration and example app.
  • Enable Flutter localization code generation in the package and add flutter_localizations and intl as dependencies.
  • Add flutter_localizations dependency to the example app and configure MaterialApp with TalkerFlutterLocalizations.supportedLocales and .localizationsDelegates.
  • Document localization support, setup instructions, supported locales, and usage examples in the README.
packages/talker_flutter/pubspec.yaml
packages/talker_flutter/example/pubspec.yaml
packages/talker_flutter/example/lib/main.dart
README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 3 issues, and left some high level feedback:

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +94 to +102
String successfulResponses(int count) {
return '$count 个成功';
}

@override
String get responsesReceived => ' 个响应已接收';

@override
String failureResponses(int count) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +3 to +4
output-localization-file: talker_flutter_localizations.dart
output-class: TalkerFlutterLocalizations
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

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."

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants