It use the system-wide settings locale. In case we want to force a specific locale, we can write a custom method that find our selected language lproj bundle
When compiled, the localizable files will be under Resources folder, for example
MyApp.app/Contents/Resources/nb.lproj
extension L10n {
private class BundleToken {}
private static var bundle: Bundle {
let language = Settings.language
switch language {
case .system:
return Bundle(for: BundleToken.self)
default:
let path = Bundle.main.path(forResource: language.rawValue, ofType: "lproj")
return Bundle(path: path ?? "") ?? .main
}
}
static func tr(_ table: String, _ key: String, _ args: CVarArg..., fallback value: String) -> String {
let format = bundle.localizedString(forKey: key, value: value, table: table)
return String(format: format, locale: Locale.current, arguments: args)
}
}
The default SwiftGen generate generated strings
L10n
file like thisIt use the system-wide settings locale. In case we want to force a specific locale, we can write a custom method that find our selected language
lproj
bundleWhen compiled, the localizable files will be under
Resources
folder, for example