Skip to content

Commit 31a9668

Browse files
author
Philipp Homann
authored
Merge pull request #1 from geraldcollaku/master
Merge the localization changes to the main repository
2 parents 22ef9e5 + e8666c5 commit 31a9668

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Sources/CoreUsefulSDK/Extensions/String+Attributed.swift

+15-1
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,23 @@ public extension String {
5858

5959
/// Returns localized string.
6060
var localized: String {
61-
return NSLocalizedString(self, comment: self)
61+
if NSLocalizedString(self, comment: self).isEmpty {
62+
return enLocalized
63+
}
64+
return NSLocalizedString(self, comment: self)
65+
}
66+
67+
/// returns localized string in english or empty string
68+
var enLocalized: String {
69+
if let enPath = Bundle.main.path(forResource: "en", ofType: "lproj") {
70+
let enBundle = Bundle(path: enPath)
71+
return enBundle?.localizedString(forKey: self, value: self, table: nil) ?? ""
72+
}
73+
return ""
6274
}
6375

76+
77+
6478
/// Returns attributed string
6579
func attributed(with attributes: [NSAttributedString.Key:Any]) -> NSAttributedString {
6680
return NSMutableAttributedString(string: self, attributes: attributes)

0 commit comments

Comments
 (0)