-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Floating-Dartists/feat/localization
Feat/localization
- Loading branch information
Showing
59 changed files
with
1,076 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,5 @@ | ||
include: package:flutter_lints/flutter.yaml | ||
include: package:fd_lints/flutter.yaml | ||
|
||
analyzer: | ||
language: | ||
strict-casts: true | ||
strict-inference: true | ||
strict-raw-types: true | ||
exclude: | ||
- lib/**.g.dart | ||
- test/**.mocks.dart | ||
- lib/generated_plugin_registrant.dart | ||
errors: | ||
missing_required_param: error | ||
unrelated_type_equality_checks: error | ||
missing_return: warning | ||
close_sinks: warning | ||
cancel_subscriptions: warning | ||
parameter_assignments: warning | ||
prefer_final_in_for_each: warning | ||
prefer_mixin: warning | ||
unawaited_futures: warning | ||
unnecessary_await_in_return: warning | ||
unnecessary_null_aware_assignments: warning | ||
use_decorated_box: warning | ||
use_string_buffers: warning | ||
avoid_unnecessary_containers: warning | ||
use_if_null_to_convert_nulls_to_bools: warning | ||
|
||
linter: | ||
rules: | ||
- always_declare_return_types | ||
- avoid_bool_literals_in_conditional_expressions | ||
- avoid_escaping_inner_quotes | ||
- avoid_positional_boolean_parameters | ||
- parameter_assignments | ||
- prefer_null_aware_method_calls | ||
- require_trailing_commas | ||
- use_is_even_rather_than_modulo | ||
- use_named_constants | ||
- use_to_and_as_if_applicable | ||
- prefer_relative_imports | ||
- avoid_unused_constructor_parameters | ||
- sort_child_properties_last | ||
- directives_ordering | ||
- close_sinks | ||
- cancel_subscriptions | ||
- unnecessary_statements | ||
- avoid_annotating_with_dynamic | ||
- prefer_final_locals | ||
- prefer_final_in_for_each | ||
- prefer_interpolation_to_compose_strings | ||
- prefer_mixin | ||
- unawaited_futures | ||
- unnecessary_await_in_return | ||
- unnecessary_lambdas | ||
- unnecessary_null_aware_assignments | ||
- unnecessary_parenthesis | ||
- unnecessary_raw_strings | ||
- use_decorated_box | ||
- use_if_null_to_convert_nulls_to_bools | ||
- use_string_buffers | ||
- avoid_unnecessary_containers | ||
- use_build_context_synchronously | ||
- use_super_parameters | ||
- "lib/src/components/logo/logo.dart" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:path/path.dart' as path; | ||
|
||
Future<void> main(List<String> args) async { | ||
final name = prompt('Label name'); | ||
final cwd = Directory.current.path; | ||
final l10nSrc = Directory(path.join(cwd, 'lib', 'l10n')); | ||
|
||
final frArb = File(path.join(l10nSrc.path, 'flutter_dsfr_fr.arb')); | ||
final frContent = | ||
jsonDecode(await frArb.readAsString()) as Map<String, dynamic>; | ||
|
||
if (frContent.containsKey(name)) { | ||
stderr.writeln('Label "$name" already exists'); | ||
exit(1); | ||
} | ||
|
||
final description = prompt('Label description'); | ||
final frTranslation = prompt('French translation'); | ||
|
||
final files = l10nSrc.listSync().whereType<File>().toList(); | ||
final futures = files.map((file) async { | ||
final newContent = await addLabel(file, name, description, frTranslation); | ||
final b = StringBuffer(); | ||
final string = const JsonEncoder.withIndent(' ').convert(newContent); | ||
b | ||
..write(string) | ||
..writeln(); | ||
|
||
await file.writeAsString(b.toString()); | ||
}); | ||
|
||
await Future.wait(futures); | ||
stdout.writeln('Done!'); | ||
} | ||
|
||
String prompt(String tag) { | ||
stdout.write('$tag?: '); | ||
final answer = stdin.readLineSync(); | ||
if (answer == null || answer.isEmpty) { | ||
throw Exception('$tag is required'); | ||
} | ||
return answer; | ||
} | ||
|
||
Future<Map<String, dynamic>> addLabel( | ||
File file, | ||
String name, | ||
String description, | ||
String frTranslation, | ||
) async { | ||
final content = jsonDecode(await file.readAsString()) as Map<String, dynamic>; | ||
|
||
return { | ||
...content, | ||
"@@last_modified": DateTime.now().toIso8601String(), | ||
name: frTranslation, | ||
"@$name": {"description": description}, | ||
}; | ||
} |
Oops, something went wrong.