localizely / intl_utils

Dart package that creates a binding between your translations from .arb files and your Flutter app
BSD 3-Clause "New" or "Revised" License
135 stars 81 forks source link

[BUG] 'decimalDigits' is ignored when format double value with format 'decimalPercentPattern' #119

Closed suesitran closed 1 year ago

suesitran commented 1 year ago

I notice this issue while working on my app. Below is the code I defined in myintl_en.arb, in which I use format decimalPercentPattern, with optionalParameters 'decimalDigits'

  "percentage":"({number})",
  "@percentage": {
    "placeholders": {
      "number": {
        "type": "double",
        "format": "decimalPercentPattern",
        "decimalDigits": 2
      }
    }
  }

However, after I run command dart run intl_utils:generate, the generated string does not includedecimalDigits

  /// `({number})`
  String percentage(double number) {
    final NumberFormat numberNumberFormat = NumberFormat.decimalPercentPattern(
      locale: Intl.getCurrentLocale(), // <=== decimalDigits is missing here.
    );
    final String numberString = numberNumberFormat.format(number);

    return Intl.message(
      '($numberString)',
      name: 'spentAmountPercentage',
      desc: '',
      args: [numberString],
    );
  }
}

I'm using intl: ^0.18.1, and intl_utils: ^2.8.5

lzoran commented 1 year ago

Hi @suesitran,

It looks like the metadata for the placeholder that includes decimalDigits is not set up correctly within the arb file.

Here's an example that should work:

  "percentage":"({number})",
  "@percentage": {
    "placeholders": {
      "number": {
        "type": "double",
        "format": "decimalPercentPattern",
        "optionalParameters": {
          "decimalDigits": 2
        }
      }
    }
  }
suesitran commented 1 year ago

Great. Thank you 🙏