Add a mechanism for customizing app strings
This commit is contained in:
@@ -78,6 +78,11 @@ extension {{enumName}} {
|
||||
// Use preferredLocalizations to get a language that is in the bundle and the user's preferred list of languages.
|
||||
let languages = Bundle.overrideLocalizations ?? Bundle.app.preferredLocalizations
|
||||
|
||||
// Letro: customize strings
|
||||
if let translation = trLetro(key, args, languages: languages) {
|
||||
return translation
|
||||
}
|
||||
|
||||
for language in languages {
|
||||
if let translation = trIn(language, table, key, args) {
|
||||
return translation
|
||||
@@ -86,6 +91,19 @@ extension {{enumName}} {
|
||||
return Bundle.app.developmentLocalization.flatMap { trIn($0, table, key, args) } ?? key
|
||||
}
|
||||
|
||||
private static func trLetro(_ key: String, _ args: [CVarArg], languages: [String]) -> String? {
|
||||
// Letro: customize strings
|
||||
// Fall back to English Letro overrides
|
||||
for language in languages + ["en"] {
|
||||
guard let bundle = Bundle.lprojBundle(for: language) else { continue }
|
||||
let format = NSLocalizedString(key, tableName: "Letro", bundle: bundle, comment: "")
|
||||
let translation = String(format: format, locale: Locale(identifier: language), arguments: args)
|
||||
guard translation != key else { continue }
|
||||
return translation
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
private static func trIn(_ language: String, _ table: String, _ key: String, _ args: CVarArg...) -> String? {
|
||||
guard let bundle = Bundle.lprojBundle(for: language) else { return nil }
|
||||
let format = NSLocalizedString(key, tableName: table, bundle: bundle, comment: "")
|
||||
|
||||
Reference in New Issue
Block a user