Skip to content

Commit 20ebdfe

Browse files
committed
When context is empty we set it to Localizable.strings
If string where imported using XLIFF the context will also contain path, so we strip the path and keep the file name only.
1 parent 32092f2 commit 20ebdfe

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Tool/Source/Functions.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,19 @@ func processJSON(data: Data, outputFolderURL: URL) throws
9191
for translation in translations ?? []
9292
{
9393
guard let term = translation["term"] as? String,
94-
let context = translation["context"] as? String else
94+
var context = translation["context"] as? String else
9595
{
9696
preconditionFailure()
9797
}
98+
99+
if context.isEmpty {
100+
context = "Localizable.strings"
101+
} else {
102+
let range = context.range(of: "/", options: String.CompareOptions.backwards, range: nil, locale: nil)
103+
if let range = range {
104+
context = context.substring(from: range.upperBound)
105+
}
106+
}
98107

99108
let translated: TranslatedTerm
100109

0 commit comments

Comments
 (0)