flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.15k stars 27.23k forks source link

[gen-l10n] nested localizations broken #133919

Open tomassasovsky opened 1 year ago

tomassasovsky commented 1 year ago

Is there an existing issue for this?

Steps to reproduce

This "fix" broke our use case:

Expected results

  @override
  String onboardingDescription(int count) {
    String _temp0 = intl.Intl.pluralLogic(
      count,
      locale: localeName,
      other: 'ERROR: onboardingDescription for this index not found',
      two: '$onboardingThirdDescription',
      one: '$onboardingSecondDescription',
      zero: '$onboardingFirstDescription',
    );
    return '$_temp0';

Actual results

    @override
  String onboardingDescription(int count) {
    String _temp0 = intl.Intl.pluralLogic(
      count,
      locale: localeName,
      other: 'ERROR: onboardingDescription for this index not found',
      two: '\$onboardingThirdDescription',
      one: '\$onboardingSecondDescription',
      zero: '\$onboardingFirstDescription',
    );
    return '$_temp0';
  }

Code sample

Code sample ```json { "onboardingDescription": "{count, plural, =0{$onboardingFirstDescription} =1{$onboardingSecondDescription} =2{$onboardingThirdDescription} other{ERROR: onboardingDescription for this index not found}}", "@onboardingDescription": { "placeholders": { "count": { "type": "int" } } }, "onboardingFirstDescription": "View your upcoming and past games. Select a game and record it by pressing the red button.", "onboardingSecondDescription": "To record a game follow the set-up instructions. Once finished recording, save and upload later to get it analyzed.", "onboardingThirdDescription": "Upload your game's videos in My Recordings." } ```

Screenshots or Video

Screenshots / Video demonstration [Upload media here]

Logs

Logs ```console [Paste your logs here] ```

Flutter Doctor output

Doctor output ```console [Paste your output here] ```
darshankawar commented 1 year ago

Thanks for the report @tomassasovsky I tried to recreate the replication using the details you provided, but getting below error while trying to run flutter gen-l10n:

The arb file /Users/dhs/Documents/NCFlutter/new_project/lib/l10n/app_en.arb has the following formatting issue: 
FormatException: Unexpected character (at character 24)
"onboardingDescription": "{count, plural, =0{$onboardingFirstDescription} =...
Screenshot 2023-09-04 at 4 12 31 PM

Can you provide complete details or replication details so that we can try to debug it further ?

tomassasovsky commented 1 year ago

@darshankawar Fixed the code sample.

darshankawar commented 1 year ago

Thanks for the update. I was able to replicate it using latest stable and master versions and see below:

import 'package:intl/intl.dart' as intl;

import 'app_localizations.dart';

/// The translations for English (`en`).
class AppLocalizationsEn extends AppLocalizations {
  AppLocalizationsEn([String locale = 'en']) : super(locale);

  @override
  String onboardingDescription(int count) {
    String _temp0 = intl.Intl.pluralLogic(
      count,
      locale: localeName,
      other: 'ERROR: onboardingDescription for this index not found',
      two: '\$onboardingThirdDescription',
      one: '\$onboardingSecondDescription',
      zero: '\$onboardingFirstDescription',
    );
    return '$_temp0';
  }

  @override
  String get onboardingFirstDescription => 'View your upcoming and past games. Select a game and record it by pressing the red button.';

  @override
  String get onboardingSecondDescription => 'To record a game follow the set-up instructions. Once finished recording, save and upload later to get it analyzed.';

  @override
  String get onboardingThirdDescription => 'Upload your game\'s videos in My Recordings.';
}
stable, master flutter doctor -v ``` [!] Flutter (Channel stable, 3.13.2, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.13.2 on channel stable at /Users/dhs/documents/fluttersdk/flutter ! Warning: `flutter` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision ff5b5b5fa6 (7 days ago), 2023-08-24 08:12:28 -0500 • Engine revision b20183e040 • Dart version 3.1.0 • DevTools version 2.25.0 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. [!] Flutter (Channel master, 3.14.0-14.0.pre.93, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.14.0-14.0.pre.93 on channel master at /Users/dhs/documents/fluttersdk/flutter ! Warning: `flutter` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision ef9befc9da (11 hours ago), 2023-09-03 11:23:20 -0700 • Engine revision fbc6f4a540 • Dart version 3.2.0 (build 3.2.0-131.0.dev) • DevTools version 2.27.0 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/dhs/Library/Android/sdk ✗ cmdline-tools component is missing Run `path/to/sdkmanager --install "cmdline-tools;latest"` See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details. [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 13C100 • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2) • IntelliJ at /Applications/IntelliJ IDEA.app • Flutter plugin version 65.1.4 • Dart plugin version 213.7228 [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.29.0 [✓] Connected device (3 available) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 15.3.1 19D52 • macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.119 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. ```
HansMuller commented 1 year ago

This looks like more of a feature request to allow referencing other arb strings from a given arb string via string interpolation. The previous implementation allowed this unintentionally because it would not escape the dollar signs in the generated code.

It should be possible to work around this by turning the "interpolated strings" into placeholders, and then pass those referenced arb strings in as parameters.

We could implement this feature, it would by check if the symbol after the dollar sign is a valid arb string getter. That's not syntax defined by ICU so it would be custom behavior supported by Flutter i18n.

CC @thkim1011

sostenesgomes commented 5 months ago

We also had a breakdown due to the fix carried out. It would be a good feature to write less and reuse patterns.