2
2
mirror of https://github.com/mastodon/mastodon-ios synced 2025-04-11 22:58:02 +02:00
Marcus Kida 2e7054cb68
Implement "Default Post Language" and "Ask Before"-Alerts (#1240)
* Implement Settings->General->"Ask Before" and add "Ask Before Posting Without Alt Text" IOS-166

* Implement Alt Missing Alert for Status Edits (IOS-166)

* Fix status edit composes duplicate message

* Show (or don't) the "Really delete post?" Alert based on the User's preference (IOS-166)

* Implement alert for boost/unboost (IOS-166)

* Begin implementing "Default Post Language"-Setting (IOS-166)

* Show "Unfollow @user?" Alert (IOS-166)

* Merge conflict fixes for IOS-166

* Implement default post language setting (IOS-166)

* Fix follow button state not updated correctly (IOS-166)

* Add PR feedback (IOS-166)

* Improve default language cell style (IOS-166)

* Fix language filter broken (IOS-166)
2024-02-28 10:52:04 +01:00

42 lines
1.3 KiB
Swift

// Copyright © 2023 Mastodon gGmbH. All rights reserved.
import Foundation
// Consider replacing this with Locale.Language when dropping iOS 15
public struct Language: Identifiable {
public let endonym: String
public let exonym: String
public let id: String
public let localeId: String?
init(endonym: String, exonym: String, id: String, localeId: String?) {
self.endonym = endonym
self.exonym = exonym
self.id = id
self.localeId = localeId
}
init?(id: String) {
guard let endonym = Locale(identifier: id).localizedString(forLanguageCode: id),
let exonym = Locale.current.localizedString(forLanguageCode: id)
else { return nil }
self.endonym = endonym
self.exonym = exonym
self.id = id
self.localeId = nil
}
func contains(_ query: String) -> Bool {
"\(endonym) \(exonym) \(id)".localizedCaseInsensitiveContains(query)
}
var exonymIsDifferent: Bool {
endonym.caseInsensitiveCompare(exonym) != .orderedSame
}
var label: AttributedString {
AttributedString(endonym, attributes: AttributeContainer([.languageIdentifier: id]))
+ AttributedString(exonymIsDifferent ? " (\(exonym))" : "")
}
}