chore(localizations): replace sh with dart script, update docs and remove the sh script.

pull/1924/head
Ellet 10 months ago
parent 731e483d8b
commit b5ecbd3dce
  1. 33
      doc/translation.md
  2. 24
      scripts/regenerate_translations.dart
  3. 29
      scripts/regenerate_translations.sh

@ -37,32 +37,31 @@ Currently, translations are available for these 37 locales:
#### Contributing to translations
The translation files are located in the [l10n folder](../lib/src/l10n/). Feel free to contribute your own translations, just copy the [English translations](../lib/src/l10n/quill_en.arb) map and replace the values with your translations.
The translation files are located in the [l10n folder](../lib/src/l10n/). Feel free to contribute your own translations.
Add a new file in the l10n folder with the following name
`quill_${localName}.arb` for example `quill_de.arb`
You can take a look at the [untranslated.json](../lib/src/l10n/untranslated.json) file, which is a generated file that tells you which keys with which locales haven't translated so you can find the missings easily.
paste the English version and replace the values
1. Create a new file in [l10n](../lib/src/l10n/) folder, with the following name`quill_${localName}.arb` for example `quill_de.arb`
Also, you can take a look at the [untranslated.json](../lib/src/l10n/untranslated.json) JSON file, which is a generated file that tells you which keys with which locales haven't translated so you can find the missings easily
2. Copy the [Arb Template](../lib/src/l10n/quill_en.arb) file and paste it into your new file, replace the values with your translations
After you are done and want to test the changes, run the following in the root folder (preferred):
3. Once you finish, run the following script:
```
./scripts/regenerate_translations.sh
```
```bash
dart ./scripts/regenerate_translations.dart
```
or (if you can't run the script for some reasons):
Or (if you can't run the script for some reason):
```
flutter gen-l10n
dart fix --apply ./lib/src/l10n/generated
dart format ./lib/src/l10n/generated
```
```bash
flutter gen-l10n
dart fix --apply ./lib/src/l10n/generated
dart format ./lib/src/l10n/generated
```
This will generate the new dart files from the arb files in order to take effect, otherwise, you won't notice a difference
The script above will generate Dart files from the Arb files in order to test the changes and take effect, otherwise you won't notice a difference.
> If you added or removed translations, make sure to update `_expectedTranslationKeysLength` variable in `./scripts/ensure_translations_correct.dart` <br>
> If you added or removed translations in the template file, make sure to update `_expectedTranslationKeysLength` variable in `./scripts/ensure_translations_correct.dart` <br>
> Otherwise you don't need to update it.
Then open a pull request so everyone can benefit from your translations!

@ -0,0 +1,24 @@
// ignore_for_file: avoid_print
import 'dart:io' show Directory, Process;
Future<void> main(List<String> args) async {
final generatedDartLocalizationsFolder = Directory('lib/src/l10n/generated');
if (await generatedDartLocalizationsFolder.exists()) {
print(
'Generated directory (${generatedDartLocalizationsFolder.path}) exists, deleting it... 📁',
);
await generatedDartLocalizationsFolder.delete(recursive: true);
}
print('Running flutter pub get... 📦');
await Process.run('flutter', ['pub', 'get']);
print('Running flutter gen-l10n... 🌍');
await Process.run('flutter', ['gen-l10n']);
print('Applying Dart fixes to the newly generated files... 🔧');
await Process.run('dart', ['fix', '--apply', './lib/src/l10n/generated']);
print('Formatting the newly generated Dart files... ✨');
await Process.run('dart', ['format', './lib/src/l10n/generated']);
}

@ -1,29 +0,0 @@
#!/bin/bash
# Important: make sure to run the script in the root folder of the repo:
# ./scripts/regenerate_translations.sh
# otherwise the script could delete the wrong folder in rare cases
# TODO: Refactor this to a dart script to allow developers who use Windows to use it
echo ""
echo "Delete the current generated localizations..."
rm -rf lib/src/l10n/generated
echo ""
echo "Run flutter pub get.."
flutter pub get
echo ""
echo "Run flutter gen-l10n"
flutter gen-l10n
echo ""
echo ""
echo "Apply dart fixes to the newly generated files"
dart fix --apply ./lib/src/l10n/generated
echo ""
echo "Formate the newly generated dart files"
dart format ./lib/src/l10n/generated
Loading…
Cancel
Save