From fc8498ae5a1d8a9becea68a1366b9c850dacaac3 Mon Sep 17 00:00:00 2001 From: Muhammad Mohiuddin Date: Thu, 20 Jun 2024 21:49:40 +0200 Subject: [PATCH] refactor --- example/strings.i18n.yaml | 3 +++ example/strings_de.i18n.yaml | 3 +++ lib/builder.dart | 12 ++++++++---- pubspec.yaml | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 example/strings.i18n.yaml create mode 100644 example/strings_de.i18n.yaml diff --git a/example/strings.i18n.yaml b/example/strings.i18n.yaml new file mode 100644 index 0000000..bf47d3c --- /dev/null +++ b/example/strings.i18n.yaml @@ -0,0 +1,3 @@ +strings: + ok: OK + cancel: CANCEL \ No newline at end of file diff --git a/example/strings_de.i18n.yaml b/example/strings_de.i18n.yaml new file mode 100644 index 0000000..23ba45a --- /dev/null +++ b/example/strings_de.i18n.yaml @@ -0,0 +1,3 @@ +strings: + ok: OK + cancel: STORNIEREN \ No newline at end of file diff --git a/lib/builder.dart b/lib/builder.dart index cb6e962..fbe304b 100644 --- a/lib/builder.dart +++ b/lib/builder.dart @@ -38,12 +38,16 @@ class YamlBasedBuilder implements Builder { final currentMap = loadYaml(contents) as YamlMap; final currentKeys = currentMap.allKeys; - final allFiles = await buildStep.findAssets(Glob('**.i18n.yaml')).toList(); + final pattern = Glob('**.i18n.yaml'); + final allFiles = await buildStep.findAssets(pattern).toList(); + final currentFileName = currentFile.pathSegments.last.replaceAll( + '.i18n.yaml', + '', + ); final defaultFile = allFiles.firstWhere( (e) { - final name = e.uri.pathSegments.last.replaceAll(".i18n.yaml", ""); - - return !name.contains('_') && currentFile.pathSegments.last.replaceAll(".i18n.yaml", "").startsWith(name); + final name = e.uri.pathSegments.last.replaceAll('.i18n.yaml', ''); + return !name.contains('_') && currentFileName.startsWith(name); }, ); diff --git a/pubspec.yaml b/pubspec.yaml index 362909c..7c2d049 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: glob: ^2.0.0 dev_dependencies: - lints: ^2.0.0 + lints: ^4.0.0 test: ^1.16.8 build_runner: ^2.0.0 build_web_compilers: ^4.0.0