I need to set the default Russian language in the application to swift. I am using Xcodegen to generate .xcodeproj. There is my project.yml
options:
deploymentTarget: '13.0'
groupSortPosition: top
generateEmptyDirectories: true
minimumXcodeGenVersion: '2.32.0'
developmentLanguage: ru
After generation, Russian is displayed as default
In app delegate I call this function:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
LanguageManager.shared.firstLaunchCurrentLanguageSetup()
...
final class LanguageManager {
static let shared = LanguageManager()
var selected: String {
set {
UserDefaults.standard.set([newValue, selected], forKey: "AppleLanguages")
UserDefaults.standard.set(newValue, forKey: "language")
UserDefaults.standard.synchronize()
setLanguage()
}
get {
return UserDefaults.standard.string(forKey: "language") ?? LanguagesList.russianCode
}
}
func firstLaunchCurrentLanguageSetup() {
if UserDefaults.standard.string(forKey: "language") != nil {
return
} else {
selected = LanguagesList.russianCode
}
}
private func setLanguage() {
NotificationCenter.default.post(name: NSNotification.Name("LanguageDidChange"), object: nil)
}
}
struct LanguagesList {
static let englishCode = "en"
static let russianCode = "ru"
static let languages: [String: String] = [
englishCode: "English",
russianCode: "Русский"
]
}
After all these manipulations, when the application is first launched, it still runs in English on the device with the English language set, and when repeated, it is already in Russian. I also need to run it in Russian at the first launch
I am not able to comment so I posted an answer here.
Please Add
setLanguage()
function in your questionOr
You can check/Add below code in your
setLanguage()
function