Skip to content

Commit

Permalink
Add the option to get the english localized string from the extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Collaku committed Mar 29, 2021
1 parent f0226df commit e8666c5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Sources/CoreUsefulSDK/Extensions/String+Attributed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,22 @@ public extension String {
/// Returns localized string.
var localized: String {
if NSLocalizedString(self, comment: self).isEmpty {
 if let enPath = Bundle.main.path(forResource: "en", ofType: "lproj") {
let enBundle = Bundle(path: enPath)
return enBundle?.localizedString(forKey: self, value: self, table: nil) ?? ""
}
return enLocalized
}
return NSLocalizedString(self, comment: self)
}

/// returns localized string in english or empty string
var enLocalized: String {
if let enPath = Bundle.main.path(forResource: "en", ofType: "lproj") {
let enBundle = Bundle(path: enPath)
return enBundle?.localizedString(forKey: self, value: self, table: nil) ?? ""
}
return  NSLocalizedString(self, comment: self)
return ""
}



/// Returns attributed string
func attributed(with attributes: [NSAttributedString.Key:Any]) -> NSAttributedString {
return NSMutableAttributedString(string: self, attributes: attributes)
Expand Down

0 comments on commit e8666c5

Please sign in to comment.