Skip to content
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

Generated l10n file is missing 'intl' import with Flutter 2.2.0 #83102

Closed
SebastianEngel opened this issue May 21, 2021 · 10 comments
Closed

Generated l10n file is missing 'intl' import with Flutter 2.2.0 #83102

SebastianEngel opened this issue May 21, 2021 · 10 comments
Labels
a: internationalization Supporting other languages or locales. (aka i18n) c: regression It was better in the past than it is now found in release: 2.2 Found to occur in 2.2 found in release: 2.3 Found to occur in 2.3 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on r: fixed Issue is closed as already fixed in a newer version

Comments

@SebastianEngel
Copy link

After upgrading my Flutter SDK to 2.2.0 the generated localization file is missing the 'intl' import which leads to the following error:

.dart_tool/flutter_gen/gen_l10n/translations_de.dart:54:11: Error: 'intl.DateFormat' can't be used as a type because 'intl' doesn't refer to an import prefix.
    final intl.DateFormat dateDateFormat = intl.DateFormat.yMMMM(localeName);
          ^^^^^^^^^^^^^^^

Before upgrading to 2.2.0 (was 2.0.6):
Bildschirmfoto 2021-05-21 um 16 25 00

After upgrading to 2.2.0:
Bildschirmfoto 2021-05-21 um 16 26 06

Flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel unknown, 2.2.0, on macOS 11.3.1 20E241 darwin-arm, locale de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] VS Code (version 1.56.2)
[✓] Connected device (3 available)
@TahaTesser TahaTesser added the in triage Presently being triaged by the triage team label May 24, 2021
@TahaTesser
Copy link
Member

Hi @SebastianEngel
Thanks for filing the issue, I can confirm files like .dart_tool\flutter_gen\gen_l10n\app_localizations_es.dart are missing intl import but I don't get : Error: 'intl.DateFormat' can't be used as a type because 'intl' such error when running official sample

I am using a sample from here

flutter doctor -v
[✓] Flutter (Channel stable, 2.2.0, on Microsoft Windows [Version 10.0.19043.985], locale en-US)
    • Flutter version 2.2.0 at C:\Users\Taha\Code\flutter_stable
    • Framework revision b22742018b (9 days ago), 2021-05-14 19:12:57 -0700
    • Engine revision a9d88a4d18
    • Dart version 2.13.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\Taha\Code\SDK
    • Platform android-30, build-tools 30.0.3
    • ANDROID_SDK_ROOT = C:\Users\Taha\Code\SDK
    • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java.exe
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.9.6)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.9.31313.79
    • Windows 10 SDK version 10.0.19041.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[✓] VS Code (version 1.56.2)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.22.0

[✓] Connected device (5 available)
    • Redmi K20 Pro (mobile)  • def0ad20      • android-arm64  • Android 10 (API 29)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)       • windows       • windows-x64    • Microsoft Windows [Version 10.0.19043.985]
    • Chrome (web)            • chrome        • web-javascript • Google Chrome 90.0.4430.212
    • Edge (web)              • edge          • web-javascript • Microsoft Edge 90.0.818.66

! Doctor found issues in 1 category.

Can you please try the code sample and reproduce the issue
Thank you

@TahaTesser TahaTesser added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 24, 2021
@SebastianEngel
Copy link
Author

Hi @TahaTesser,

it seems like these samples are very basic and don't use any DateTime placeholders, right?

I do have something like this in my localizations:

  "bookingDate": "{date}",
  "@bookingDate": {
    "description": "The day the user is booking time for on the booking page.",
    "placeholders": {
      "date": {
        "type": "DateTime",
        "format": "yMMMEd"
      }
    }
  },

The generated code looks like this:

  @override
  String bookingDate(DateTime date) {
    final intl.DateFormat dateDateFormat = intl.DateFormat.yMMMEd(localeName);
    final String dateString = dateDateFormat.format(date);

    return '${dateString}';
  }

