Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 2 additions & 87 deletions import-locales-firefox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,90 +5,5 @@ if [ ! -d Client.xcodeproj ]; then
exit 1
fi

ignore_errors=false
# Check command line parameters
while [[ $# -gt 0 ]]
do
case $1 in
--ignore-errors)
ignore_errors=true
;;
esac
shift
done

SDK_PATH=`xcrun --show-sdk-path`

# If the virtualenv with the Python modules that we need doesn't exist,
# or a clean run was requested, create the virtualenv.
if [ ! -d import-locales-env ] || [ "${clean_run}" = true ]
then
rm -rf import-locales-env || exit 1
echo "Setting up new virtualenv..."
virtualenv import-locales-env --python=python2.7 || exit 1
source import-locales-env/bin/activate || exit 1
# install libxml2
CFLAGS=-I"$SDK_PATH/usr/include/libxml2" LIBXML2_VERSION=2.9.2 pip install lxml==4.1.1 || exit 1
else
echo "Reusing existing virtualenv found in import-locales-env"
source import-locales-env/bin/activate || exit 1
fi

echo "Creating firefoxios-l10n Git repo"
rm -rf firefoxios-l10n
git clone --depth 1 https://github.com/mozilla-l10n/firefoxios-l10n firefoxios-l10n || exit 1

# Store current relative path to the script
script_path=$(dirname "$0")

# Remove the templates directory so that scripts do not have to special case it
rm -rf firefoxios-l10n/templates

if [ "$1" == "--release" ]
then
# Get the list of shipping locales. File is in the root of the main
# firefox-ios code repository
shipping_locales=$(cat shipping_locales.txt)

# Get the list of folders within the Git l10n clone and remove those
# not available in shipping locales.
for folder in firefoxios-l10n/*/
do
shipping_locale=false
for locale in ${shipping_locales}
do
if [[ "firefoxios-l10n/${locale}/" == ${folder} ]]
then
# This is a shipping locale, I can stop searching
shipping_locale=true
break
fi
done

if ! ${shipping_locale}
then
# Locale is not in shipping_locales.txt
echo "Removing non shipping locale: ${folder}"
rm -rf "${folder}"
fi
done
fi

# Clean up files (remove unwanted sections, map locale codes)
${script_path}/update-xliff.py firefoxios-l10n firefox-ios.xliff || exit 1

# Remove unwanted sections like Info.plist files and $(VARIABLES)
${script_path}/xliff-cleanup.py firefoxios-l10n/*/*.xliff || exit 1

# Export XLIFF files to individual .strings files
rm -rf localized-strings || exit 1
mkdir localized-strings || exit 1
if [ "${ignore_errors}" = true ]
then
${script_path}/xliff-to-strings.py firefoxios-l10n localized-strings --ignore-errors || exit 1
else
${script_path}/xliff-to-strings.py firefoxios-l10n localized-strings || exit 1
fi

# Modify the Xcode project to reference the strings files we just created
${script_path}/strings-import.py Client.xcodeproj localized-strings || exit 1
dir=$(dirname "$0")
${dir}/import-locales.sh Client.xcodeproj firefoxios-l10n firefox-ios.xliff
9 changes: 9 additions & 0 deletions import-locales-lockwise.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /usr/bin/env bash

if [ ! -d Lockbox.xcodeproj ]; then
echo "Please run this from the project root that contains lockbox-ios.xcodeproj"
exit 1
fi

dir=$(dirname "$0")
${dir}/import-locales.sh Lockbox.xcodeproj lockwiseios-l10n lockwise-ios.xliff
93 changes: 93 additions & 0 deletions import-locales.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#! /usr/bin/env bash

ignore_errors=false
# Check command line parameters
# while [[ $# -gt 0 ]]
# do
# case $1 in
# --ignore-errors)
# ignore_errors=true
# ;;
# esac
# shift
# done

xcodeproj="$1"
l10n_repo="$2"
l10n_file="$3"

SDK_PATH=`xcrun --show-sdk-path`

# If the virtualenv with the Python modules that we need doesn't exist,
# or a clean run was requested, create the virtualenv.
if [ ! -d import-locales-env ] || [ "${clean_run}" = true ]
then
rm -rf import-locales-env || exit 1
echo "Setting up new virtualenv..."
virtualenv import-locales-env --python=python2.7 || exit 1
source import-locales-env/bin/activate || exit 1
# install libxml2
CFLAGS=-I"$SDK_PATH/usr/include/libxml2" LIBXML2_VERSION=2.9.2 pip install lxml==4.1.1 || exit 1
else
echo "Reusing existing virtualenv found in import-locales-env"
source import-locales-env/bin/activate || exit 1
fi

echo "Creating firefoxios-l10n Git repo"
rm -rf ${l10n_repo}
git clone --depth 1 https://github.com/mozilla-l10n/${l10n_repo} ${l10n_repo} || exit 1

# Store current relative path to the script
script_path=$(dirname "$0")

# Remove the templates directory so that scripts do not have to special case it
rm -rf ${l10n_repo}/templates

if [ "$1" == "--release" ]
then
# Get the list of shipping locales. File is in the root of the main
# firefox-ios code repository
shipping_locales=$(cat shipping_locales.txt)

# Get the list of folders within the Git l10n clone and remove those
# not available in shipping locales.
for folder in ${l10n_repo}/*/
do
shipping_locale=false
for locale in ${shipping_locales}
do
if [[ "${l10n_repo}/${locale}/" == ${folder} ]]
then
# This is a shipping locale, I can stop searching
shipping_locale=true
break
fi
done

if ! ${shipping_locale}
then
# Locale is not in shipping_locales.txt
echo "Removing non shipping locale: ${folder}"
rm -rf "${folder}"
fi
done
fi

# Clean up files (remove unwanted sections, map locale codes)
${script_path}/update-xliff.py ${l10n_repo} ${l10n_file} || exit 1

# Remove unwanted sections like Info.plist files and $(VARIABLES)
${script_path}/xliff-cleanup.py ${l10n_repo}/*/*.xliff || exit 1

# Export XLIFF files to individual .strings files
rm -rf localized-strings || exit 1
mkdir localized-strings || exit 1
if [ "${ignore_errors}" = true ]
then
${script_path}/xliff-to-strings.py ${l10n_repo} localized-strings ${l10n_file} --ignore-errors || exit 1
else
${script_path}/xliff-to-strings.py ${l10n_repo} localized-strings ${l10n_file} || exit 1
fi

# Modify the Xcode project to reference the strings files we just created
${script_path}/strings-import.py ${xcodeproj} || exit 1
97 changes: 85 additions & 12 deletions strings-import.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@
# strings-import.py project.xcodeproj strings-directory
#

import argparse
import glob
import os
import sys
import fnmatch

from mod_pbxproj import XcodeProject, PBXFileReference, PBXBuildFile, PBXVariantGroup
from mod_pbxproj import XcodeProject, PBXFileReference, PBXBuildFile, PBXVariantGroup, PBXGroup

TARGETS = {
"Client": {"path": "Client"},
"NotificationService": {"path": "Extensions/NotificationService"},
"ShareTo": {"path": "Extensions/ShareTo"},
"Today": {"path": "Extensions/Today"},
"Shared": {"path": "Shared"},
"Firefox Lockbox": {"path": "lockbox-ios/**", "groupName": "lockbox-ios"},
"CredentialProvider": {"path": "CredentialProvider/**"}
}

LOCKBOX_TARGETS = [
"Firefox Lockbox",
"CredentialProvider"
]

LOCALES_TO_SKIP = []

def get_groups(project):
Expand Down Expand Up @@ -47,7 +56,20 @@ def find_resources_phase(project, target):

# TODO This should come from the transformed XLIFF files
def paths_for_localized_resources(path):
return [path for path in glob.glob(path + "/*.lproj/*.strings")]
paths = [p for p in glob.glob(path + "/*.lproj/*.strings")]

# this script is run with python 2.7 which doesn't support ** in glob searches :(
if path.endswith("/**"):
paths = []
for root, dirnames, filenames in os.walk(path[:-3]):
for filename in fnmatch.filter(filenames, '*.strings'):
paths.append(os.path.join(root, filename))

print paths
return paths
else:
return [p for p in glob.glob(path + "/*.lproj/*.strings")]


# TODO Rewrite to make more robust
def locale_name_from_path(path):
Expand All @@ -64,14 +86,48 @@ def add_file_reference(project, path, variant_group):

return file_reference

def file_reference_exists(project, path, variant_group):
for id in project.get_ids():
obj = project.objects[id]
if obj and obj.get('isa') == "PBXFileReference" and obj.get('path') == path:
print "Found file reference for " + obj.get('path')
return True

print "Could not file file reference for " + path

return False


def find_parent_group(project, group_id):
for group in get_groups(project):
if group.has_child(group_id):
return group

return None

def variant_in_group(project, variant_group_id, parent_group_id):
group = find_parent_group(project, variant_group_id)
if group:
if group.id == parent_group_id:
return True
return variant_in_group(project, group.id, parent_group_id)

return False

def get_or_add_variant_group(project, name, parent_group, phase):
print "Looking for " + name + " in parent group " + str(parent_group.id) + " | " + str(parent_group.get('name'))
for variant_group in project.objects.values():
if variant_group.get('isa') == 'PBXVariantGroup':
if variant_group.get('name') == name and parent_group.has_child(variant_group.id):
# If the variantgroup with the name exists and it is part of
# our parent group then we assume it has been setup correctly.
return variant_group

variant_group_name = variant_group.get('name')
if variant_group_name == name or variant_group_name == name.replace("strings", "storyboard", 1) or variant_group_name == name.replace("strings", "xib", 1):
# parent_group.has_child only checks one level
# but Localizable.strings is located in lockbox-ios/Common/Resources/Strings
if variant_in_group(project, variant_group.id, parent_group.id):
print "Found a variant_group for " + variant_group_name
return variant_group

print "Creating variant group " + str(name) + " under " + str(parent_group.id)
variant_group = PBXVariantGroup.Create(name)
project.objects[variant_group.id] = variant_group
parent_group.add_child(variant_group)
Expand All @@ -85,21 +141,31 @@ def get_or_add_variant_group(project, name, parent_group, phase):
return variant_group

if __name__ == "__main__":
project = XcodeProject.Load("Client.xcodeproj/project.pbxproj")
parser = argparse.ArgumentParser()
parser.add_argument("xcode_project", help="Location of XCode project")
args = parser.parse_args()

project = XcodeProject.Load(args.xcode_project + "/project.pbxproj")
if not project:
print "Can't open ", "Client.xcodeproj/project.pbxproj"
print "Can't open ", args.xcode_project + "/project.pbxproj"
sys.exit(1)

for target_name in TARGETS.keys():
target = find_target(project, target_name)
if not target:
print "Can't find target ", target_name
sys.exit(1)
continue

parent_group = find_group(project, target_name)
group_name = target_name
if "groupName" in TARGETS[target_name]:
group_name = TARGETS[target_name]["groupName"]

parent_group = find_group(project, group_name)
if not parent_group:
print "Can't find group ", target_name
sys.exit(1)
print "Can't find group ", group_name
continue

print "found ", target_name

phase = find_resources_phase(project, target)
if not phase:
Expand All @@ -122,6 +188,13 @@ def get_or_add_variant_group(project, name, parent_group, phase):
c = path.split(os.sep)
group_relative_path = c[-2] + "/" + c[-1]

if target_name in LOCKBOX_TARGETS:
# Lockbox has translations checked into the repo
# first check to see if there is already a reference to that file
print path + "|||" + group_relative_path
if file_reference_exists(project, group_relative_path, variant_group):
continue

file_reference = add_file_reference(project, group_relative_path, variant_group)

project.save()
3 changes: 3 additions & 0 deletions xliff-cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def indent(elem, level=0):
files_to_keep = [
'Client/Info.plist',
'Extensions/Today/Info.plist'
'lockbox-ios/Common/Resources/en.lproj/InfoPlist.strings',
'CredentialProvider/en.lproj/InfoPlist.strings'
]

strings_to_remove = [
Expand All @@ -60,6 +62,7 @@ def indent(elem, level=0):
'ShortcutItemTitleNewPrivateTab',
'ShortcutItemTitleNewTab',
'ShortcutItemTitleQRCode',
'NSFaceIDUsageDescription'
]

if __name__ == '__main__':
Expand Down
Loading