From b2073df2406d2652a0a2ec0c0bb7d939e278cacc Mon Sep 17 00:00:00 2001 From: Javier del Canto Date: Thu, 13 Nov 2025 09:24:42 -0300 Subject: [PATCH 1/7] Add .vscode directory to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index acc8fb0..75e160a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ .buildlog/ .history .svn/ +.vscode # IntelliJ related *.iml From 86e8851b67d0a31f499338846e47061ac8718e54 Mon Sep 17 00:00:00 2001 From: Javier del Canto Date: Thu, 13 Nov 2025 09:25:12 -0300 Subject: [PATCH 2/7] Update intl dependency to version 0.20.2 --- pubspec.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 327ad15..e2f0ae5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,10 +11,8 @@ dependencies: flutter: sdk: flutter universal_io: ^2.2.2 - intl: ^0.19.0 + intl: ^0.20.2 dev_dependencies: flutter_test: sdk: flutter - -flutter: \ No newline at end of file From 2e7c8a3498be2489b8e28580f0b74256c33b606e Mon Sep 17 00:00:00 2001 From: Javier del Canto Date: Thu, 13 Nov 2025 09:25:16 -0300 Subject: [PATCH 3/7] Refactor constants and locale file service for improved readability and structure --- lib/src/constants/constants.dart | 23 +++--- lib/src/services/locale_file_service.dart | 87 ++++++++++------------- lib/src/utils/device_locale.dart | 29 ++++---- 3 files changed, 62 insertions(+), 77 deletions(-) diff --git a/lib/src/constants/constants.dart b/lib/src/constants/constants.dart index 94c57cc..c041ec8 100644 --- a/lib/src/constants/constants.dart +++ b/lib/src/constants/constants.dart @@ -1,15 +1,12 @@ -class Constants -{ - static const String assetManifestFilename = 'AssetManifest.json'; +class Constants { + static const String localizedAssetsPath = 'assets/i18n'; - static const String localizedAssetsPath = 'assets/i18n'; + static const String pluralZero = 'zero'; + static const String pluralOne = 'one'; + static const String pluralTwo = 'two'; + static const String pluralFew = 'few'; + static const String pluralMany = 'many'; + static const String pluralOther = 'other'; - static const String pluralZero = 'zero'; - static const String pluralOne = 'one'; - static const String pluralTwo = 'two'; - static const String pluralFew = 'few'; - static const String pluralMany = 'many'; - static const String pluralOther = 'other'; - - static const String pluralValueArg = '{{value}}'; -} \ No newline at end of file + static const String pluralValueArg = '{{value}}'; +} diff --git a/lib/src/services/locale_file_service.dart b/lib/src/services/locale_file_service.dart index c9c0d0b..7bd3875 100644 --- a/lib/src/services/locale_file_service.dart +++ b/lib/src/services/locale_file_service.dart @@ -1,69 +1,58 @@ import 'dart:convert'; import 'package:flutter/services.dart'; -import 'package:flutter_translate/src/constants/constants.dart'; -class LocaleFileService -{ - static Future> getLocaleFiles(List locales, String basePath) async - { - var localizedFiles = await _getAllLocaleFiles(basePath); +class LocaleFileService { + static Future> getLocaleFiles( + List locales, String basePath) async { + var localizedFiles = await _getAllLocaleFiles(basePath); - final files = new Map(); + final files = new Map(); - for(final language in locales.toSet()) - { - var file = _findLocaleFile(language, localizedFiles, basePath); + for (final language in locales.toSet()) { + var file = _findLocaleFile(language, localizedFiles, basePath); - files[language] = file; - } - - return files; + files[language] = file; } - static Future getLocaleContent(String file) async - { - final ByteData? data = await rootBundle.load(file); - - if (data == null) return null; - - return utf8.decode(data.buffer.asUint8List()); - } + return files; + } - static Future> _getAllLocaleFiles(String basePath) async - { - final manifest = await rootBundle.loadString(Constants.assetManifestFilename); + static Future getLocaleContent(String file) async { + final ByteData? data = await rootBundle.load(file); - Map map = jsonDecode(manifest); + if (data == null) return null; - var separator = basePath.endsWith('/') ? '' : '/'; + return utf8.decode(data.buffer.asUint8List()); + } - return map.keys.where((x) => x.startsWith('$basePath$separator')).toList(); - } + static Future> _getAllLocaleFiles(String basePath) async { + final assetManifest = await AssetManifest.loadFromAssetBundle(rootBundle); + final assets = assetManifest.listAssets(); - static String _findLocaleFile(String languageCode, List localizedFiles, String basePath) - { - var file = _getFilepath(languageCode, basePath); + return assets; + } - if(!localizedFiles.contains(file)) - { - if(languageCode.contains('_')) - { - file = _getFilepath(languageCode.split('_').first, basePath); - } - } + static String _findLocaleFile( + String languageCode, List localizedFiles, String basePath) { + var file = _getFilepath(languageCode, basePath); - if(file == null) - { - throw new Exception('The asset file for the language "$languageCode" was not found.'); - } + if (!localizedFiles.contains(file)) { + if (languageCode.contains('_')) { + file = _getFilepath(languageCode.split('_').first, basePath); + } + } - return file; + if (file == null) { + throw new Exception( + 'The asset file for the language "$languageCode" was not found.'); } - static String? _getFilepath(String languageCode, String basePath) - { - var separator = basePath.endsWith('/') ? '' : '/'; + return file; + } - return '$basePath$separator$languageCode.json'; - } + static String? _getFilepath(String languageCode, String basePath) { + var separator = basePath.endsWith('/') ? '' : '/'; + + return '$basePath$separator$languageCode.json'; + } } diff --git a/lib/src/utils/device_locale.dart b/lib/src/utils/device_locale.dart index ac32e86..74a5bf8 100644 --- a/lib/src/utils/device_locale.dart +++ b/lib/src/utils/device_locale.dart @@ -2,23 +2,22 @@ import 'package:flutter/widgets.dart'; import 'package:universal_io/io.dart'; /// Returns the current device locale -Locale? getCurrentLocale() -{ - return _localeFromString(Platform.localeName); +Locale? getCurrentLocale() { + return _localeFromString(Platform.localeName); } -Locale? _localeFromString(String code) -{ - var separator = code.contains('_') ? '_' : code.contains('-') ? '-' : null; +Locale? _localeFromString(String code) { + var separator = code.contains('_') + ? '_' + : code.contains('-') + ? '-' + : null; - if (separator != null) - { - var parts = code.split(RegExp(separator)); + if (separator != null) { + var parts = code.split(RegExp(separator)); - return Locale(parts[0], parts[1]); - } - else - { - return Locale(code); - } + return Locale(parts[0], parts[1]); + } else { + return Locale(code); + } } From dca4fa5a7171250966742f88944997ec79d76512 Mon Sep 17 00:00:00 2001 From: Javier del Canto Date: Thu, 13 Nov 2025 09:27:34 -0300 Subject: [PATCH 4/7] Bump version to 4.1.1 in pubspec.yaml --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index e2f0ae5..08bf58e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_translate description: Flutter Translate is a fully featured localization / internationalization (i18n) library for Flutter. -version: 4.1.0 +version: 4.1.1 homepage: https://jesway.com repository: https://github.com/Jesway/flutter_translate From e27329a4a2eb30bfe9e69ae518539aafc76ddafe Mon Sep 17 00:00:00 2001 From: Javier del Canto Date: Thu, 13 Nov 2025 09:32:21 -0300 Subject: [PATCH 5/7] Refactor locale file retrieval to ensure correct base path filtering --- lib/src/services/locale_file_service.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/services/locale_file_service.dart b/lib/src/services/locale_file_service.dart index 7bd3875..250e5b0 100644 --- a/lib/src/services/locale_file_service.dart +++ b/lib/src/services/locale_file_service.dart @@ -29,7 +29,9 @@ class LocaleFileService { final assetManifest = await AssetManifest.loadFromAssetBundle(rootBundle); final assets = assetManifest.listAssets(); - return assets; + final separator = basePath.endsWith('/') ? '' : '/'; + + return assets.where((x) => x.startsWith('$basePath$separator')).toList(); } static String _findLocaleFile( From 56a0b2ab04e8898b5fdc01bffd55af63bc96685e Mon Sep 17 00:00:00 2001 From: Javier del Canto Date: Thu, 13 Nov 2025 09:33:24 -0300 Subject: [PATCH 6/7] Bump version to 4.1.2 in pubspec.yaml --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 08bf58e..89801d0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_translate description: Flutter Translate is a fully featured localization / internationalization (i18n) library for Flutter. -version: 4.1.1 +version: 4.1.2 homepage: https://jesway.com repository: https://github.com/Jesway/flutter_translate From 3e497e5cac51abab3480d2d391d993e8d3a504fa Mon Sep 17 00:00:00 2001 From: Javier del Canto Date: Thu, 13 Nov 2025 10:56:03 -0300 Subject: [PATCH 7/7] Update CHANGELOG for version 4.1.2: upgrade packages and fix breaking change --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ab4ed6..9062383 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -125,4 +125,9 @@ ## [4.1.0] -- Upgraded packages and SDK version \ No newline at end of file +- Upgraded packages and SDK version + +## [4.1.2] + +- Upgraded packages and SDK version +- Fixed [breaking change](https://docs.flutter.dev/release/breaking-changes/asset-manifest-dot-json) from Flutter \ No newline at end of file