That's a case when the 'intl' import is required and which breaks with Flutter 2.2.0.

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 24, 2021
@TahaTesser
Copy link
Member

Hi @SebastianEngel
My bad, adding date reproduces the issue, However, this seems to be fixed on the latest master channel

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 helloWorld(DateTime date) {
    final intl.DateFormat dateDateFormat = intl.DateFormat.yMMMEd(localeName);
    final String dateString = dateDateFormat.format(date);

    return 'Hello World!';
  }
}

Tested the code sample on the following channels

stable beta dev master

Check flutter doctor -v outputs for each channel below

flutter doctor -v
[✓] Flutter (Channel stable, 2.2.0, on Microsoft Windows [Version 10.0.19043.985], locale en-US)
    • Flutter version 2.2.0 at C:\Users\Taha\Code\flutter_stable
    • Framework revision b22742018b (10 days ago), 2021-05-14 19:12:57 -0700
    • Engine revision a9d88a4d18
    • Dart version 2.13.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\Taha\Code\SDK
    • Platform android-30, build-tools 30.0.3
    • ANDROID_SDK_ROOT = C:\Users\Taha\Code\SDK
    • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java.exe
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.9.6)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.9.31313.79
    • Windows 10 SDK version 10.0.19041.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[✓] VS Code (version 1.56.2)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.22.0

[✓] Connected device (4 available)
    • Redmi K20 Pro (mobile) • def0ad20 • android-arm64  • Android 10 (API 29)
    • Windows (desktop)      • windows  • windows-x64    • Microsoft Windows [Version 10.0.19043.985]
    • Chrome (web)           • chrome   • web-javascript • Google Chrome 90.0.4430.212
    • Edge (web)             • edge     • web-javascript • Microsoft Edge 90.0.818.66

! Doctor found issues in 1 category.
[✓] Flutter (Channel beta, 2.2.0, on Microsoft Windows [Version 10.0.19043.985], locale en-US)
    • Flutter version 2.2.0 at C:\Users\Taha\Code\flutter_beta
    • Framework revision b22742018b (10 days ago), 2021-05-14 19:12:57 -0700
    • Engine revision a9d88a4d18
    • Dart version 2.13.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\Taha\Code\SDK
    • Platform android-30, build-tools 30.0.3
    • ANDROID_SDK_ROOT = C:\Users\Taha\Code\SDK
    • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java.exe
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.9.6)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.9.31313.79
    • Windows 10 SDK version 10.0.19041.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[✓] VS Code (version 1.56.2)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.22.0

[✓] Connected device (4 available)
    • Redmi K20 Pro (mobile) • def0ad20 • android-arm64  • Android 10 (API 29)
    • Windows (desktop)      • windows  • windows-x64    • Microsoft Windows [Version 10.0.19043.985]
    • Chrome (web)           • chrome   • web-javascript • Google Chrome 90.0.4430.212
    • Edge (web)             • edge     • web-javascript • Microsoft Edge 90.0.818.66

! Doctor found issues in 1 category.
[✓] Flutter (Channel dev, 2.3.0-12.1.pre, on Microsoft Windows [Version 10.0.19043.985], locale en-US)
    • Flutter version 2.3.0-12.1.pre at C:\Users\Taha\Code\flutter_dev
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f9c825981c (6 days ago), 2021-05-18 14:07:52 -0700
    • Engine revision 26e217e6c3
    • Dart version 2.14.0 (build 2.14.0-edge.a527411e5100a0a4f48c4009087a1b988aa784af)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\Taha\Code\SDK
    • Platform android-30, build-tools 30.0.3
    • ANDROID_SDK_ROOT = C:\Users\Taha\Code\SDK
    • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.9.6)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.9.31313.79
    • Windows 10 SDK version 10.0.19041.0

[✓] Android Studio (version 4.2.0)
    • Android Studio at C:\Users\Taha\Code\android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[✓] VS Code (version 1.56.2)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.22.0

