From cf2aa3f7ee10030f140f8aa5b3743b66e0bf5799 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 21 Jul 2021 17:17:22 +0300 Subject: [PATCH] localization script refactoring --- xcode/aux_scripts/import_strings.php | 16 ++++++------- xcode/build_phases/localization.sh | 34 ++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/xcode/aux_scripts/import_strings.php b/xcode/aux_scripts/import_strings.php index 7cfdc7d..84b076c 100644 --- a/xcode/aux_scripts/import_strings.php +++ b/xcode/aux_scripts/import_strings.php @@ -1,14 +1,13 @@ $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: "'.$value_without_linefeed.'")'."\n".PHP_EOL; } $ios_swift_strings .= '}'.PHP_EOL; - file_put_contents($localization.'String+Localization.swift', $ios_swift_strings); + echo $ios_swift_strings; + file_put_contents($LOCALIZATION_PATH.'String+Localization.swift', $ios_swift_strings); } } ?> diff --git a/xcode/build_phases/localization.sh b/xcode/build_phases/localization.sh index 8c8bf61..dea12e3 100644 --- a/xcode/build_phases/localization.sh +++ b/xcode/build_phases/localization.sh @@ -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}