Skip to content

Commit

Permalink
♻️ (l10n) Auto detect Bundle at call site
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Jan 8, 2024
1 parent 2dc76b5 commit 6e3c7a8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Modules/LocalizationKit/Sources/LocalizationKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import Foundation

public enum l10n {
public static func LocalizedString(
_ key: StaticString, value: String.LocalizationValue, comment: StaticString
_ key: StaticString, value: String.LocalizationValue, bundle: Bundle? = nil, comment: StaticString, dsoHandle: UnsafeRawPointer = #dsohandle
)
-> AttributedString
{
let string = String(localized: key, defaultValue: value, comment: comment)
var dlInformation = dl_info()
let _ = dladdr(dsoHandle, &dlInformation)

Check warning on line 17 in Modules/LocalizationKit/Sources/LocalizationKit.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Prefer `_ = foo()` over `let _ = foo()` when discarding a result from a function (redundant_discardable_let)
let path = String(cString: dlInformation.dli_fname)
let url = URL(fileURLWithPath: path).deletingLastPathComponent()
let bundle = bundle ?? Bundle(url: url)

let string = String(localized: key, defaultValue: value, bundle: bundle, comment: comment)
let markdown =
(try? AttributedString(
markdown: string,
Expand Down

0 comments on commit 6e3c7a8

Please sign in to comment.