Skip to content

Flutter Localization - Can't use datetime placeholder in select placeholder #113495

@raresvanca

Description

@raresvanca

If using a DateTime placeholder inside a select placeholder the generation tool forgets to format the text.

Steps to Reproduce

  1. Generate translations using the following configuration:
"couponExpirationDate": "{expirationDate, select, none{No expiration date} today{Expires today} tomorrow{Expires tomorrow} other{Expires on: {date}}}",
"@couponExpirationDate": {
  "placeholders": {
    "expirationDate": {
      "type": "String",
    },
    "date": {
      "type": "DateTime",
      "format": "MMMd",
    }
  }
}

Expected results:

String couponExpirationDate(String expirationDate, DateTime date) {
  final DateFormat dateFormat = DateFormat.MMMd(_localeName);
  final String dateString = dateFormat.format(date);
  return intl.Intl.select(
      expirationDate,
      {
        'none': 'No expiration date',
        'today': 'Expires today',
        'tomorrow': 'Expires tomorrow',
        'other': 'Expires on: ${dateString}'
      },
  );
}

Actual generated code:

String couponExpirationDate(String expirationDate, DateTime date) {
  return intl.Intl.select(
      expirationDate,
      {
        'none': 'No expiration date',
        'today': 'Expires today',
        'tomorrow': 'Expires tomorrow',
        'other': 'Expires on: ${dateString}'
      },
  );
}
Code sample
{
  "couponExpirationDate": "{expirationDate, select, none{No expiration date} today{Expires today} tomorrow{Expires tomorrow} other{Expires on: {date}}}",
  "@couponExpirationDate": {
    "description": "Text for date expiration. Select the type and then insert the date if it others",
    "placeholders": {
      "expirationDate": {
        "type": "String",
        "description": "When it expires"
      },
      "date": {
        "type": "DateTime",
        "format": "d MMM",
        "isCustomDateFormat": "true",
        "example": "14 dec",
        "description": "Expiration date"
      }
    }
  },
}
Logs
[✓] Flutter (Channel beta, 3.4.0-17.2.pre, on Pop!_OS 22.04 LTS 5.19.0-76051900-generic, locale en_GB.UTF-8)
    • Flutter version 3.4.0-17.2.pre on channel beta at /home/rares/.apps/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d6260f127f (4 weeks ago), 2022-09-21 13:33:49 -0500
    • Engine revision 3950c6140a
    • Dart version 2.19.0 (build 2.19.0-146.2.beta)
    • DevTools version 2.16.0

Checking Android licenses is taking an unexpectedly long time...[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /home/rares/.apps/android-sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /home/rares/.apps/apps/AndroidStudio/ch-0/212.5712.43.2112.8609683/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 14.0.0-1ubuntu1
    • cmake version 3.22.1
    • ninja version 1.10.1
    • pkg-config version 0.29.2

[✓] Android Studio (version 2021.2)
    • Android Studio at /home/rares/.apps/apps/AndroidStudio/ch-0/212.5712.43.2112.8609683
    • Flutter plugin version 69.0.2
    • Dart plugin version 212.5744
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] IntelliJ IDEA Community Edition (version 2022.2)
    • IntelliJ at /home/rares/.apps/apps/IDEA-C/ch-0/222.3345.118
    • 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

[✓] VS Code (version 1.71.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.50.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Pop!_OS 22.04 LTS 5.19.0-76051900-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 105.0.5195.125

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: internationalizationSupporting other languages or locales. (aka i18n)found in release: 3.3Found to occur in 3.3found in release: 3.4Found to occur in 3.4found in release: 3.5Found to occur in 3.5has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versiontoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions