Jesway / flutter_translate

Flutter Translate is a fully featured localization / internationalization (i18n) library for Flutter.
MIT License
401 stars 118 forks source link

Default value if not found #27

Closed porfirioribeiro closed 4 years ago

porfirioribeiro commented 4 years ago

First of all, thanks for this nice project :)

Currently translate('key') returns the key is it didn't find a translation, but would be nice to be able to specify a default value like

translate('my.key', def: 'Something');

Or have a function that returns null so we can do:

translate('my.key') ?? 'Something';
bratan commented 4 years ago

Thanks for the suggestion.

I don't think I will implement this behavior since it will have to be added as an option and it will just bloat the configuration, considering that generally there should be no missing translations.

In the next couple of days I`m going to implement https://github.com/bratan/flutter_translate_gen/issues/1 which will make sure there are no missing translation keys.

porfirioribeiro commented 4 years ago

Ok, i understand, for my use case i was dealing with the possibility of having a missing key and wanted to actually specify a default value. But i made a workaround in my code that fits my needs, you can close this if you feel it's the best for the project ;)

Thanks!