Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6: Fixed a custom asset output dir #7

Merged
merged 2 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions bin/icapps_translations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic> defaultTranslations;
Expand All @@ -26,9 +30,9 @@ Future<void> main(List<String> 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);
}
Expand Down Expand Up @@ -60,7 +64,8 @@ Future<void> _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);
Expand Down Expand Up @@ -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<String, dynamic> values = json.decode(jsonContent);')
..writeln(' localizations._localisedValues = values;')
Expand Down Expand Up @@ -220,7 +225,8 @@ void createLocalizationDelegateFile() {
..writeln(' @override')
..writeln(' Future<Localization> 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')
Expand Down
14 changes: 14 additions & 0 deletions bin/src/params.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 += '/';
}
}
}
2 changes: 2 additions & 0 deletions example/.flutter-plugins
Original file line number Diff line number Diff line change
@@ -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/
1 change: 1 addition & 0 deletions example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -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"}
4 changes: 0 additions & 4 deletions example/assets/locale/en.json

This file was deleted.

4 changes: 0 additions & 4 deletions example/assets/locale/nl.json

This file was deleted.

3 changes: 3 additions & 0 deletions example/assets/localization/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"welcome_message": "Hi There"
}
3 changes: 3 additions & 0 deletions example/assets/localization/nl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"welcome_message": "Hallo daar"
}
18 changes: 18 additions & 0 deletions example/ios/Flutter/Flutter.podspec
Original file line number Diff line number Diff line change
@@ -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' => '[email protected]' }
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
10 changes: 6 additions & 4 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -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"
86 changes: 49 additions & 37 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
22 changes: 22 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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
Loading