Skip to content

Commit e8666c5

Browse files
author
Gerald Collaku
committed
Add the option to get the english localized string from the extension
1 parent f0226df commit e8666c5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Sources/CoreUsefulSDK/Extensions/String+Attributed.swift

+13-5
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,22 @@ public extension String {
5959
/// Returns localized string.
6060
var localized: String {
6161
if NSLocalizedString(self, comment: self).isEmpty {
62-
 if let enPath = Bundle.main.path(forResource: "en", ofType: "lproj") {
63-
let enBundle = Bundle(path: enPath)
64-
return enBundle?.localizedString(forKey: self, value: self, table: nil) ?? ""
65-
}
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) ?? ""
6672
}
67-
return  NSLocalizedString(self, comment: self)
73+
return ""
6874
}
6975

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

0 commit comments

Comments
 (0)