-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathlocaliseStrings.sh
76 lines (68 loc) · 2.31 KB
/
localiseStrings.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
#!/bin/bash
input="Classes/MobileMessaging/Resources/Localization/en.lproj/MobileMessaging.strings"
output="Classes/MobileMessaging/Core/Utils/MMLoc.swift"
generate () {
chmod 666 "${output}"
echo "//" > $output
echo "// ${output##*/}" >> $output
echo "// ConversationsMobile" >> $output
echo "//" >> $output
echo "// Created by localiseStrings.sh on $(date +%d/%m/%Y)." >> $output
echo "// Copyright © $(date +%Y) Infobip Ltd. All rights reserved." >> $output
echo "//" >> $output
echo >> $output
echo "// This file was generated automatically by localiseString.sh script. You can update the variables in MMLoc by cleaning and building the MobileMessaging SDK project." >> $output
echo >> $output
echo "// swiftlint:disable identifier_name" >> $output
echo "// swiftlint:disable line_length" >> $output
echo "// swiftlint:disable file_length" >> $output
echo "// swiftlint:disable type_body_length" >> $output
# echo "// swiftlint:disable type_name" >> $output
echo >> $output
echo "public enum MMLoc {" >> $output
while IFS= read -r line
do
#gen_const "$line"
local curKey=$(gen_const "$line")
local curValue=$(gen_value "$line")
local camelKey=$(snakeToCamel "$curKey")
if [ ! -z "$curKey" ]
then
echo " public static var \`${camelKey}\`: String { return MMLocalization.localizedString(forKey: \"mm_${curKey}\", defaultString: \"${curValue}\") }" >> $output
fi
done < "$input"
echo "}" >> $output
chmod 444 "${output}"
}
gen_const () {
local fullString="$1"
local quotedKey="${fullString%=*}"
local keyWithPrefix="${quotedKey//\"/}"
local key="${keyWithPrefix#mm_}"
echo "${key//\ /}"
}
gen_value () {
local fullString="$1"
local cutSemicolonString="${fullString%;*}"
local quotedValue="${cutSemicolonString##*=}"
local value="${quotedValue//\"/}"
echo "${value}" | xargs
}
snakeToCamel () {
local snakeKey="$1"
echo "${snakeKey}" | perl -nE 'say lcfirst join "", map {ucfirst lc} split /[^[:alnum:]]+/'
local step1= $key
}
outDate=$(stat -f "%m" "$output")
inDate=$(stat -f "%m" "$input")
if ! test -f "$output"
then
generate
fi
if [ $((inDate)) -gt $((outDate)) ]
then
echo "$output is outdated. last changes in: $inDate, out: $outDate"
generate
else
echo "$output is not outdated. last changes in: $inDate, out: $outDate"
fi