[✓] Connected device (5 available)
    • Redmi K20 Pro (mobile)  • def0ad20 • android-arm64   • Android 10 (API 29)
    • Windows (desktop)       • windows  • windows-x64     • Microsoft Windows [Version 10.0.19043.985]
    • Windows (UWP) (desktop) • winuwp   • windows-uwp-x64 •
    • Chrome (web)            • chrome   • web-javascript  • Google Chrome 90.0.4430.212
    • Edge (web)              • edge     • web-javascript  • Microsoft Edge 90.0.818.66

• No issues found!
[✓] Flutter (Channel master, 2.3.0-13.0.pre.145, on Microsoft Windows [Version 10.0.19043.985], locale en-US)
    • Flutter version 2.3.0-13.0.pre.145 at C:\Users\Taha\Code\flutter_master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision fdb1fb184d (3 hours ago), 2021-05-24 22:04:02 -0700
    • Engine revision b1385c0df1
    • Dart version 2.14.0 (build 2.14.0-145.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\Taha\Code\SDK
    • Platform android-30, build-tools 30.0.3
    • ANDROID_SDK_ROOT = C:\Users\Taha\Code\SDK
    • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.9.6)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.9.31313.79
    • Windows 10 SDK version 10.0.19041.0

[✓] Android Studio (version 4.2.0)
    • Android Studio at C:\Users\Taha\Code\android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[✓] VS Code (version 1.56.2)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.22.0

[✓] Connected device (5 available)
    • Redmi K20 Pro (mobile)  • def0ad20 • android-arm64   • Android 10 (API 29)
    • Windows (desktop)       • windows  • windows-x64     • Microsoft Windows [Version 10.0.19043.985]
    • Windows (UWP) (desktop) • winuwp   • windows-uwp-x64 •
    • Chrome (web)            • chrome   • web-javascript  • Google Chrome 90.0.4430.212
    • Edge (web)              • edge     • web-javascript  • Microsoft Edge 90.0.818.66

• No issues found!

✅ : No Issue ❌: Has issue

Can you please upgrade to the latest master and try again
Execute the following commands to upgrade
flutter channel master
flutter upgrade --force
flutter doctor -v

@TahaTesser TahaTesser added a: internationalization Supporting other languages or locales. (aka i18n) found in release: 2.2 Found to occur in 2.2 found in release: 2.3 Found to occur in 2.3 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on c: regression It was better in the past than it is now and removed in triage Presently being triaged by the triage team labels May 25, 2021
@SebastianEngel
Copy link
Author

@TahaTesser Thank you for that quick action. Looks good, just tried it 👍🏻

Since without this fix it's not possible to switch to 2.2.0 when having DateTimes in localizations, does this fix qualify for a hotfix on stable?

@TahaTesser
Copy link
Member

Regarding #83102 (comment)

cc: @christopherfujino

@christopherfujino
Copy link
Member

@HansMuller what do you think, does this necessitate a cherry-pick request? And if so, can you determine where it was fixed?

@SoftXperience
Copy link

Problem is in gen_l10n.dart file:
.replaceAll('@(requiresIntlImport)', _containsPluralMessage() ? "import 'package:intl/intl.dart' as intl;" : '');
The import is only added, if you use Plurals.

So a workaround is to add a dummy plurals string to your arb file.

@HansMuller
Copy link
Contributor

@goderbauer - this looks similar to #82713 which you fixed in #83122. Could you take a look?

@goderbauer
Copy link
Member

This issue was fixed in #83122 and should not appear on master. I think this would be a worthwhile cherry-pick. I'll add the label to request it.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: internationalization Supporting other languages or locales. (aka i18n) c: regression It was better in the past than it is now found in release: 2.2 Found to occur in 2.2 found in release: 2.3 Found to occur in 2.3 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
Development

No branches or pull requests

6 participants