From 5b637c7b77145ea774b7d9f5e313d02d9bfef80b Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Tue, 3 Sep 2024 15:31:46 +1000 Subject: [PATCH] fix an issue where plural strings have other dynamic values --- SessionUtilitiesKit/General/Localization.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/SessionUtilitiesKit/General/Localization.swift b/SessionUtilitiesKit/General/Localization.swift index fe8a0c290..4cfa983d5 100644 --- a/SessionUtilitiesKit/General/Localization.swift +++ b/SessionUtilitiesKit/General/Localization.swift @@ -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 "
" with "\n" - localizedString = localizedString.replacingOccurrences(of: "
", 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 "
" with "\n" + localizedString = localizedString.replacingOccurrences(of: "
", with: "\n") return localizedString }