Эх сурвалжийг харах

hack plurals form that is not supported by the core anymore

B. Petersen 5 жил өмнө
parent
commit
926d0a91eb

+ 1 - 0
deltachat-ios/DC/events.swift

@@ -183,6 +183,7 @@ public func callbackSwift(event: CInt, data1: CUnsignedLong, data2: CUnsignedLon
         case DC_STR_NOMESSAGES: string = String.localized("chat_no_messages")
         case DC_STR_SELF: string = String.localized("self")
         case DC_STR_DRAFT: string = String.localized("draft")
+        case DC_STR_MEMBER: return nil // we create this string in hackPluralsString()
         case DC_STR_VOICEMESSAGE: string = String.localized("voice_message")
         case DC_STR_DEADDROP: string = String.localized("chat_contact_request")
         case DC_STR_IMAGE: string = String.localized("image")

+ 12 - 1
deltachat-ios/View/ChatTitleView.swift

@@ -47,6 +47,17 @@ class ChatTitleView: UIView {
         subtitleLabel.textColor = baseColor.withAlphaComponent(0.95)
         titleLabel.textColor = baseColor
         titleLabel.text = title
-        subtitleLabel.text = subtitle
+        subtitleLabel.text = hackPluralsString(string: subtitle)
     }
 }
+
+func hackPluralsString(string: String?) -> String? {
+    // the rust-core does not care about plural forms (there is just once case that was not worth the effort up to now)
+    // therefore, we check if the returned string has the form "N member(s)" and localized the corrently to one/few/many/other
+    guard var string = string else { return nil }
+    if string.hasSuffix(" member(s)") {
+        guard let value = Int(string.components(separatedBy: " ")[0]) else { return string }
+        string = String.localizedStringWithFormat(NSLocalizedString("n_members", comment: ""), value)
+    }
+    return string
+}