Skip to content

Commit

Permalink
UI: use English localization as a fallback when a string has no trans…
Browse files Browse the repository at this point in the history
…lation
  • Loading branch information
Iksas committed Dec 27, 2023
1 parent 2fec12a commit 3be6e69
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Sources/WireGuardApp/LocalizationHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@

import Foundation

/// Gets the English string from the Base.lproj bundle, which can be used as a fallback when the translation for a certain language is missing.
func tr_base(_ key: String) -> String {
let baseBundlePath: String? = Bundle.main.path(forResource: "Base", ofType: "lproj")
let baseBundle: Bundle? = Bundle(path: baseBundlePath ?? "") ?? nil
return baseBundle?.localizedString(forKey: key, value: nil, table: nil) ?? key
}

func tr(_ key: String) -> String {
return NSLocalizedString(key, comment: "")
return NSLocalizedString(key, value: tr_base(key), comment: "")
}

func tr(format: String, _ arguments: CVarArg...) -> String {
return String(format: NSLocalizedString(format, comment: ""), arguments: arguments)
return String(format: NSLocalizedString(format, value: tr_base(format), comment: ""), arguments: arguments)
}

0 comments on commit 3be6e69

Please sign in to comment.