mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Fixed translation bug when the locale contained the region (#765)
* Fixed the issue, added tests and italian translation * changelog * improved translation handling code and added more tests * Update UnitTests/Sources/LocalizationTests.swift Co-authored-by: Stefan Ceriu <stefanc@matrix.org> --------- Co-authored-by: Stefan Ceriu <stefanc@matrix.org>
This commit is contained in:
@@ -78,18 +78,22 @@ extension {{enumName}} {
|
||||
let languages = Bundle.preferredLanguages
|
||||
|
||||
for language in languages {
|
||||
let translation = trIn(language, table, key, args)
|
||||
if translation != key {
|
||||
if let translation = trIn(language, table, key, args) {
|
||||
return translation
|
||||
// If we can't find a translation for this language
|
||||
// we check if we can find one by stripping the region
|
||||
} else if let langCode = Locale(identifier: language).language.languageCode?.identifier,
|
||||
let translation = trIn(langCode, table, key, args) {
|
||||
return translation
|
||||
}
|
||||
}
|
||||
}
|
||||
return key
|
||||
}
|
||||
}
|
||||
|
||||
private static func trIn(_ language: String, _ table: String, _ key: String, _ args: CVarArg...) -> String {
|
||||
private static func trIn(_ language: String, _ table: String, _ key: String, _ args: CVarArg...) -> String? {
|
||||
guard let bundle = Bundle(for: BundleToken.self).lprojBundle(for: language) else {
|
||||
// no translations for the desired language
|
||||
return key
|
||||
return nil
|
||||
}
|
||||
let format = NSLocalizedString(key, tableName: table, bundle: bundle, comment: "")
|
||||
return String(format: format, locale: Locale(identifier: language), arguments: args)
|
||||
|
||||
Reference in New Issue
Block a user