Skip to content

Commit

Permalink
Fix memory leak caused by NSLocalizedString
Browse files Browse the repository at this point in the history
  • Loading branch information
fthdgn committed Apr 2, 2024
1 parent 8d26021 commit b590a5c
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ extension String {
switch source {
case let .hosting(bundle):
// With fallback to developmentValue
let format = NSLocalizedString(key.description, tableName: tableName, bundle: bundle, value: developmentValue ?? "", comment: "")
let format = if #available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) {
String(localized: key, defaultValue: .init(developmentValue ?? ""), table: tableName, bundle: bundle, comment: "")
} else {
NSLocalizedString(key.description, tableName: tableName, bundle: bundle, value: developmentValue ?? "", comment: "")
}
self = String(format: format, locale: overrideLocale ?? Locale.current, arguments: arguments)

case let .selected(bundle, locale):
// Don't use developmentValue with selected bundle/locale
let format = NSLocalizedString(key.description, tableName: tableName, bundle: bundle, value: "", comment: "")
let format = if #available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) {
String(localized: key, defaultValue: .init(developmentValue ?? ""), table: tableName, bundle: bundle, comment: "")
} else {
NSLocalizedString(key.description, tableName: tableName, bundle: bundle, value: developmentValue ?? "", comment: "")
}
self = String(format: format, locale: overrideLocale ?? locale, arguments: arguments)

case .none:
Expand Down

0 comments on commit b590a5c

Please sign in to comment.