Skip to content

Instantly share code, notes, and snippets.

@croccio
Created April 24, 2020 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save croccio/2c01496d054d93dc977a60de44308129 to your computer and use it in GitHub Desktop.
Save croccio/2c01496d054d93dc977a60de44308129 to your computer and use it in GitHub Desktop.
Enable multiple Localizable.strings on xCode 11.x.x with new build system
#!/bin/sh
# MergeLocalizable.sh
# EAD
#
# Created by Antonio Scardigno on 24/04/2020.
# Copyright © 2020 UPU. All rights reserved.
############################################################
##ONLY FOR TEST############################################# if u would run it from terminal uncomment these line
#SRCROOT = "put path folder that contain project file. " ## ex: /Users/username/xCodeProject/myApp
#PROJECT_NAME = "put name of project" ## ex: MyApp
############################################################
### ENVIRONMENT VARIABLE DURING BUILD
### SRCROOT root of the project
### PROJECT_NAME name of the project
### move into resources folder of the porject
cd "${SRCROOT}/${PROJECT_NAME}/Resource"
### foreach folder ending with .lproj
for file in *; do
if [[ -d "$file" ]] && [[ "$file" == *".lproj" ]]; then
### move in
cd "$file"
### clear Localizable .strings
echo "" > Localizable.strings
### for each .localizable.strings files
for file in *.localizable.strings; do
### read it
while read line; do
### and append in Localizable.strings
echo "$line" >> Localizable.strings
done < $file
done
### go to previous folder and then start it agin with next .lproj folder
cd ".."
fi
done
@croccio
Copy link
Author

croccio commented Apr 24, 2020

To use it:

  1. Import it in your project
  2. Add this script in Build Phases (click on your poject, move in Build Phases tab, click on + button, drag and drop script on new buil phases added and move it to the top of other build phases)
  3. Put you localization folder and file in PATH_TO_MY_PROJECT/MyApp/Resource
  4. Add and EMPTY localizable strings
  5. Create as many file as you want with .localizable.strings extension

So the structure should be this:

PROJECT_WORKSPACE
|-FolderOfMyProject
   |-- MyProject.xcodeProj
   |-- MyProject.xcworkspace
   |-- ProjectName
         |-- Resource
               |-- en.lproj (as many as language of your app)
                    |-- Localizable.strings //not add here your string, it is overwritten every time
                    |-- LocalizableFIle1.localizable.strings
                    |-- LocalizableFIle2.localizable.strings
                    |-- LocalizableFIle3.localizable.strings
                    |-- .....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment