Skip to content

Commit

Permalink
v1.0.23
Browse files Browse the repository at this point in the history
## [1.0.23]
- fix bug with empty `param_output_pattern` and `Fts.tr(namedArgs:)`
- added `fts extract --exclude path1,pathN` to exclude paths from capture.
- added `fts extract --clean` to remove duplicated records.
- added `Fts.useMasterTextAsKey` to use master text as key for translation, for example `"Hello".tr()`
- added `Fts.onSystemLocaleChanged` notifier, receives the events when the window detects a locale change (like on Android 13)
- change pubspec dependencies to NOT force any constrains (and avoid errors on flutter pub get)
- cleaned up code.
- renamed SimpleLangPicker to LangPickerMaterial and added LangPickerCupertino
  • Loading branch information
Roi Peker committed Oct 21, 2022
1 parent 7c3cd46 commit 54488b2
Show file tree
Hide file tree
Showing 20 changed files with 408 additions and 275 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,13 @@
## [1.0.23]
- fix bug with empty `param_output_pattern` and `Fts.tr(namedArgs:)`
- added `fts extract --exclude path1,pathN` to exclude paths from capture.
- added `fts extract --clean` to remove duplicated records.
- added `Fts.useMasterTextAsKey` to use master text as key for translation, for example `"Hello".tr()`
- added `Fts.onSystemLocaleChanged` notifier, receives the events when the window detects a locale change (like on Android 13)
- change pubspec dependencies to NOT force any constrains (and avoid errors on flutter pub get)
- cleaned up code.
- renamed SimpleLangPicker to LangPickerMaterial and added LangPickerCupertino

## [1.0.22]
- fix generated dart files format.
- made "run" the default command when no arguments are passed.
Expand Down
30 changes: 26 additions & 4 deletions README.md
Expand Up @@ -41,6 +41,25 @@ Manage all your Strings and translation from a single place.


## News 📰
Since v1.0.23:

`fts extract --exclude path1,pathN` excludes paths from the extraction capture.
`fts extract --clean` removes duplicated text results.

If you capture your text with `extract` from a source code, you could use
`Fts.useMasterTextAsKey=true`, to use the master text as key for translation,
for example `"Hello world".tr()`

You can detect OS locale changes with
```dart
Fts.onSystemLocaleChanged.addListener((){
print(Fts.deviceLocale);
});
```
Receives the events when the window detects a locale change (like Android 13 feature)

SimpleLangPicker now is `LangPickerMaterial` and a new iOS flavor, `LangPickerCupertino`.


Since v1.0.22:

