A Flutter package that allows you to access translated strings without having to pass context.
Not having to pass context is especially useful when you need to access translations outside the widget build tree like a controller class, bloc etc.
Unlike other packages with similar functionality you can access your translation keys in a statically typed way, as properties, and not as raw strings that you have to be copying over. The compiler will prevent you from making any mistakes that would otherwise be discovered during runtime.
Extension not replacement
This package is an extension to the original Flutter localization toolchain and does not replace any parts of it nor it requires the use of specialized IDE extensions.
Follow the official guide “Internationalizing Flutter apps”.
dependencies: current_context: ^0.0.1
flutter gen-l10ncommand once to verify that the localization files are generated. Normally this step is not needed.
Import the generated localizations file:
S.curent.xyzto access your translated message.
This package will auto-initialize during the first runtime use. If you want to force initialization you can call:
You can do that in the main function of your project.
No need to specify non nullable getters
There is no need to set
nullable-getter: false to avoid having to deal with nullable strings.
Use at your own risk
This package is currently experimental and the API might change.
Since potential issues might arise only use at your own risk.
If you spot an issue please open an issue or even better make a PR that fixes it.