Created
November 3, 2016 00:25
-
-
Save Mozilla9/82387a4cd03647afa3a4684267533c7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# First param is the extension name | |
# | |
TMPDIR="${SRCROOT}/build/localizations/tmp" | |
BUNDLE_DIR="${SRCROOT}/build/localizations/localizations.bundle" | |
EXT_NAME="${1}" | |
CURRENT_DIR="$( pwd )" | |
rm -rf "${TMPDIR}" | |
( cd ${BUNDLE_DIR}; rm -rf *; cd ${CURRENT_DIR} ) | |
mkdir "${TMPDIR}" | |
# Get all languages in the extension | |
EXT_LOC_DIRS=$( cd "${SRCROOT}/${EXT_NAME}/localizations"; ls ) | |
# Process all dirs with localizations | |
for loc_dir in ${EXT_LOC_DIRS} | |
do | |
# Check that the dir is not exists | |
if [ ! -d "${SRCROOT}/app/localizations/${loc_dir}" ]; then | |
# Just copy folder to the bundle dir and process the next statement | |
cp -rf "${SRCROOT}/${EXT_NAME}/localizations/${loc_dir}" "${BUNDLE_DIR}" | |
continue | |
fi | |
# Copy lang-dir from the app | |
cp -rf "${SRCROOT}/app/localizations/${loc_dir}" "${BUNDLE_DIR}" | |
# Get list of all filenames in the current folder | |
LOC_FILES=$( cd "${SRCROOT}/${EXT_NAME}/localizations/${loc_dir}"; ls ) | |
# Process all files in directory | |
for loc_file in ${LOC_FILES} | |
do | |
# Check that the file is exists | |
if [ -f "${BUNDLE_DIR}/${loc_dir}/${loc_file}" ] && [[ ${loc_file} =~ \.strings$ ]]; then | |
cp -rf "${BUNDLE_DIR}/${loc_dir}/${loc_file}" "${TMPDIR}" | |
LC_ALL=C sort -b -i "${TMPDIR}/${loc_file}" > "${TMPDIR}/app.strings" | |
#sort -b "${TMPDIR}/${loc_file}" > "${TMPDIR}/app.strings" | |
if [ "0" != $? ]; then | |
echo "Sorting error of ${BUNDLE_DIR}/${loc_dir}/${loc_file}. Try to fix the locale or input file" | |
exit -1 | |
fi | |
cp -rf "${SRCROOT}/${EXT_NAME}/localizations/${loc_dir}/${loc_file}" "${TMPDIR}" | |
LC_ALL=C sort -b -i "${TMPDIR}/${loc_file}" > "${TMPDIR}/ext.strings" | |
#sort -b "${TMPDIR}/${loc_file}" > "${TMPDIR}/ext.strings" | |
if [ "0" != $? ]; then | |
echo "Sorting error of ${SRCROOT}/${EXT_NAME}/localizations/${loc_dir}/${loc_file}. Try to fix the locale or input file" | |
exit -1 | |
fi | |
join -t"=" -1 1 -2 1 -o "0 1.2" "${TMPDIR}/ext.strings" "${TMPDIR}/app.strings" > "${TMPDIR}/${loc_file}" | |
join -t"=" -1 1 -2 1 -v1 "${TMPDIR}/ext.strings" "${TMPDIR}/app.strings" >> "${TMPDIR}/${loc_file}" | |
join -t"=" -1 1 -2 1 -v2 "${TMPDIR}/ext.strings" "${TMPDIR}/app.strings" >> "${TMPDIR}/${loc_file}" | |
mv "${TMPDIR}/${loc_file}" "${BUNDLE_DIR}/${loc_dir}/" | |
else | |
# Just copy file to the bundle | |
cp -rf "${SRCROOT}/${EXT_NAME}/localizations/${loc_dir}/${loc_file}" "${BUNDLE_DIR}/${loc_dir}/" | |
fi | |
done | |
done | |
# Convert to binary | |
for loc_dir in ${EXT_LOC_DIRS} | |
do | |
# Get list of all filenames in the current folder | |
LOC_FILES=$( cd "${BUNDLE_DIR}/${loc_dir}"; ls ) | |
# Process all files in directory | |
for loc_file in ${LOC_FILES} | |
do | |
# check on empty file | |
if [ -s "${BUNDLE_DIR}/${loc_dir}/${loc_file}" ]; then | |
plutil -convert binary1 -- "${BUNDLE_DIR}/${loc_dir}/${loc_file}" | |
if [ "0" != $? ]; then | |
echo "Convert error of ${BUNDLE_DIR}/${loc_dir}/${loc_file}. Try to fix the input file" | |
exit -1 | |
fi | |
else | |
rm -rf "${BUNDLE_DIR}/${loc_dir}/${loc_file}" | |
fi | |
done | |
done | |
rm -rf "${TMPDIR}" | |
echo "The localization is successfully finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment