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

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

Closed
liplum opened this issue Sep 23, 2022 · 7 comments · Fixed by #114808
Closed

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

liplum opened this issue Sep 23, 2022 · 7 comments · Fixed by #114808
Labels
a: internationalization Supporting other languages or locales. (aka i18n) found in release: 3.3 Found to occur in 3.3 found in release: 3.4 Found to occur in 3.4 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@liplum
Copy link

liplum commented Sep 23, 2022

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

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

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

@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
Copy link
Author

liplum commented Sep 23, 2022

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

asashour commented Sep 23, 2022

... 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 huycozy added the in triage Presently being triaged by the triage team label Sep 23, 2022
@huycozy
Copy link
Member

huycozy commented Sep 23, 2022

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!

@huycozy huycozy added tool Affects the "flutter" command-line tool. See also t: labels. a: internationalization Supporting other languages or locales. (aka i18n) has reproducible steps The issue has been confirmed reproducible and is ready to work on found in release: 3.3 Found to occur in 3.3 found in release: 3.4 Found to occur in 3.4 and removed in triage Presently being triaged by the triage team labels Sep 23, 2022
@christopherfujino christopherfujino added the P2 Important issues not at the top of the work list label Oct 4, 2022
asashour added a commit to asashour/flutter that referenced this issue Nov 7, 2022
auto-submit bot pushed a commit that referenced this issue Dec 1, 2022
* [gen_l10n] keys can contain dollar sign

Fixes #112250

* Update packages/flutter_tools/lib/src/localizations/gen_l10n.dart

Co-authored-by: Christopher Fujino <fujino@google.com>
mit-mit pushed a commit to mit-mit/flutter that referenced this issue Dec 6, 2022
* [gen_l10n] keys can contain dollar sign

Fixes flutter#112250

* Update packages/flutter_tools/lib/src/localizations/gen_l10n.dart

Co-authored-by: Christopher Fujino <fujino@google.com>
shogohida pushed a commit to shogohida/flutter that referenced this issue Dec 7, 2022
* [gen_l10n] keys can contain dollar sign

Fixes flutter#112250

* Update packages/flutter_tools/lib/src/localizations/gen_l10n.dart

Co-authored-by: Christopher Fujino <fujino@google.com>
gspencergoog pushed a commit to gspencergoog/flutter that referenced this issue Jan 19, 2023
* [gen_l10n] keys can contain dollar sign

Fixes flutter#112250

* Update packages/flutter_tools/lib/src/localizations/gen_l10n.dart

Co-authored-by: Christopher Fujino <fujino@google.com>
@github-actions
Copy link

github-actions bot commented Mar 5, 2023

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 Mar 5, 2023
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) found in release: 3.3 Found to occur in 3.3 found in release: 3.4 Found to occur in 3.4 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants