Skip to content

Commit

Permalink
Merge pull request #10 from roipeker/roi_dev
Browse files Browse the repository at this point in the history
## [1.0.9+18]
  • Loading branch information
roipeker committed Jul 25, 2021
2 parents 7a4082a + 25c8019 commit 711368e
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 78 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,11 @@
## [1.0.9+18]
- README improvements.
- new arguments inside variables.
- fixes Locale canonicalization, now uses the Flutter way: en_US instead of en-us
- fixes Intl generator error when only languageCode_countryCode is defined (without the languageCode only fallback).
- Much improved RegExp for variable detection in GoogleSheet cells, when GoogleTranslate corrupts the format breaking the generated code.
- Automatic iOS Info.plist sync with locales (only macos).

## [1.0.8+17]
- Improved support for `arb` generation based on `intl` standards!
- Fixed error for clearing unused rows when you have more than one worksheet.
Expand Down
50 changes: 48 additions & 2 deletions README.md
Expand Up @@ -102,7 +102,7 @@ To store "variables" or placeholders in your strings to be replaced later in you
"Welcome back {{user}}, today is {{date}}."
```

It will store the values in the sheet as {{0}} {{1}} and so on, to avoid complications with GoogleTranslate, and it will
It will store the values in the sheet as {{0}} {{1}} and so on, to avoid complications with GoogleTranslate (although in rare cases GTranslate will truncate the {{}} somehow, don't worry), and it will
generate a *vars.lock* file in the directory where you point your "entry_file" in config.

So you can define your own pattern for the code/json generation:
Expand Down Expand Up @@ -134,14 +134,19 @@ This command tool is in alpha state, but don't worry, as it doesn't touch any of

Also... when you specify an --output that ends with `.yaml`, you will have a pretty cool template to plug into `fts run` :)

- If you run the cli on macos, `fts` keeps your [iOS app bundle](https://flutter.dev/docs/development/accessibility-and-localization/internationalization#localizing-for-ios-updating-the-ios-app-bundle) synced automatically with the locales! One thing less to worry about.

### arb and Intl:

We have an experimental support for arb generation. In config.yaml just set (or create if it doesnt exists) this field.
(This tag will soon be changed to something more "generic" as arb output).

```yaml
intl:
enabled: true
```


Example of .arb readable metadata:
```yaml
today: "Today is {{date}}, and is hot."
Expand All @@ -156,6 +161,7 @@ Example of .arb readable metadata:
For plurals, we have a custom way of writing the dictionary. Just use `plural:variableName:` so `fts` knows how to generate the String.
Remember that `other` is mandatory (the default value) when you use plurals.

Raw way of adding the metadata:
```yaml
### not required, but you will be a much cooler dev if you provide context :)
"@messageCount":
Expand All @@ -175,15 +181,55 @@ Remember that `other` is mandatory (the default value) when you use plurals.
Previous yaml will output in *lib/l10n/app_en.arb* (or the path you defined in arb-dir inside l10n.yaml) :
`"messageCount": "{count,plural, =0{No new messages}=1{You have 1 new message}=2{You have a couple of messages}other{You have {count} new messages}}",`

Now you can also capture internal variables in the plural/selector modifiers, and add the type and parsing information into it!
```yaml
messageCount:
plural:count:
=0: No new messages
=1: You have 1 new message. You won {{money:int:compactCurrency(decimalDigits:2,name:"Euro",symbol:"€")}}, congratulations!
=2: You have a couple of messages
other: You have {{count:int}} new messages
```

All {{variables}} supports this special way to define name, type, format, arguments.
Useful when you don't want to use the @meta arb approach.

The "format" part applies to [NumberFormatter](https://api.flutter.dev/flutter/intl/NumberFormat-class.html) and [DateFormat](https://api.flutter.dev/flutter/intl/DateFormat-class.html) constructors.
`{{variable:Type:Format(OptionalNamedArguments)}}`


Selectors (like gender), are also included for the arb generation, although not yet supported on intl for code generation:
```yaml
roleWelcome:
selector:role:
admin: Hi admin!
manager: Hi manager!
other: Hi visitor.
```
output arb:
```arb
"mainRoleWelcome": "{role, select, admin {Hi admin!} manager {Hi manager!} other {Hi visitor.} }",
"@mainRoleWelcome": {
"description": "Auto-generated for mainRoleWelcome",
"placeholders": {
"role": {
"type": "String"
}
}
}
```

We will try to provide a richer experience integrating more libraries outputs in the future.

### 📝 Considerations:

- Is preferable to keep the *trconfig.yaml* in the root of your project, some commands assumes that location (like arb generation).

- When using arb output, make sure you have *l10n.yaml* next to the *trconfig.yaml* at the root of your project.

- In your spreadsheet, the first column will always be your "keys", don't change that, don't move the column.

- In your `trconfig.yaml`, the first locale you define is your **master** language:
- In your *trconfig.yaml*, the first locale you define is your **master** language:

```yaml
locales:
Expand Down
12 changes: 11 additions & 1 deletion bin/main.dart
@@ -1,7 +1,17 @@
import 'dart:io';

import 'package:flutter_translation_sheet/src/runner.dart';

Future<void> main(List<String> args) async {
// var a = 'Aca hay {{{{123}} items {a} and 3';

//
// var res = _captureGoogleTranslateVar.allMatches(a);
// res.forEach((e) {
// var key = e.group(0)!;
// var res2 = key.replaceAll(_replaceAndLeaveDigitVar, '');
// print(res2);
// });
// print(a);
exit(await FTSCommandRunner().run(args));
}

6 changes: 3 additions & 3 deletions lib/src/io/dart_gen.dart
Expand Up @@ -29,11 +29,13 @@ void createLocalesFiles(Map<String, Map<String, String>> localesMap) {
localeMap,
beautify: true,
);

/// save dart file.
if (config.useDartMaps && config.validTranslationFile) {
/// Dart translation file.
var data = prettyJson(localeMap);
/// cleanup special chars in translated String.
data = data.replaceAll(r'$', '\\\$');

var localeInfo = langInfoFromKey(localeName);
var className = 'Locale${localeName.pascalCase}';
var fileData = '''
Expand Down Expand Up @@ -216,13 +218,11 @@ String _buildTKeyMap({
var classCanBeConst = false;
for (var k in map.keys) {
final v = map[k];

/// special case for @properties n .arb (invalid for dart files)
if (k.startsWith('@')) {
trace('Skipping property $k from Keys');
continue;
}

/// TODO: find bad characters for the field...
var fieldName = k.trim().camelCase;
// fieldName = fieldName.replaceAll(':', '_');
Expand Down
7 changes: 6 additions & 1 deletion lib/src/io/env_parser.dart
Expand Up @@ -233,11 +233,16 @@ class EnvConfig {
String paramOutputPattern1 = '{{';
String paramOutputPattern2 = '}}';
bool intlEnabled = false;

// param_output_pattern
bool useDartMaps = false;

String get iosDirPath {
return p.canonicalize(p.join(configProjectDir, 'ios'));
}

String get intlYamlPath {
return !intlEnabled ? '' : joinDir([configProjectDir,'l10n.yaml']);
return !intlEnabled ? '' : joinDir([configProjectDir, 'l10n.yaml']);
}

String get inputYamlDir {
Expand Down

0 comments on commit 711368e

Please sign in to comment.