Skip to content

Commit

Permalink
Merge branch 'development' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelsetragni committed Jan 3, 2024
2 parents 28faa5b + bfc87bb commit 914690a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion IosAwnCore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'IosAwnCore'
s.version = '0.9.0'
s.version = '0.9.1'
s.summary = 'Awesome Notifications iOS Core'

s.description = <<-DESC
Expand Down
22 changes: 12 additions & 10 deletions IosAwnCore/Classes/builders/NotificationBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,22 @@ public class NotificationBuilder {
let languageCode = LocalizationManager.shared.getLocalization()

if let titleLocKey = notificationModel.content?.titleLocKey {
let format = titleLocKey.localized(forLanguageCode: languageCode)
if let args = notificationModel.content?.titleLocArgs {
notificationModel.content!.title = String(format: format, arguments: args)
} else {
notificationModel.content!.title = format
if let format = titleLocKey.localized(forLanguageCode: languageCode) {
if let args = notificationModel.content?.titleLocArgs {
notificationModel.content!.title = String(format: format, arguments: args)
} else {
notificationModel.content!.title = format
}
}
}

if let bodyLocKey = notificationModel.content?.bodyLocKey {
let format = bodyLocKey.localized(forLanguageCode: languageCode)
if let args = notificationModel.content?.bodyLocArgs {
notificationModel.content!.body = String(format: format, arguments: args)
} else {
notificationModel.content!.body = format
if let format = bodyLocKey.localized(forLanguageCode: languageCode) {
if let args = notificationModel.content?.bodyLocArgs {
notificationModel.content!.body = String(format: format, arguments: args)
} else {
notificationModel.content!.body = format
}
}
}

Expand Down
26 changes: 21 additions & 5 deletions IosAwnCore/Classes/extensions/StringExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,23 @@ extension String {
return modifiedString.components(separatedBy: stop)
}

func localized(forLanguageCode languageCode: String) -> String {
guard let path = Bundle.main.path(forResource: formatLanguageCode(languageCode), ofType: "lproj"),
let bundle = Bundle(path: path) else {
return self // Return the original string if no localization is found
func localized(forLanguageCode languageCode: String) -> String? {
let formattedLanguageCode = formatLanguageCode(languageCode)

// Try with the full language code first (e.g., "en-US")
if let path = Bundle.main.path(forResource: formattedLanguageCode, ofType: "lproj"),
let bundle = Bundle(path: path) {
return NSLocalizedString(self, bundle: bundle, comment: "")
}

// If not found, try with only the language part (e.g., "en")
let primaryLanguageCode = onlyFirstLanguageCode(formattedLanguageCode)
if let path = Bundle.main.path(forResource: primaryLanguageCode, ofType: "lproj"),
let bundle = Bundle(path: path) {
return NSLocalizedString(self, bundle: bundle, comment: "")
}
return NSLocalizedString(self, bundle: bundle, comment: "")

return nil // Return nil if no localization is found
}

private func formatLanguageCode(_ code: String) -> String {
Expand All @@ -139,6 +150,11 @@ extension String {
return formattedCode
}

private func onlyFirstLanguageCode(_ code: String) -> String {
let parts = code.split(separator: "-")
return parts[0].lowercased()
}

var md5: String {
let data = Data(self.utf8)
let hash = data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) -> [UInt8] in
Expand Down

0 comments on commit 914690a

Please sign in to comment.