fix an issue where plural strings have other dynamic values

pull/1023/head
Ryan ZHAO 7 months ago
parent 02a4dc9e8c
commit 5b637c7b77

@ -33,14 +33,8 @@ final public class LocalizationHelper: CustomStringConvertible {
// If the localized string matches the key provided then the localisation failed
var localizedString: String = NSLocalizedString(template, comment: "")
for (key, value) in replacements {
localizedString = localizedString.replacingOccurrences(of: tokenize(key), with: value)
}
// Replace html tag "<br/>" with "\n"
localizedString = localizedString.replacingOccurrences(of: "<br/>", with: "\n")
// Deal with plurals
// Note: We have to deal with plurals first, so we can get the correct string
if !self.numbers.isEmpty {
localizedString = String(
format: localizedString,
@ -48,6 +42,13 @@ final public class LocalizationHelper: CustomStringConvertible {
arguments: self.numbers
)
}
for (key, value) in replacements {
localizedString = localizedString.replacingOccurrences(of: tokenize(key), with: value)
}
// Replace html tag "<br/>" with "\n"
localizedString = localizedString.replacingOccurrences(of: "<br/>", with: "\n")
return localizedString
}

Loading…
Cancel
Save