diff --git a/CHANGELOG.md b/CHANGELOG.md index 23eb554..b055eaa 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [2.1.0] - 2020-06-16 +### Added +-Support for a multi module architecture + ## [2.0.0] - 2020-02-10 ### Breaking -isInTest => showLocalizationKeys diff --git a/README.md b/README.md index d7392df..8754801 100755 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ icapps_translations: api_key: 'enter-your-api-key' default_language: 'nl' languages: ['en', 'nl'] + locale_assets_path: 'assets/locale/' //This is the location where your json files should be saved. + assets_path: 'assets/locale/' //This is the location where your json files are located in your flutter app. ``` set an env variable for your api_key diff --git a/bin/icapps_translations.dart b/bin/icapps_translations.dart index d7c98d6..34e8249 100644 --- a/bin/icapps_translations.dart +++ b/bin/icapps_translations.dart @@ -11,8 +11,12 @@ import 'src/translation_file_writer.dart'; const baseUrl = 'https://translations.icapps.com/api/translations/'; -final outputDir = join('lib', 'util', 'locale'); -final assetsDir = join('assets', 'locale'); +final defaultOutputDir = join('lib', 'util', 'locale'); +final defaultAssetsDir = join('assets', 'locale'); + +final outputDir = defaultOutputDir; +var localeAssetsDir = defaultAssetsDir; +var assetsDir = defaultAssetsDir; Params params; Map defaultTranslations; @@ -26,9 +30,9 @@ Future main(List args) async { await parsePubspec(pubspecYaml); - final localeFolder = Directory(join(Directory.current.path, assetsDir)); + final localeFolder = Directory(join(Directory.current.path, localeAssetsDir)); if (!localeFolder.existsSync()) { - print('assets/locale folder does not yet exist.'); + print('$localeAssetsDir folder does not yet exist.'); print('Creating folder...'); localeFolder.createSync(recursive: true); } @@ -60,7 +64,8 @@ Future _buildJson(String language) async { throw Exception( '\n\nFailed to get $url with statuscode ${response.statusCode}\n'); } - final file = File(join(Directory.current.path, assetsDir, '$language.json')); + final file = + File(join(Directory.current.path, localeAssetsDir, '$language.json')); const encoder = JsonEncoder.withIndent(' '); final changedBody = response.body.replaceAll(r'\\n', r'\n'); final body = json.decode(changedBody); @@ -124,7 +129,7 @@ void createLocalizationFile() { ..writeln(' return localizations;') ..writeln(' }') ..writeln( - " final jsonContent = await rootBundle.loadString('assets/locale/\${locale.languageCode}.json');") + " final jsonContent = await rootBundle.loadString('$assetsDir\${locale.languageCode}.json');") ..writeln( ' final Map values = json.decode(jsonContent);') ..writeln(' localizations._localisedValues = values;') @@ -220,7 +225,8 @@ void createLocalizationDelegateFile() { ..writeln(' @override') ..writeln(' Future load(Locale locale) async {') ..writeln(' activeLocale = newLocale ?? locale;') - ..writeln(' return Localization.load(activeLocale, showLocalizationKeys: showLocalizationKeys);') + ..writeln( + ' return Localization.load(activeLocale, showLocalizationKeys: showLocalizationKeys);') ..writeln(' }') ..writeln() ..writeln(' @override') diff --git a/bin/src/params.dart b/bin/src/params.dart index 67d48a3..5698b66 100644 --- a/bin/src/params.dart +++ b/bin/src/params.dart @@ -2,6 +2,8 @@ import 'dart:io'; import 'package:yaml/yaml.dart'; +import '../icapps_translations.dart'; + class Params { static const icappsTranslationsYaml = 'icapps_translations'; static const ENV_API_KEY = 'API_KEY_ICAPPS_TRANSLATIONS'; @@ -67,5 +69,17 @@ class Params { if (!languages.contains(defaultLanguage)) { throw Exception('default language is not included in the languages list'); } + + localeAssetsDir = config['locale_assets_path']; + localeAssetsDir ??= defaultAssetsDir; + if (!localeAssetsDir.endsWith('/')) { + localeAssetsDir += '/'; + } + + assetsDir = config['assets_path']; + assetsDir ??= defaultAssetsDir; + if (!assetsDir.endsWith('/')) { + assetsDir += '/'; + } } } diff --git a/example/.flutter-plugins b/example/.flutter-plugins new file mode 100644 index 0000000..d851eab --- /dev/null +++ b/example/.flutter-plugins @@ -0,0 +1,2 @@ +# This is a generated file; do not edit or check into version control. +shared_preferences=/Users/vanlooverenkoen/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.3+4/ diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies new file mode 100644 index 0000000..2e12ac4 --- /dev/null +++ b/example/.flutter-plugins-dependencies @@ -0,0 +1 @@ +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.3+4/","dependencies":[]}],"android":[{"name":"shared_preferences","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.3+4/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"shared_preferences","dependencies":[]}],"date_created":"2020-06-16 11:11:44.284440","version":"1.17.3"} \ No newline at end of file diff --git a/example/assets/locale/en.json b/example/assets/locale/en.json deleted file mode 100644 index bd380b6..0000000 --- a/example/assets/locale/en.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "app_title": "Flutter Template EN", - "welcome_message": "Welcome" -} \ No newline at end of file diff --git a/example/assets/locale/nl.json b/example/assets/locale/nl.json deleted file mode 100644 index 9fc6e74..0000000 --- a/example/assets/locale/nl.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "app_title": "Flutter Template NL", - "welcome_message": "Welkom" -} \ No newline at end of file diff --git a/example/assets/localization/en.json b/example/assets/localization/en.json new file mode 100644 index 0000000..20057c2 --- /dev/null +++ b/example/assets/localization/en.json @@ -0,0 +1,3 @@ +{ + "welcome_message": "Hi There" +} \ No newline at end of file diff --git a/example/assets/localization/nl.json b/example/assets/localization/nl.json new file mode 100644 index 0000000..805bf85 --- /dev/null +++ b/example/assets/localization/nl.json @@ -0,0 +1,3 @@ +{ + "welcome_message": "Hallo daar" +} \ No newline at end of file diff --git a/example/ios/Flutter/Flutter.podspec b/example/ios/Flutter/Flutter.podspec new file mode 100644 index 0000000..5ca3041 --- /dev/null +++ b/example/ios/Flutter/Flutter.podspec @@ -0,0 +1,18 @@ +# +# NOTE: This podspec is NOT to be published. It is only used as a local source! +# + +Pod::Spec.new do |s| + s.name = 'Flutter' + s.version = '1.0.0' + s.summary = 'High-performance, high-fidelity mobile apps.' + s.description = <<-DESC +Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS. + DESC + s.homepage = 'https://flutter.io' + s.license = { :type => 'MIT' } + s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } + s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s } + s.ios.deployment_target = '8.0' + s.vendored_frameworks = 'Flutter.framework' +end diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index 997dc04..0f6d41e 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -1,10 +1,12 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=/Users/hannesvandenberghe/Developer/flutter" -export "FLUTTER_APPLICATION_PATH=/Users/hannesvandenberghe/Developer/FlutFlut/flutter-icapps-translations/example" -export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_ROOT=/Users/vanlooverenkoen/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/vanlooverenkoen/Documents/work/flutter-icapps-translations/example" +export "FLUTTER_TARGET=/Users/vanlooverenkoen/Documents/work/flutter-icapps-translations/example/lib/main.dart" export "FLUTTER_BUILD_DIR=build" export "SYMROOT=${SOURCE_ROOT}/../build/ios" -export "FLUTTER_FRAMEWORK_DIR=/Users/hannesvandenberghe/Developer/flutter/bin/cache/artifacts/engine/ios" +export "OTHER_LDFLAGS=$(inherited) -framework Flutter" +export "FLUTTER_FRAMEWORK_DIR=/Users/vanlooverenkoen/flutter/bin/cache/artifacts/engine/ios" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=1" +export "TRACK_WIDGET_CREATION=true" diff --git a/example/ios/Podfile b/example/ios/Podfile index 64ba749..5a69b89 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -15,54 +15,66 @@ def parse_KV_file(file, separator='=') if !File.exists? file_abs_path return []; end - pods_ary = [] + generated_key_values = {} skip_line_start_symbols = ["#", "/"] - File.foreach(file_abs_path) { |line| - next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ } - plugin = line.split(pattern=separator) - if plugin.length == 2 - podname = plugin[0].strip() - path = plugin[1].strip() - podpath = File.expand_path("#{path}", file_abs_path) - pods_ary.push({:name => podname, :path => podpath}); - else - puts "Invalid plugin specification: #{line}" - end - } - return pods_ary + File.foreach(file_abs_path) do |line| + next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ } + plugin = line.split(pattern=separator) + if plugin.length == 2 + podname = plugin[0].strip() + path = plugin[1].strip() + podpath = File.expand_path("#{path}", file_abs_path) + generated_key_values[podname] = podpath + else + puts "Invalid plugin specification: #{line}" + end + end + generated_key_values end target 'Runner' do - # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock - # referring to absolute paths on developers' machines. - system('rm -rf .symlinks') - system('mkdir -p .symlinks/plugins') + # Flutter Pod - # Flutter Pods - generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig') - if generated_xcode_build_settings.empty? - puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first." - end - generated_xcode_build_settings.map { |p| - if p[:name] == 'FLUTTER_FRAMEWORK_DIR' - symlink = File.join('.symlinks', 'flutter') - File.symlink(File.dirname(p[:path]), symlink) - pod 'Flutter', :path => File.join(symlink, File.basename(p[:path])) + copied_flutter_dir = File.join(__dir__, 'Flutter') + copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework') + copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec') + unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path) + # Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet. + # That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration. + # CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist. + + generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig') + unless File.exist?(generated_xcode_build_settings_path) + raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path) + cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR']; + + unless File.exist?(copied_framework_path) + FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir) end - } + unless File.exist?(copied_podspec_path) + FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir) + end + end + + # Keep pod path relative so it can be checked into Podfile.lock. + pod 'Flutter', :path => 'Flutter' # Plugin Pods + + # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock + # referring to absolute paths on developers' machines. + system('rm -rf .symlinks') + system('mkdir -p .symlinks/plugins') plugin_pods = parse_KV_file('../.flutter-plugins') - plugin_pods.map { |p| - symlink = File.join('.symlinks', 'plugins', p[:name]) - File.symlink(p[:path], symlink) - pod p[:name], :path => File.join(symlink, 'ios') - } + plugin_pods.each do |name, path| + symlink = File.join('.symlinks', 'plugins', name) + File.symlink(path, symlink) + pod name, :path => File.join(symlink, 'ios') + end end -# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system. -install! 'cocoapods', :disable_input_output_paths => true - post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock new file mode 100644 index 0000000..029f79b --- /dev/null +++ b/example/ios/Podfile.lock @@ -0,0 +1,22 @@ +PODS: + - Flutter (1.0.0) + - shared_preferences (0.0.1): + - Flutter + +DEPENDENCIES: + - Flutter (from `Flutter`) + - shared_preferences (from `.symlinks/plugins/shared_preferences/ios`) + +EXTERNAL SOURCES: + Flutter: + :path: Flutter + shared_preferences: + :path: ".symlinks/plugins/shared_preferences/ios" + +SPEC CHECKSUMS: + Flutter: 0e3d915762c693b495b44d77113d4970485de6ec + shared_preferences: 1feebfa37bb57264736e16865e7ffae7fc99b523 + +PODFILE CHECKSUM: f32fb4e7c14f8b3ca19a369d7be425dd9241af27 + +COCOAPODS: 1.9.1 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj old mode 100755 new mode 100644 index bdbe25e..bcc24fa --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -8,18 +8,14 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; + BEB4F40CFF3235EA6E9C9E92 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B145880AFC98DC3E202F01B /* libPods-Runner.a */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -29,8 +25,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -40,21 +34,21 @@ /* Begin PBXFileReference section */ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; - 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; + 5B145880AFC98DC3E202F01B /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; - 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + C9B76BE23F5885DC1604A7B0 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; + FC72910609FC36193C897B13 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -62,21 +56,27 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, + BEB4F40CFF3235EA6E9C9E92 /* libPods-Runner.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 5C13A7A78DEE6D28F3FE8BAA /* Pods */ = { + isa = PBXGroup; + children = ( + FC72910609FC36193C897B13 /* Pods-Runner.debug.xcconfig */, + C9B76BE23F5885DC1604A7B0 /* Pods-Runner.release.xcconfig */, + ); + name = Pods; + path = Pods; + sourceTree = ""; + }; 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */, - 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, - 9740EEBA1CF902C7004384FC /* Flutter.framework */, 9740EEB21CF90195004384FC /* Debug.xcconfig */, 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 9740EEB31CF90195004384FC /* Generated.xcconfig */, @@ -90,7 +90,8 @@ 9740EEB11CF90186004384FC /* Flutter */, 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, - CF3B75C9A7D2FA2A4C99F110 /* Frameworks */, + 5C13A7A78DEE6D28F3FE8BAA /* Pods */, + A50D666E155545C59E6F7A4C /* Frameworks */, ); sourceTree = ""; }; @@ -126,6 +127,14 @@ name = "Supporting Files"; sourceTree = ""; }; + A50D666E155545C59E6F7A4C /* Frameworks */ = { + isa = PBXGroup; + children = ( + 5B145880AFC98DC3E202F01B /* libPods-Runner.a */, + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -133,12 +142,14 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( + 45729BAC763A6E36DA4F77A9 /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + C432179A75A76D3CBBA49A33 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -190,7 +201,6 @@ 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */, 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -210,7 +220,29 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; + }; + 45729BAC763A6E36DA4F77A9 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; @@ -226,6 +258,24 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; }; + C432179A75A76D3CBBA49A33 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", + "${PODS_ROOT}/../Flutter/Flutter.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcworkspace/contents.xcworkspacedata index 1d526a1..21a3cc1 100755 --- a/example/ios/Runner.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -4,4 +4,7 @@ + + diff --git a/example/lib/util/locale/localization.dart b/example/lib/util/locale/localization.dart index 34a28b5..359424d 100644 --- a/example/lib/util/locale/localization.dart +++ b/example/lib/util/locale/localization.dart @@ -17,7 +17,7 @@ class Localization { if (showLocalizationKeys) { return localizations; } - final jsonContent = await rootBundle.loadString('assets/locale/${locale.languageCode}.json'); + final jsonContent = await rootBundle.loadString('assets/localization/${locale.languageCode}.json'); final Map values = json.decode(jsonContent); localizations._localisedValues = values; return localizations; @@ -45,6 +45,8 @@ class Localization { return value; } + String get welcomeMessage => _t(LocalizationKeys.welcomeMessage); + String getTranslation(String key, {List args}) => _t(key, args: args ?? List()); } diff --git a/example/lib/util/locale/localization_keys.dart b/example/lib/util/locale/localization_keys.dart index 719c664..89b2477 100644 --- a/example/lib/util/locale/localization_keys.dart +++ b/example/lib/util/locale/localization_keys.dart @@ -3,7 +3,6 @@ //============================================================// class LocalizationKeys { - static const appTitle = 'app_title'; - static const welcomeMessage = 'welcome_message'; + } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 6f30085..708ca4d 100755 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -29,9 +29,11 @@ dev_dependencies: flutter: assets: - - assets/locale/ + - assets/localization/ icapps_translations: api_key: 'enter-your-api-key' default_language: 'nl' - languages: ['en', 'nl'] \ No newline at end of file + languages: ['en', 'nl'] + locale_assets_path: 'assets/localization' + assets_path: 'assets/localization' \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index f01c6e2..4c70890 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,15 +1,15 @@ name: icapps_translations description: Dart tool to generate flutter translations code from the icapps translations tool -version: 2.0.0 +version: 2.1.0 homepage: https://github.com/icapps/flutter-icapps-translations environment: sdk: ">=2.0.0 <3.0.0" dependencies: - http: ^0.12.0+4 + http: ^0.12.1 path: ^1.6.4 - yaml: ^2.2.0 + yaml: ^2.2.1 dev_dependencies: - test: ^1.14.2 + test: ^1.14.7 diff --git a/test/test_format.dart b/test/format_test.dart similarity index 94% rename from test/test_format.dart rename to test/format_test.dart index dcf1628..11ea083 100644 --- a/test/test_format.dart +++ b/test/format_test.dart @@ -25,13 +25,13 @@ void main() { test('Test translations with 1 string argument', () { final sb = StringBuffer(); FileWriter.buildTranslationFunction(sb, 'app_title', 'hallo %1\$s'); - expect(sb.toString(), equals(" String appTitle(String arg1) => _t(LocalizationKeys.appTitle, args: [arg1]);\n\n")); + expect(sb.toString(), equals(' String appTitle(String arg1) => _t(LocalizationKeys.appTitle, args: [arg1]);\n\n')); }); test('Test translations with 2 string arguments', () { final sb = StringBuffer(); FileWriter.buildTranslationFunction(sb, 'app_title', 'hallo %1\$s %2\$s'); - expect(sb.toString(), equals(" String appTitle(String arg1, String arg2) => _t(LocalizationKeys.appTitle, args: [arg1, arg2]);\n\n")); + expect(sb.toString(), equals(' String appTitle(String arg1, String arg2) => _t(LocalizationKeys.appTitle, args: [arg1, arg2]);\n\n')); }); test('Test translations with 1 string argument but 2 string replacements', () { @@ -63,7 +63,7 @@ void main() { test('Test translations with 1 number argument but 2 number replacements', () { final sb = StringBuffer(); FileWriter.buildTranslationFunction(sb, 'app_title', 'hallo %1\$d %1\$d'); - expect(sb.toString(), equals(" String appTitle(num arg1) => _t(LocalizationKeys.appTitle, args: [arg1]);\n\n")); + expect(sb.toString(), equals(' String appTitle(num arg1) => _t(LocalizationKeys.appTitle, args: [arg1]);\n\n')); }); test('Test translations with 11 arguments of the same index and same type', () {