Skip to content

Commit bfc87bb

Browse files
Merge branch 'features/increase-loc-tolerance' into development
2 parents f4de2fd + c2499ac commit bfc87bb

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

IosAwnCore.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'IosAwnCore'
11-
s.version = '0.9.0'
11+
s.version = '0.9.1'
1212
s.summary = 'Awesome Notifications iOS Core'
1313

1414
s.description = <<-DESC

IosAwnCore/Classes/builders/NotificationBuilder.swift

+12-10
Original file line numberDiff line numberDiff line change
@@ -240,20 +240,22 @@ public class NotificationBuilder {
240240
let languageCode = LocalizationManager.shared.getLocalization()
241241

242242
if let titleLocKey = notificationModel.content?.titleLocKey {
243-
let format = titleLocKey.localized(forLanguageCode: languageCode)
244-
if let args = notificationModel.content?.titleLocArgs {
245-
notificationModel.content!.title = String(format: format, arguments: args)
246-
} else {
247-
notificationModel.content!.title = format
243+
if let format = titleLocKey.localized(forLanguageCode: languageCode) {
244+
if let args = notificationModel.content?.titleLocArgs {
245+
notificationModel.content!.title = String(format: format, arguments: args)
246+
} else {
247+
notificationModel.content!.title = format
248+
}
248249
}
249250
}
250251

251252
if let bodyLocKey = notificationModel.content?.bodyLocKey {
252-
let format = bodyLocKey.localized(forLanguageCode: languageCode)
253-
if let args = notificationModel.content?.bodyLocArgs {
254-
notificationModel.content!.body = String(format: format, arguments: args)
255-
} else {
256-
notificationModel.content!.body = format
253+
if let format = bodyLocKey.localized(forLanguageCode: languageCode) {
254+
if let args = notificationModel.content?.bodyLocArgs {
255+
notificationModel.content!.body = String(format: format, arguments: args)
256+
} else {
257+
notificationModel.content!.body = format
258+
}
257259
}
258260
}
259261

IosAwnCore/Classes/extensions/StringExtension.swift

+21-5
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,23 @@ extension String {
120120
return modifiedString.components(separatedBy: stop)
121121
}
122122

123-
func localized(forLanguageCode languageCode: String) -> String {
124-
guard let path = Bundle.main.path(forResource: formatLanguageCode(languageCode), ofType: "lproj"),
125-
let bundle = Bundle(path: path) else {
126-
return self // Return the original string if no localization is found
123+
func localized(forLanguageCode languageCode: String) -> String? {
124+
let formattedLanguageCode = formatLanguageCode(languageCode)
125+
126+
// Try with the full language code first (e.g., "en-US")
127+
if let path = Bundle.main.path(forResource: formattedLanguageCode, ofType: "lproj"),
128+
let bundle = Bundle(path: path) {
129+
return NSLocalizedString(self, bundle: bundle, comment: "")
130+
}
131+
132+
// If not found, try with only the language part (e.g., "en")
133+
let primaryLanguageCode = onlyFirstLanguageCode(formattedLanguageCode)
134+
if let path = Bundle.main.path(forResource: primaryLanguageCode, ofType: "lproj"),
135+
let bundle = Bundle(path: path) {
136+
return NSLocalizedString(self, bundle: bundle, comment: "")
127137
}
128-
return NSLocalizedString(self, bundle: bundle, comment: "")
138+
139+
return nil // Return nil if no localization is found
129140
}
130141

131142
private func formatLanguageCode(_ code: String) -> String {
@@ -139,6 +150,11 @@ extension String {
139150
return formattedCode
140151
}
141152

153+
private func onlyFirstLanguageCode(_ code: String) -> String {
154+
let parts = code.split(separator: "-")
155+
return parts[0].lowercased()
156+
}
157+
142158
var md5: String {
143159
let data = Data(self.utf8)
144160
let hash = data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) -> [UInt8] in

0 commit comments

Comments
 (0)