crowdin / flutter-sdk

Crowdin Flutter SDK for instant translation delivery Over-The-Air directly to your application
https://pub.dev/packages/crowdin_sdk
MIT License
28 stars 4 forks source link

Crowdin package doesn't handle parameters correctly #61

Open JSBmanD opened 1 week ago

JSBmanD commented 1 week ago

Describe the bug When I create string in crowdin website with variable {business} inside text it creates arb file with string with such structure "some_translation": "Discount for {business}" As it's not structure, crowdin generator makes corrupted class "some_translation": "Discount for {business}", "@some_translation": { "placeholders": { "business": { "type": "String" } } },

image

To Reproduce Steps to reproduce the behavior:

  1. Latest sdk (0.6.3)
  2. Create arb file:
    {
    "@@locale": "en",
    "some_translation": "Discount for {business}"
    }
  3. Generate class with fvm flutter gen-l10n fvm dart run crowdin_sdk:gen
  4. Try to run app
  5. See an error

Expected behavior Generator makes not getter for this string but function with parameter that could be passed into as default intl generates String some_translation(Object business);

Environment

Additional context I'm using crowdin on the web to create strings

FlutterOd commented 1 day ago

Hi @JSBmanD

Since in Steps to reproduce you use .arb file with the string without any placeholders - it's expected behaviour that Flutter SDK generates simple getter.

Could you please clarify what do you get in your .arb files from Crowdin website?

For translation with variable in your .arb file you should receive such structure: "some_translation": "Discount for {business}", "@some_translation": { "placeholders": { "business": { "type": "String" } } },

And with such structure Flutter SDK generates function with parameter

JSBmanD commented 1 day ago

@FlutterOd i'm using this placeholder {business}. I know that metadata structure is a preferable way of using vars but flutter can generate func with param from simple placeholder (using intl generation). Is it possible to create string with correct placeholder in crowdin web?

FlutterOd commented 1 day ago

@JSBmanD

Currently Crowdin doesn't have mechanism to generate structure with placeholders when you add new strings with Crowdin UI.

To manage strings with variables we recommend to add them in your Flutter project .arb file with needed placeholders and then update the source file in Crowdin.

We will consider supporting simple strings with variables (without placeholder structure) on SDK side in the future

JSBmanD commented 1 day ago

@FlutterOd the problem is more on a crowdin package. Because intl_utils supports generating translation with variable even though i don't have metadata property.