Skip to content

Commit

Permalink
Merge pull request #1 from geraldcollaku/master
Browse files Browse the repository at this point in the history
Merge the localization changes to the main repository
  • Loading branch information
Philipp Homann authored Apr 16, 2021
2 parents 22ef9e5 + e8666c5 commit 31a9668
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Sources/CoreUsefulSDK/Extensions/String+Attributed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,23 @@ public extension String {

/// Returns localized string.
var localized: String {
return NSLocalizedString(self, comment: self)
if NSLocalizedString(self, comment: self).isEmpty {
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 ""
}



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

0 comments on commit 31a9668

Please sign in to comment.