Can I use LocaleKeys in code to find missing translations? #3285
Unanswered
SteveHawes
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to write my code so that the editor will alert me if there is a missing translation key (rather than finding out at runtime by seeing the key on the screen!)
All the examples and tutorials I can find that deal with localization show the translations being done using the following pattern:
Text('my_text'.tr);
This works fine if the my_text key has been defined in the translations but if not then the screen will show 'my_text' as the text.
In the locales.g.dart file there is a class called LocaleKeys that contains all the keys that have been defined in the various language files and I would like to use something like:
Text(LocaleKeys.my_text.tr)
In this way, if I try to use a key that is not defined I will immediately get a compiler error. I can do this by adding an import statement to every screen:
import 'package:my_app/generated/locales.g.dart';
This will achieve what I want but is there any downside to importing this file into every screen and is there a better way of doing it?
Thanks
Steve
Beta Was this translation helpful? Give feedback.
All reactions