2022-11-03 19:59:58 +01:00
|
|
|
//
|
|
|
|
// MetaEntity+Accessibility.swift
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Created by Jed Fox on 2022-11-03.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Meta
|
2022-11-08 19:30:17 +01:00
|
|
|
import MastodonLocalization
|
2023-03-20 08:02:41 +01:00
|
|
|
import Foundation
|
2022-11-03 19:59:58 +01:00
|
|
|
|
2023-02-07 21:36:27 +01:00
|
|
|
extension Meta {
|
|
|
|
public var accessibilityLabel: String? {
|
|
|
|
switch self {
|
2022-11-03 19:59:58 +01:00
|
|
|
case .url(_, trimmed: _, url: let url, userInfo: _):
|
2022-11-08 19:30:17 +01:00
|
|
|
return L10n.Common.Controls.Status.MetaEntity.url(url)
|
2022-11-03 19:59:58 +01:00
|
|
|
case .hashtag(_, hashtag: let hashtag, userInfo: _):
|
2022-11-08 19:30:17 +01:00
|
|
|
return L10n.Common.Controls.Status.MetaEntity.hashtag(hashtag)
|
2022-11-03 19:59:58 +01:00
|
|
|
case .mention(_, mention: let mention, userInfo: _):
|
2022-11-08 19:30:17 +01:00
|
|
|
return L10n.Common.Controls.Status.MetaEntity.mention(mention)
|
2022-11-03 19:59:58 +01:00
|
|
|
case .email(let email, userInfo: _):
|
2022-11-08 19:30:17 +01:00
|
|
|
return L10n.Common.Controls.Status.MetaEntity.email(email)
|
2022-11-03 19:59:58 +01:00
|
|
|
// emoji are not actionable
|
|
|
|
case .emoji:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-20 08:02:41 +01:00
|
|
|
|
|
|
|
extension MetaContent {
|
|
|
|
public var accessibilityLabel: String {
|
|
|
|
return entities.reversed().reduce(string) { string, entity in
|
|
|
|
if case .emoji(_, let shortcode, _, _) = entity.meta {
|
|
|
|
return (string as NSString).replacingCharacters(in: entity.range, with: ":" + shortcode + ":")
|
|
|
|
}
|
|
|
|
return string
|
|
|
|
} as String
|
|
|
|
}
|
|
|
|
}
|