translation_string_extractor 0.0.1+2 translation_string_extractor: ^0.0.1+2 copied to clipboard
Extracts .tr and .tr() strings from a project into a JSON file or returns a Map
Translation String Extractor #
Extracts strings marked for translation with .tr
or .tr()
and writes them into JSON file or returns a Map.
The tool will ignore file names ending in .g.dart
.
Input:
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class TestClass extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(children: [
Text('Hello'.tr),
Text("""World""".tr),
]);
}
}
Output:
{
"Hello": "Hello",
"World": "World"
}
Installation #
dev_dependencies:
translation_string_extractor: <latest>
Or install the package globally:
dart pub global activate translation_string_extractor
Usage #
As a dev dependency:
dart run translation_string_extractor:extract -d=lib -o=locale.json
Globally:
translation_string_extractor -d=lib -o=locale.json
Public Signature:
TranlationStringExtractor ...
static void extractStrings(String directory, String outputFile);
static Map<String, String> read(String directory) {
SplayTreeMap<String, String> map = SplayTreeMap<String, String>();
static void write(Map<String, String> map, String outputFile);
Issues #
https://github.com/xErik/translation_string_extractor/issues
License #
This package is licensed under the MIT license.