Skip to content

Commit ca7f430

Browse files
Umesh Shresthastha-ums
Umesh Shrestha
authored andcommitted
No translation for the key callback
1 parent 8048ff5 commit ca7f430

File tree

8 files changed

+57
-85
lines changed

8 files changed

+57
-85
lines changed

example/ios/Flutter/AppFrameworkInfo.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>8.0</string>
24+
<string>9.0</string>
2525
</dict>
2626
</plist>

example/ios/Podfile

+15-61
Original file line numberDiff line numberDiff line change
@@ -10,78 +10,32 @@ project 'Runner', {
1010
'Release' => :release,
1111
}
1212

13-
def parse_KV_file(file, separator='=')
14-
file_abs_path = File.expand_path(file)
15-
if !File.exists? file_abs_path
16-
return [];
13+
def flutter_root
14+
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
15+
unless File.exist?(generated_xcode_build_settings_path)
16+
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
1717
end
18-
generated_key_values = {}
19-
skip_line_start_symbols = ["#", "/"]
20-
File.foreach(file_abs_path) do |line|
21-
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
22-
plugin = line.split(pattern=separator)
23-
if plugin.length == 2
24-
podname = plugin[0].strip()
25-
path = plugin[1].strip()
26-
podpath = File.expand_path("#{path}", file_abs_path)
27-
generated_key_values[podname] = podpath
28-
else
29-
puts "Invalid plugin specification: #{line}"
30-
end
18+
19+
File.foreach(generated_xcode_build_settings_path) do |line|
20+
matches = line.match(/FLUTTER_ROOT\=(.*)/)
21+
return matches[1].strip if matches
3122
end
32-
generated_key_values
23+
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
3324
end
3425

26+
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
27+
28+
flutter_ios_podfile_setup
29+
3530
target 'Runner' do
3631
use_frameworks!
3732
use_modular_headers!
3833

39-
# Flutter Pod
40-
41-
copied_flutter_dir = File.join(__dir__, 'Flutter')
42-
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
43-
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
44-
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
45-
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
46-
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
47-
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.
48-
49-
generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
50-
unless File.exist?(generated_xcode_build_settings_path)
51-
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
52-
end
53-
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
54-
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];
55-
56-
unless File.exist?(copied_framework_path)
57-
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
58-
end
59-
unless File.exist?(copied_podspec_path)
60-
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
61-
end
62-
end
63-
64-
# Keep pod path relative so it can be checked into Podfile.lock.
65-
pod 'Flutter', :path => 'Flutter'
66-
67-
# Plugin Pods
68-
69-
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
70-
# referring to absolute paths on developers' machines.
71-
system('rm -rf .symlinks')
72-
system('mkdir -p .symlinks/plugins')
73-
plugin_pods = parse_KV_file('../.flutter-plugins')
74-
plugin_pods.each do |name, path|
75-
symlink = File.join('.symlinks', 'plugins', name)
76-
File.symlink(path, symlink)
77-
pod name, :path => File.join(symlink, 'ios')
78-
end
34+
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
7935
end
8036

8137
post_install do |installer|
8238
installer.pods_project.targets.each do |target|
83-
target.build_configurations.each do |config|
84-
config.build_settings['ENABLE_BITCODE'] = 'NO'
85-
end
39+
flutter_additional_ios_build_settings(target)
8640
end
8741
end