Expand Down Expand Up @@ -83,11 +102,11 @@ Keys.title.tr();
```

If you work with RTL languages, you can use `Fts.textDirection` to assign the `Directionality`.
Or better, use the `FtsDelegate()` !
Or better, use the `Fts.delegate` !

```dart
return MaterialApp(
localizationsDelegates: const [FtsDelegate()],
localizationsDelegates: const [Fts.delegate],
home: MyHomePage(),
);
```
Expand Down Expand Up @@ -434,14 +453,17 @@ output arb:

### Widgets 📐

You can use `SimpleLangPicker()` widget when you generate the dart code (included by default in `TData` class]).
/// Simple language picker (Cupertino style).
You can use `LangPickerMaterial()` and `LangPickerCupertino()` widgets when you generate the dart code (included by default in `TData` class]).

Is meant to be a quick tester to change languages. For example, if you use GetX for translations:

```dart
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
actions: [
SimpleLangPicker(
LangPickerMaterial(
onSelected: Get.updateLocale,
selected: Get.locale,
),
Expand Down
2 changes: 1 addition & 1 deletion bin/main.dart
Expand Up @@ -9,7 +9,7 @@ import 'package:flutter_translation_sheet/src/utils/errors.dart';
Future<void> main(List<String> args) async {
_checkEnvironment();
try {
if(args.isEmpty){
if (args.isEmpty) {
args = ['run'];
}
exit(await FTSCommandRunner().run(args));
Expand Down
3 changes: 1 addition & 2 deletions lib/flutter_translation_sheet.dart
Expand Up @@ -4,5 +4,4 @@ export 'src/io/io.dart';
export 'src/common.dart';
export 'package:recase/recase.dart';
export 'src/samples/generator.dart';
export 'src/data/strings.dart';
export 'src/commands/commands.dart';
export 'src/data/strings.dart';
2 changes: 0 additions & 2 deletions lib/src/commands/commands.dart

This file was deleted.

130 changes: 0 additions & 130 deletions lib/src/commands/init.dart

This file was deleted.

1 change: 0 additions & 1 deletion lib/src/commands/run.dart

This file was deleted.

1 change: 0 additions & 1 deletion lib/src/data/strings.dart
Expand Up @@ -55,4 +55,3 @@ flutter:
assets:
- ##replace
''';

28 changes: 22 additions & 6 deletions lib/src/io/commands.dart
@@ -1,9 +1,6 @@
import 'dart:convert';
import 'dart:io';

import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:args/src/arg_parser.dart';
import 'package:dcli/dcli.dart';
import 'package:flutter_translation_sheet/flutter_translation_sheet.dart';
import 'package:yaml/yaml.dart';
Expand All @@ -19,10 +16,24 @@ class ExtractStringCommand extends Command<int> {
final String name = 'extract';
final Future Function() exec;


ExtractStringCommand(this.exec) {
argParser.addOption('path',
abbr: 'p',
help: 'Set the /lib folder to search for Strings in dart files.');
help:
'Path used to search for strings (recursive), for example, pass the /lib folder to search for Strings in dart files.');
argParser.addOption('exclude',
defaultsTo: null,
abbr: 'r',
help:
'Comma separated list of files and folders to be excluded from the extraction.');

argParser.addFlag('clean',
defaultsTo: false,
abbr: 'c',
help:
'Clean results, preventing duplicates');

argParser.addOption('output',
defaultsTo: 'strings.yaml',
abbr: 'o',
Expand All @@ -36,7 +47,7 @@ class ExtractStringCommand extends Command<int> {
abbr: 's',
help:
'Toggles permissive mode, capturing strings without spaces in it.');
addConfigOption(argParser);
// addConfigOption(argParser);
}

@override
Expand All @@ -52,6 +63,12 @@ class ExtractStringCommand extends Command<int> {
if (argResults!.wasParsed('permissive')) {
extractPermissive = argResults!['permissive']!;
}
if (argResults!.wasParsed('exclude')) {
extractExcludePaths = argResults!['exclude']!;
}
if (argResults!.wasParsed('clean')) {
extractCleanResults = argResults!['clean']!;
}
if (argResults!.wasParsed('path')) {
libFolder = argResults!['path']!.trim();
}
Expand Down Expand Up @@ -268,7 +285,6 @@ void startConfig(String path) {
var f = File(path);
if (!f.existsSync()) {
error('Error: $path config file not found');

/// ask to create from template.
var useCreateTemplate = confirm(
yellow(
Expand Down
18 changes: 14 additions & 4 deletions lib/src/io/dart_gen.dart
Expand Up @@ -38,7 +38,7 @@ void createLocalesFiles(
addAssetsToPubSpec();
}

for (var localeKey in localesMap.keys) {
for (var localeKey in localesMap.keys) {
// trace('Locale ', localeKey);
var localeName = normLocale(localeKey);
var localeMap = localesMap[localeKey]!;
Expand Down Expand Up @@ -145,9 +145,15 @@ void createFtsUtilsFile() {
config.paramFtsUtilsArgsPattern,
);

var patt = config.paramOutputPattern;
if (patt.isEmpty || patt == '*') {
trace("PARAM ISFUCKED! $patt");
patt = '{*}';
}
patt = patt.replaceFirst('*', '\$key');
fileContent = fileContent.replaceFirst(
'##namedArgsPattern',
config.paramOutputPattern.replaceFirst('*', '\$key'),
patt,
);

var importString = imports.map((e) => "import '$e';").join('\n');
Expand Down Expand Up @@ -250,6 +256,7 @@ abstract class $_tClassName {
var fileContent = '''
// ignore_for_file: lines_longer_than_80_chars
import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
$_imports
Expand All @@ -259,8 +266,11 @@ $_classAppLocales
$_kLangVoTemplate
/// demo widget
$kSimpleLangPickerWidget
/// demo widgets
$kLangPickerMaterial
$kLangPickerCupertino
''';
if (save) {
Expand Down
1 change: 0 additions & 1 deletion lib/src/io/dart_localization_gen.dart

This file was deleted.

9 changes: 3 additions & 6 deletions lib/src/io/env_parser.dart
Expand Up @@ -2,12 +2,9 @@ import 'dart:io';

import 'package:dcli/dcli.dart';
import 'package:flutter_translation_sheet/flutter_translation_sheet.dart';
import 'package:googleapis/servicemanagement/v1.dart';
import 'package:path/path.dart' as p;
import 'package:yaml/yaml.dart';

import '../utils/utils.dart';

const defaultConfigEnvPath = 'trconfig.yaml';
EnvConfig config = EnvConfig._();
String configPath = '';
Expand Down Expand Up @@ -57,7 +54,7 @@ void loadEnv({
config.dartTKeysId = doc?['dart']?['keys_id'] ?? '';
config.useDartMaps = doc?['dart']?['use_maps'] ?? false;
config.dartTranslationsId = doc?['dart']?['translations_id'] ?? '';
config.paramOutputPattern = doc?['param_output_pattern'] ?? '';
config.paramOutputPattern = doc?['param_output_pattern'] ?? '{*}';
config.resolveLinkedKeys = doc?['resolve_linked_keys'] ?? false;
config.paramFtsUtilsArgsPattern =
doc?['dart']?['fts_utils_args_pattern'] ?? '%s';
Expand Down Expand Up @@ -115,9 +112,9 @@ See https://cloud.google.com/translate/docs/languages for a list of supported tr
exit(2);
}
if (config.tableId == null) {
config.tableId = 'Sheet1';
trace(
'$defaultConfigEnvPath: [gsheets:worksheet] not defined, add it.');
exit(2);
'$defaultConfigEnvPath: [gsheets:worksheet] not defined, will default to "Sheet1", make sure it matches.');
}
var _sheetUrl =
'https://docs.google.com/spreadsheets/d/${config.sheetId}/edit#gid=0';
Expand Down

0 comments on commit 54488b2

Please sign in to comment.