[gen_l10n] A name that has any dollar sign ($) isn't allowed.

This issue has been tracked since 2022-09-23.

flutter_localizations(gen_l10n comamnd) doesn't allow a property name to have a dollar sign ($) in any postion.

Steps to Reproduce

  1. Execute flutter gen-l10n involved in any *.arb file which has a key that contains a dollar sign ($).
  2. Loot at the terminal output.

Expected results: Dollar sign can be a part of the property name, so it should succeed.

Actual results: gen-l10n failed.

Code sample

In app_en.arb file:

{
  "$address": "Address:"
}

Logs

Invalid ARB resource name "$address" in LocalFile: '<ProjectFolder>\lib/l10n\app_en.arb'.
Resources names must be valid Dart method names: they have to be camel case, cannot start with a number or
underscore, and cannot contain non-alphanumeric characters.
navaronbracke wrote this answer on 2022-09-23

In plain Dart the string "$address" would resolve to a string which interpolates the value of a variable called address,
i.e.

final int address = 42;

final out = "$address";

print(out); // "42" 

This is probably why it is disallowed.

Either the warning message should be expanded to include a mention of $ signs, or the tool should escape
the dollar sign when generating translations, using \$.

asashour wrote this answer on 2022-09-23

I guess the reason mentioned, that the name must be a valid Dart method name. However, methods are allowed to start with $, e.g.

class A {
  void $asdf() {}

  void f() {
    var x = $asdf();
  }
}

I think this should be handled, or there is another reason of rejection.

navaronbracke wrote this answer on 2022-09-23

@asashour I forgot to mention, the format "$foo" is used as a string with a parameter in the gen_l10n tool, that might be the reason for the rejection?

See https://github.com/flutter/flutter/blob/master/packages/flutter_localizations/lib/src/l10n/README.md#values-with-parameters-plurals

liplum wrote this answer on 2022-09-23

methods are allowed to start with $

Yes, I want to use it to overload the placeholders functions because dart doesn't have function overloading feature.

{
  "foo$A": "foo {a}",
  "@foo$A": {
    "placeholders": {
      "a": {
        "type": "int",
      }
    }
  },
  "foo$B": "bar {a} {b}",
  "@foo$B": {
    "placeholders": {
      "a": {
        "type": "int",
      },
      "b": {
        "type": "String",
      }
    }
  }
}

It's not only about prefix-$ but also includes a dollar sign in the middle.

asashour wrote this answer on 2022-09-23

... the format "$foo" is used as a string with a parameter in the gen_l10n tool, that might be the reason for the rejection?

Thanks, but this applies to the values, not keys.

What I recall, is that the key must be a valid method name, because a corresponding getter is created in AppLocalizations, which is overridden by the specific language class.

huycozy wrote this answer on 2022-09-23

Hi @liplum, thanks for filing the issue. This issue is reproducible on the latest stable and master channels with provided sample code (app_en.arb)

Logs
Invalid ARB resource name "$address" in LocalFile: '/Users/huynq/Documents/NEVERCODE.IO/RepoduceProjects/reproduce_issue_gen_l10n/lib/l10n/app_en.arb'.
Resources names must be valid Dart method names: they have to be camel case, cannot start with a number or underscore, and cannot contain non-alphanumeric characters.
flutter doctor -v
[✓] Flutter (Channel stable, 3.3.2, on macOS 12.6 21G115 darwin-x64, locale en-VN)
    • Flutter version 3.3.2 on channel stable at /Users/huynq/Documents/GitHub/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision e3c29ec00c (6 days ago), 2022-09-14 08:46:55 -0500
    • Engine revision a4ff2c53d8
    • Dart version 2.18.1
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 13E113
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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.12+0-b1504.28-7817840)

[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
    • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
    • 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 /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.48.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 12.6 21G115 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 105.0.5195.125

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

• No issues found!
[✓] Flutter (Channel master, 3.4.0-28.0.pre.123, on macOS 12.6 21G115 darwin-x64, locale en-VN)
    • Flutter version 3.4.0-28.0.pre.123 on channel master at /Users/huynq/Documents/GitHub/flutter_master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4aa27d844e (3 minutes ago), 2022-09-22 21:00:22 -0700
    • Engine revision a5489ce4f9
    • Dart version 2.19.0 (build 2.19.0-229.0.dev)
    • DevTools version 2.17.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A309
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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.12+0-b1504.28-7817840)

[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
    • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
    • 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 /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.48.0

[✓] Connected device (3 available)
    • SM T225 (mobile) • R9JT3004VRJ • android-arm64  • Android 12 (API 31)
    • macOS (desktop)  • macos       • darwin-x64     • macOS 12.6 21G115 darwin-x64
    • Chrome (web)     • chrome      • web-javascript • Google Chrome 105.0.5195.125
    ! Error: Failed to prepare the device for development. Please unlock and reconnect the device. (code 806)

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

• No issues found!

Labeling this issue for further insights from the team. Thanks!

More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2022-10-04
Star Count 145499
Watcher Count 3567
Fork Count 23393
Issue Count 11206

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date