kiwi-bop / intl_generator

Message extraction and code generation from translated messages for the intl package

Home Page:https://pub.dev/packages/intl_translation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for nullable parameters

mikes222 opened this issue · comments

The following code in appLocalization:

String lblUserWithName(String? name) => Intl.message('User $name', name: "lblUserWithName", args: [name!]);

leads to an error message:

Skipping invalid Intl.message invocation
    <Intl.message('User $name', name: "lblUserWithName", args: [name!])>
    reason: The 'args' argument must match the message arguments, e.g. args: [name]
    from lib/i10n/applocalization.dart    line: 84, column: 43

Suggestion is to either change the type of args to dynamic or Object? or support "name!" as args-parameter (I think the former is not consistent).

Yeah that's a bit tricky and doesn't really make sens to me. Because here if you put name to null you'll see User null. Not sure that's what you want. I don't have any real good use case where nullable should be handled as params.

For some apps which are written mainly for technical audience it is ok to provide null as parameter value. In other apps I use conditional texts like

String lblUserWithName(String? name) => Intl.message('User ${name ?? "unknown"}', name: "lblUserWithName", args: [name!]);

This saves me from doing the condition in the sourcecode wich makes the source more readable. Anyway I do agree with you that both are edgecases and if the implementation is too hard it is ok to do the null-check in source.