Merge pull request #269 from TouchInstinct/feature/localization_script_improvements
localization script refactoring
This commit is contained in:
commit
cbf10f95f9
|
|
@ -1,14 +1,13 @@
|
|||
<?php
|
||||
$PRODUCT_NAME = $argv[1];
|
||||
$LOCALIZATION_PATH = $argv[1];
|
||||
$COMMON_STRINGS_PATH = $argv[2];
|
||||
$BUNDLE = $argv[3];
|
||||
|
||||
function createFolder($path) {
|
||||
if (!file_exists($path)) {
|
||||
mkdir($path, 0777, true);
|
||||
}
|
||||
}
|
||||
|
||||
$localization = './'.$PRODUCT_NAME.'/Resources/Localization/';
|
||||
|
||||
$baseFile = file_get_contents(array_pop(glob($COMMON_STRINGS_PATH.'/default*.json')));
|
||||
$baseJson = json_decode($baseFile, true);
|
||||
|
|
@ -31,25 +30,26 @@
|
|||
}
|
||||
$ios_strings = preg_replace('/(\\\\)(u)([0-9a-fA-F]{4})/', '$1U$3', $ios_strings);
|
||||
|
||||
$lproj = $localization.$languageName.'.lproj/';
|
||||
$lproj = $LOCALIZATION_PATH.$languageName.'.lproj/';
|
||||
createFolder($lproj);
|
||||
file_put_contents($lproj.'Localizable.strings', $ios_strings);
|
||||
|
||||
if($isBase) {
|
||||
createFolder($localization.'Base.lproj/');
|
||||
file_put_contents($localization.'Base.lproj/Localizable.strings', $ios_strings);
|
||||
createFolder($LOCALIZATION_PATH.'Base.lproj/');
|
||||
file_put_contents($LOCALIZATION_PATH.'Base.lproj/Localizable.strings', $ios_strings);
|
||||
$ios_swift_strings = 'import Foundation'.PHP_EOL.PHP_EOL.
|
||||
'// swiftlint:disable superfluous_disable_command'.PHP_EOL.
|
||||
'// swiftlint:disable line_length'.PHP_EOL.
|
||||
'// swiftlint:disable file_length'.PHP_EOL.
|
||||
'// swiftlint:disable cyrillic_strings'.PHP_EOL.
|
||||
'// swiftlint:disable identifier_name'.PHP_EOL.PHP_EOL.
|
||||
'public extension String {'.PHP_EOL;
|
||||
foreach ($json as $key=>$value) {
|
||||
$value_without_linefeed = preg_replace("/\r|\n/", " ", $value);
|
||||
$ios_swift_strings .= "\t/// ".$value_without_linefeed."\n\t".'static let '.preg_replace_callback('/_(.?)/', function ($m) { return strtoupper($m[1]); }, $key).' = NSLocalizedString("'.$key.'", comment: "")'."\n".PHP_EOL;
|
||||
$ios_swift_strings .= "\t/// ".$value_without_linefeed."\n\t".'static let '.preg_replace_callback('/_(.?)/', function ($m) { return strtoupper($m[1]); }, $key).' = NSLocalizedString("'.$key.'", bundle: '.$BUNDLE.', comment: "'.addslashes($value_without_linefeed).'")'."\n".PHP_EOL;
|
||||
}
|
||||
$ios_swift_strings .= '}'.PHP_EOL;
|
||||
file_put_contents($localization.'String+Localization.swift', $ios_swift_strings);
|
||||
file_put_contents($LOCALIZATION_PATH.'String+Localization.swift', $ios_swift_strings);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,16 +1,36 @@
|
|||
LOCALIZATION_PATH="${PRODUCT_NAME}/Resources/Localization"
|
||||
#first argument set strings folder path
|
||||
#!/bin/sh
|
||||
|
||||
# Description:
|
||||
# Generates Localizeable.strings and String+Localization.swift files.
|
||||
#
|
||||
# Parameters:
|
||||
# $1 - path to strings folder containing json files.
|
||||
# $2 - path to Localization folder (output).
|
||||
# $3 - Bundle for localization. Default is `.main`.
|
||||
#
|
||||
# Required environment variables:
|
||||
# SCRIPT_DIR - directory of current script.
|
||||
#
|
||||
# Optional environment variables:
|
||||
# PRODUCT_NAME - product name to produce path to localization folder (output).
|
||||
#
|
||||
# Examples of usage:
|
||||
# . localization.sh
|
||||
# . localization.sh common/strings Resources/Localization/ .main
|
||||
#
|
||||
|
||||
STRINGS_FOLDER=${1:-"common/strings"}
|
||||
LOCALIZATION_PATH=${2:-"${PRODUCT_NAME}/Resources/Localization/"}
|
||||
BUNDLE=${3:-".main"}
|
||||
|
||||
if ! [ -e ${LOCALIZATION_PATH} ]; then
|
||||
echo "${PROJECT_DIR}/${LOCALIZATION_PATH} path does not exist. Add these folders and try again."
|
||||
echo "${LOCALIZATION_PATH} path does not exist. Add these folders and try again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [ -e "${PROJECT_DIR}/${STRINGS_FOLDER}" ]; then
|
||||
echo "${PROJECT_DIR}/${STRINGS_FOLDER} path does not exist. Submodule with strings should be named common and contain strings folder."
|
||||
if ! [ -e "${STRINGS_FOLDER}" ]; then
|
||||
echo "${STRINGS_FOLDER} path does not exist. Submodule with strings should be named common and contain strings folder."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#second argument set strings script path
|
||||
php ${2:-build-scripts/xcode/aux_scripts/import_strings.php} ${PRODUCT_NAME} ${STRINGS_FOLDER}
|
||||
php ${SCRIPT_DIR}/../aux_scripts/import_strings.php ${LOCALIZATION_PATH} ${STRINGS_FOLDER} ${BUNDLE}
|
||||
|
|
|
|||
|
|
@ -86,9 +86,20 @@ private_lane :buildConfiguration do |options|
|
|||
options[:scheme] = options[:scheme] || options[:appName]
|
||||
options[:lane_name] = lane_name
|
||||
|
||||
ipa_name = "#{options[:appName]}.ipa"
|
||||
options[:output_name] = ipa_name
|
||||
|
||||
options[:ipa_path] = "./#{ipa_name}"
|
||||
options[:dsym_path] = "./#{options[:appName]}.app.dSYM.zip"
|
||||
|
||||
options[:xcodeproj_path] = options[:xcodeproj_path] || "../#{options[:appName]}.xcodeproj"
|
||||
options[:workspace] = options[:workspace] || File.expand_path("../#{options[:appName]}.xcworkspace")
|
||||
|
||||
configuration_type = Touchlane::ConfigurationType.from_lane_name(lane_name)
|
||||
options = fill_up_options_using_configuration_type(options, configuration_type)
|
||||
|
||||
generate_xcodeproj_if_needed(options)
|
||||
|
||||
openKeychain(options)
|
||||
|
||||
if !options[:buildNumber].nil?
|
||||
|
|
@ -97,17 +108,6 @@ private_lane :buildConfiguration do |options|
|
|||
)
|
||||
end
|
||||
|
||||
ipa_name = "#{options[:appName]}.ipa"
|
||||
options[:output_name] = ipa_name
|
||||
|
||||
options[:ipa_path] = "./#{ipa_name}"
|
||||
options[:dsym_path] = "./#{options[:appName]}.app.dSYM.zip"
|
||||
|
||||
options[:xcodeproj_path] = options[:xcodeproj_path] || "../#{options[:appName]}.xcodeproj"
|
||||
options[:workspace] = options[:workspace] || "./#{options[:appName]}.xcworkspace"
|
||||
|
||||
generate_xcodeproj_if_needed(options)
|
||||
|
||||
installDependencies(options)
|
||||
|
||||
run_code_generation_phase_if_needed(options)
|
||||
|
|
@ -420,7 +420,8 @@ def set_xcconfig_for_configuration_of_project(lane_name, configuration, xcodepro
|
|||
target_to_modify_selector = lambda do |t|
|
||||
supported_product_types = [
|
||||
Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application],
|
||||
Xcodeproj::Constants::PRODUCT_TYPE_UTI[:app_extension]
|
||||
Xcodeproj::Constants::PRODUCT_TYPE_UTI[:app_extension],
|
||||
Xcodeproj::Constants::PRODUCT_TYPE_UTI[:framework]
|
||||
]
|
||||
return !t.test_target_type? && supported_product_types.include?(t.product_type)
|
||||
end
|
||||
|
|
@ -428,10 +429,13 @@ def set_xcconfig_for_configuration_of_project(lane_name, configuration, xcodepro
|
|||
application_targets = project.native_targets.select(&target_to_modify_selector)
|
||||
|
||||
application_targets.each do |target|
|
||||
build_configuration = target.build_configuration_list[configuration]
|
||||
config_name = target.name + lane_name
|
||||
build_configuration_reference = project.files.select { |f| f.path.start_with?(config_name) }.first
|
||||
build_configuration.base_configuration_reference = build_configuration_reference
|
||||
|
||||
if !build_configuration_reference.nil? # target has custom xcconfig
|
||||
build_configuration = target.build_configuration_list[configuration]
|
||||
build_configuration.base_configuration_reference = build_configuration_reference
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
@ -454,6 +458,6 @@ def run_code_generation_phase_if_needed(options)
|
|||
code_generation_script_path = File.expand_path "../.githooks/scripts/CodeGen.sh"
|
||||
|
||||
if File.exists? code_generation_script_path
|
||||
sh(code_generation_script_path, options[:workspace_path])
|
||||
sh(code_generation_script_path, options[:workspace])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -64,23 +64,12 @@ def fetch_development_team(development_team_key, distribution_type)
|
|||
return config_option(development_team_key, team_value)
|
||||
end
|
||||
|
||||
# Return empty array or generated provisioning profile hash
|
||||
def generate_provisioning_profile(provisioning_key, bundle_id, distribution_type)
|
||||
case distribution_type
|
||||
when "appstore"
|
||||
app_store_profile = "match AppStore " + bundle_id
|
||||
config_option(provisioning_key, app_store_profile)
|
||||
else
|
||||
config_option(provisioning_key, bundle_id)
|
||||
end
|
||||
end
|
||||
|
||||
# Generate missing properties if needed
|
||||
def generate_missing_properties(target_name, properties, distribution_type)
|
||||
result = []
|
||||
development_team_key = "DEVELOPMENT_TEAM"
|
||||
provisioning_key = "PROVISIONING_PROFILE_SPECIFIER"
|
||||
bundle_id_key = "PRODUCT_BUNDLE_IDENTIFIER"
|
||||
code_sign_style_key = "CODE_SIGN_STYLE"
|
||||
|
||||
# Bundle_id_key should be among the properties (required by fastlane)
|
||||
unless properties.key?(bundle_id_key)
|
||||
|
|
@ -91,8 +80,8 @@ def generate_missing_properties(target_name, properties, distribution_type)
|
|||
result.append(fetch_development_team(development_team_key, distribution_type))
|
||||
end
|
||||
|
||||
unless properties.key?(provisioning_key)
|
||||
result.append(generate_provisioning_profile(provisioning_key, properties[bundle_id_key], distribution_type))
|
||||
unless properties.key?(code_sign_style_key)
|
||||
result.append(config_option(code_sign_style_key, "Manual"))
|
||||
end
|
||||
|
||||
return result
|
||||
|
|
@ -113,7 +102,11 @@ targets.each do |target_name, target|
|
|||
|
||||
# Add properties from settings file
|
||||
properties.each do |key, value|
|
||||
config["xcconfig_options"].append(config_option(key, value))
|
||||
if config["xcconfig_options"].any? { |option| key == option["key"] }
|
||||
config["xcconfig_options"].map! { |option| key == option["key"] ? config_option(key, value) : option }
|
||||
else
|
||||
config["xcconfig_options"].append(config_option(key, value))
|
||||
end
|
||||
end
|
||||
|
||||
# Add missing properties if needed
|
||||
|
|
|
|||
|
|
@ -2,6 +2,4 @@
|
|||
|
||||
{{#configuration.xcconfig_options}}
|
||||
{{key}} = {{value}}
|
||||
{{/configuration.xcconfig_options}}
|
||||
|
||||
CODE_SIGN_STYLE = Manual
|
||||
{{/configuration.xcconfig_options}}
|
||||
Loading…
Reference in New Issue