Skip to content

Commit 3be6e69

Browse files
committed
UI: use English localization as a fallback when a string has no translation
1 parent 2fec12a commit 3be6e69

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Sources/WireGuardApp/LocalizationHelper.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33

44
import Foundation
55

6+
/// Gets the English string from the Base.lproj bundle, which can be used as a fallback when the translation for a certain language is missing.
7+
func tr_base(_ key: String) -> String {
8+
let baseBundlePath: String? = Bundle.main.path(forResource: "Base", ofType: "lproj")
9+
let baseBundle: Bundle? = Bundle(path: baseBundlePath ?? "") ?? nil
10+
return baseBundle?.localizedString(forKey: key, value: nil, table: nil) ?? key
11+
}
12+
613
func tr(_ key: String) -> String {
7-
return NSLocalizedString(key, comment: "")
14+
return NSLocalizedString(key, value: tr_base(key), comment: "")
815
}
916

1017
func tr(format: String, _ arguments: CVarArg...) -> String {
11-
return String(format: NSLocalizedString(format, comment: ""), arguments: arguments)
18+
return String(format: NSLocalizedString(format, value: tr_base(format), comment: ""), arguments: arguments)
1219
}

0 commit comments

Comments
 (0)