example/ios/Runner.xcodeproj/project.pbxproj

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 46;
6+
objectVersion = 50;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -168,7 +168,7 @@
168168
97C146E61CF9000F007C117D /* Project object */ = {
169169
isa = PBXProject;
170170
attributes = {
171-
LastUpgradeCheck = 1020;
171+
LastUpgradeCheck = 1300;
172172
ORGANIZATIONNAME = "";
173173
TargetAttributes = {
174174
97C146ED1CF9000F007C117D = {
@@ -359,7 +359,7 @@
359359
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
360360
GCC_WARN_UNUSED_FUNCTION = YES;
361361
GCC_WARN_UNUSED_VARIABLE = YES;
362-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
362+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
363363
MTL_ENABLE_DEBUG_INFO = NO;
364364
SDKROOT = iphoneos;
365365
SUPPORTED_PLATFORMS = iphoneos;
@@ -442,7 +442,7 @@
442442
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
443443
GCC_WARN_UNUSED_FUNCTION = YES;
444444
GCC_WARN_UNUSED_VARIABLE = YES;
445-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
445+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
446446
MTL_ENABLE_DEBUG_INFO = YES;
447447
ONLY_ACTIVE_ARCH = YES;
448448
SDKROOT = iphoneos;
@@ -492,7 +492,7 @@
492492
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
493493
GCC_WARN_UNUSED_FUNCTION = YES;
494494
GCC_WARN_UNUSED_VARIABLE = YES;
495-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
495+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
496496
MTL_ENABLE_DEBUG_INFO = NO;
497497
SDKROOT = iphoneos;
498498
SUPPORTED_PLATFORMS = iphoneos;

example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1020"
3+
LastUpgradeVersion = "1300"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

example/lib/main.dart

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ void main() async {
1818
Locale('ru', 'RU')
1919
],
2020
path: 'resources/langs',
21+
onLocaleKeyNotFound: (key, locale) {
22+
print('Locale key not found $key ${locale.languageCode}');
23+
},
2124
child: MyApp(),
2225
// fallbackLocale: Locale('en', 'US'),
2326
// startLocale: Locale('de', 'DE'),

lib/src/easy_localization_app.dart

+27-16
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,23 @@ class EasyLocalization extends StatefulWidget {
7676
/// @Default value `errorWidget = ErrorWidget()`
7777
final Widget Function(FlutterError? message)? errorWidget;
7878

79-
EasyLocalization({
80-
Key? key,
81-
required this.child,
82-
required this.supportedLocales,
83-
required this.path,
84-
this.fallbackLocale,
85-
this.startLocale,
86-
this.useOnlyLangCode = false,
87-
this.useFallbackTranslations = false,
88-
this.assetLoader = const RootBundleAssetLoader(),
89-
this.saveLocale = true,
90-
this.errorWidget,
91-
}) : assert(supportedLocales.isNotEmpty),
79+
/// callback when key is not available in translations of the locale
80+
final Function(String key, Locale locale)? onLocaleKeyNotFound;
81+
82+
EasyLocalization(
83+
{Key? key,
84+
required this.child,
85+
required this.supportedLocales,
86+
required this.path,
87+
this.fallbackLocale,
88+
this.startLocale,
89+
this.useOnlyLangCode = false,
90+
this.useFallbackTranslations = false,
91+
this.assetLoader = const RootBundleAssetLoader(),
92+
this.saveLocale = true,
93+
this.errorWidget,
94+
this.onLocaleKeyNotFound})
95+
: assert(supportedLocales.isNotEmpty),
9296
assert(path.isNotEmpty),
9397
super(key: key) {
9498
EasyLocalization.logger.debug('Start');
@@ -162,6 +166,7 @@ class _EasyLocalizationState extends State<EasyLocalization> {
162166
delegate: _EasyLocalizationDelegate(
163167
localizationController: localizationController,
164168
supportedLocales: widget.supportedLocales,
169+
onLocaleKeyNotFound: widget.onLocaleKeyNotFound,
165170
),
166171
);
167172
}
@@ -241,12 +246,16 @@ class _EasyLocalizationProvider extends InheritedWidget {
241246
class _EasyLocalizationDelegate extends LocalizationsDelegate<Localization> {
242247
final List<Locale>? supportedLocales;
243248
final EasyLocalizationController? localizationController;
249+
final Function(String key, Locale locale)? onLocaleKeyNotFound;
244250

245251
/// * use only the lang code to generate i18n file path like en.json or ar.json
246252
// final bool useOnlyLangCode;
247253

248-
_EasyLocalizationDelegate(
249-
{this.localizationController, this.supportedLocales}) {
254+
_EasyLocalizationDelegate({
255+
this.localizationController,
256+
this.supportedLocales,
257+
this.onLocaleKeyNotFound,
258+
}) {
250259
EasyLocalization.logger.debug('Init Localization Delegate');
251260
}
252261

@@ -262,7 +271,9 @@ class _EasyLocalizationDelegate extends LocalizationsDelegate<Localization> {
262271

263272
Localization.load(value,
264273
translations: localizationController!.translations,
265-
fallbackTranslations: localizationController!.fallbackTranslations);
274+
fallbackTranslations: localizationController!.fallbackTranslations,
275+
onLocaleKeyNotFound: onLocaleKeyNotFound);
276+
266277
return Future.value(Localization.instance);
267278
}
268279

lib/src/localization.dart

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'translations.dart';
77
class Localization {
88
Translations? _translations, _fallbackTranslations;
99
late Locale _locale;
10+
late Function(String key, Locale locale)? _onLocaleKeyNotFound;
1011

1112
final RegExp _replaceArgRegex = RegExp('{}');
1213
final RegExp _linkKeyMatcher =
@@ -29,11 +30,13 @@ class Localization {
2930
static bool load(
3031
Locale locale, {
3132
Translations? translations,
33+
Function(String key, Locale locale)? onLocaleKeyNotFound,
3234
Translations? fallbackTranslations,
3335
}) {
3436
instance._locale = locale;
3537
instance._translations = translations;
3638
instance._fallbackTranslations = fallbackTranslations;
39+
instance._onLocaleKeyNotFound = onLocaleKeyNotFound;
3740
return translations == null ? false : true;
3841
}
3942

@@ -188,6 +191,7 @@ class Localization {
188191
String _resolve(String key, {bool logging = true, bool fallback = true}) {
189192
var resource = _translations?.get(key);
190193
if (resource == null) {
194+
if (_onLocaleKeyNotFound != null) _onLocaleKeyNotFound!(key, _locale);
191195
if (logging) {
192196
EasyLocalization.logger.warning('Localization key [$key] not found');
193197
}

0 commit comments

Comments
 (0)