-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlocalize.sh
executable file
·83 lines (73 loc) · 1.71 KB
/
localize.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
XLIFF_PATH=./tmp/xcode-xliff-export
# Sample commands to import an XLIFF file:
#
# ./localize.sh xliff
# swift run ../MergeTranslations/MergeTranslationsCLI \
# --localization fr \
# --xliffDir "tmp/xcode-xliff-export/" \
# --extraMemoryXliffFile "/Users/daniel/Downloads/Timing-5/DateRangePickerEN.xliff/frx.xliff" \
# --projectPath "../DateRangePicker" \
# --skip "DateRangePickerDemo" \
# --out "./tmp/"
function export_xliff {
xcodebuild -exportLocalizations \
-project DateRangePicker.xcodeproj \
-localizationPath $XLIFF_PATH \
-exportLanguage en \
-exportLanguage de \
-exportLanguage zh-Hans \
-exportLanguage ru \
-exportLanguage fr
}
function find_strings {
# Exclude framework and Xliff output directories
find . \
-type d \( -path ./tmp -o -path ./Frameworks -o -path ./Pods \) -prune \
-o -name \*.strings -print
}
function import_result {
if [ $# -eq 0 ]
then
print_help
exit 1
fi
rsync -av --prune-empty-dirs --include '*/' --include '*.strings' --exclude '*' "$1/" "."
}
function print_help {
echo -e "Usage:\t$0 [command [options ...]]"
echo ""
echo "Commands:"
echo -e " strings\t\tList all .strings files in the project."
echo -e " xliff\t\t\tExport Xliff for all localizations to ${XLIFF_PATH}"
echo -e " import source_dir\tImports all .strings from source_dir, preserving directory structures"
}
# No command provided
if [ $# -eq 0 ]
then
print_help
exit 1
fi
# Execute each command
case "$1"
in
"strings")
find_strings
;;
"xliff")
export_xliff
;;
"import")
shift
import_result $@
;;
"-h")
;& # fallthrough
"--help")
;& # fallthrough
"help")
;& # fallthrough
*)
print_help
;;
esac