-
Notifications
You must be signed in to change notification settings - Fork 329
Open
Description
Given proper setup for localizable string files and dictionaries, when it comes to applying plural localisation in Xcode 12.3 swift 5,
self.lblTopRoom.text = "rooms_unit".localizedPlural(tmp)
gives 1 rooms instead of 1 room
When I drilled into the swift file : String+LocalizedBundleTableName.swift, no values was assigned:
/// bundle & tableName friendly extension
public extension String {
/**
Swift 2 friendly localization syntax, replaces NSLocalizedString.
- parameter tableName: The receiver’s string table to search. If tableName is `nil`
or is an empty string, the method attempts to use `Localizable.strings`.
- parameter bundle: The receiver’s bundle to search. If bundle is `nil`,
the method attempts to use main bundle.
- returns: The localized string.
*/
func localized(using tableName: String?, in bundle: Bundle?) -> String {
let bundle: Bundle = bundle ?? .main
if let path = bundle.path(forResource: Localize.currentLanguage(), ofType: "lproj"),
let bundle = Bundle(path: path) {
return bundle.localizedString(forKey: self, value: nil, table: tableName)
}
else if let path = bundle.path(forResource: LCLBaseBundle, ofType: "lproj"),
let bundle = Bundle(path: path) {
return bundle.localizedString(forKey: self, value: nil, table: tableName)
}
return self
}
I resolve that using the following method instead . Remember to assign values into localizedString method
extension String {
func localizedForPlural(_ value: Int) -> String {
DLog("current language: \(Localize.currentLanguage())")
let selectedLanguage = Localize.currentLanguage()
//recover the language chosen by the user (in my case, from UserDefaults)
if let path = Bundle.main.path(forResource: selectedLanguage, ofType: "lproj") , let selectedBundle = Bundle(path: path) {
let string = NSLocalizedString(self, tableName: nil, bundle: selectedBundle, value: "", comment: "")
return String(format: string , value)
}
return localizedPlural(value)
}
}
I am looking forward to next version 3.3.0 . Thank you in advance.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels