From 3be6e697dda387153ee7e1cd5b5a3cad6e27220c Mon Sep 17 00:00:00 2001 From: Iksas Date: Wed, 27 Dec 2023 11:49:05 +0100 Subject: [PATCH] UI: use English localization as a fallback when a string has no translation --- Sources/WireGuardApp/LocalizationHelper.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/WireGuardApp/LocalizationHelper.swift b/Sources/WireGuardApp/LocalizationHelper.swift index fcf13a9a2..9e628a9ad 100644 --- a/Sources/WireGuardApp/LocalizationHelper.swift +++ b/Sources/WireGuardApp/LocalizationHelper.swift @@ -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) }