I need to manually change the language switch in APP
But R.string.localizable like this
/// en translation: Address copied /// /// Locales: en, es, ru static let requestAddressCopiedTitle = Rswift.StringResource(key: "request.addressCopied.title", tableName: "Localizable", bundle: R.hostingBundle, locales: ["en", "es", "ru"], comment: nil)
how to switch en er ru ?
Unfortunately, there's currently no build-in support in R.swift to manually select a language. It is a feature we'd like to add, though.
As a workaround, this is an extension I currently use in my projects:
import Foundation
import Rswift
extension StringResource {
public func localized(_ language: String) -> String {
guard
let basePath = bundle.path(forResource: "Base", ofType: "lproj"),
let baseBundle = Bundle(path: basePath)
else {
return self.key
}
let fallback = baseBundle.localizedString(forKey: key, value: key, table: tableName)
guard
let localizedPath = bundle.path(forResource: language, ofType: "lproj"),
let localizedBundle = Bundle(path: localizedPath)
else {
return fallback
}
return localizedBundle.localizedString(forKey: key, value: fallback, table: tableName)
}
}
Usage:
R.string.localizable.welcomeMessage.localized("nl")
I am looking forward to this feature in future. Because of developing a multilingual APP. Need to be matched with many languages resources. Like string file , plist file , storyboard , xib file, all this can Localization in different language version. So it should have an interface allow user to custom the Bundle.
We're tracking this feature request further in https://github.com/mac-cain13/R.swift/issues/219
Most helpful comment
Unfortunately, there's currently no build-in support in R.swift to manually select a language. It is a feature we'd like to add, though.
As a workaround, this is an extension I currently use in my projects:
Usage: