Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak caused by NSLocalizedString #891

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix memory leak caused by NSLocalizedString
fthdgn committed Apr 2, 2024
commit b590a5c92f092dcdfc46c4c8bb51f1c74e94b508
Original file line number Diff line number Diff line change
@@ -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: