hw-1

swift Localizable strings

swift Localizable strings

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
#fastlane 
AppleLocale
FASTLANE_SNAPSHOT

#get current language code
Locale.current.languageCode

#swift
NSLocalizedString("Enter the file pssword", comment: "")
#objc
NSLocalizedString(@"Close", nil)


extension String {
var localized: String {
return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "")
}
}

tempfile=$(mktemp -t 1234)
find . \( -name "*.swift" ! -path "./Carthage/*" ! -path "./Pods/*" ! -name String+ext.swift \)| while read var
do
genstrings "$var"
[ -e Localizable.strings ] && cat Localizable.strings >> $tempfile && rm -rf Localizable.strings
done
cp $tempfile Localizable.strings


Use your XCode "Find and Replace" option based on the regular expression. As for the given example (if you have no comments) the regular expression will be:

NSLocalizedString\((.*)\, comment:\ \"(.*)\"\)
and replace it with
$1.localized