polyglothq 1.1.7 polyglothq: ^1.1.7 copied to clipboard
polyglothq is a Dart CLI to support using Polyglot for Flutter projects. polyglothq fetches translations from polyglothq.com, and converts them to a Flutter-suitable form.
Polyglothq Dart CLI #
THIS IS AN INTERNAL TOOL AND MIGHT NOT BE USEFUL FOR YOU
polyglothq
is a Dart CLI to support using Polyglot for Flutter
projects. polyglothq
fetches translations from polyglothq.com, and converts them to
a Flutter-suitable form.
How to install #
You can install polyglothq
by running the following command in your terminal.
dart pub global activate polyglothq
Usage #
Authorize polyglot #
Before using polyglothq
, you'll need to authorize with your Polyglot token. Run the following command to authorize:
polyglothq authorize <token>
This command will store your token securely, allowing you to use polyglothq
with the necessary permissions.
Initialize polyglot in your project #
To start using polyglothq
in your project, run the following command in the directory that contains your project:
polyglothq init
You'll be asked to select your project from the list of polyglot projects.
Pull translations from polyglot #
Run the following command to pull translations from Polyglot.
polyglothq pull
For dynamic texts, you can use following command.
polyglothq pull --dynamic
What to do if I have the same language with different country codes? #
Use the defaultCountryCode
section in polyglot.yml
to specify default country code.
:defaultCountryCode: en: GB sw: SW
Flutter usage #
In your flutter code,
Strings.of(context).keyName // With parameters Strings.of(context).keyName('arg0', 'arg1', ...)
In cases, where you don't have access to the context:
- You'll need first to add the following widget:
MaterialApp( builder: (context, child) { return StringsLocaleWidget(child: child!); // Use StringsLocaleWidget }, );
- Then you can use:
Strings.latest.keyName
- NOTE: Using translations without context is highly discouraged, and should only be used in special cases.