Skip to content

Instantly share code, notes, and snippets.

@boyvanamstel
Created May 24, 2012 15:44
Show Gist options
  • Save boyvanamstel/2782310 to your computer and use it in GitHub Desktop.
Save boyvanamstel/2782310 to your computer and use it in GitHub Desktop.
dcxibupdater - Updates all your localized Xibs in your Xcode project using Git and ibtool
#!/bin/sh
#
# dcxibupdater - Danger Cove Xib Updater
#
# Updates all your localized Xibs in your Xcode project using Git and ibtool.
#
# Prerequisites and setup:
# - Xcode project stored in Git
# - Localized .xib files
# - IMPORTANT: Add *_prev.xib to your .gitignore
#
# Usage:
# 1. Copy the script into a file called dcxibupdater.
# 2. Make it executable (chmod a+x dcxibupdater).
# 3. Add dcxibupdater to your $PATH (e.g. /usr/bin, /usr/local/bin).
# 4. Go to root of your project (where the .git folder is).
# 5. Make sure the current state of your Xib(s) is commited to Git.
# 6. Start editing the English Xibs and save your changes.
# 7. DO NOT commit to Git just yet.
# 8. Run dcxibupdater.
# 9. Check the localized Xibs to see they're updated.
# 10. Commit your changes. Repeat.
#
# Current state:
# - Tested to work in a simple project, localized to two languages.
# - NOTICE: en is the default language.
#
# Changelog:
# 20120524
# - initial release
#
# License:
# Copyright (c) 2012, Danger Cove
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
# Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
# Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Loop through xibs in default language (en)
for f in $( find . -type f -path "*/en.lproj/*" \( -iname "*.xib" ! -iname "*_prev.xib" \) )
do
bf=$(basename $f) # Get the basename for the file
ef=${bf##*.} # Get the file extension
cf=${f%.*} # Get the path without its extension
prev=${cf}_prev.${ef}
# Git checkout the file from HEAD and save it as (filename)_prev.xib
git show HEAD:$f > $prev
if [ $prev ] && [ -f $prev ];
then
# Loop through languages, skip default (en)
for l in $( find . -type d \( -iname "*.lproj" ! -iname "en.lproj" \) )
do
dl=$(basename $l) # Get basename for the lproj directory
cl=${dl%.*} # Get the language identifier
# Run ibtool and update Xibs
ibtool --previous-file $prev --incremental-file $l/$bf --localize-incremental --write $l/$bf $f
done
# Remove the _prev.xib file
rm $prev
else
echo "Previous state of $bf not found."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment