mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-30 23:20:28 +00:00
Merge commit '9af928467be19a06bb6aee61136fb3e541a5d6eb'
# Conflicts: # Telegram/Telegram-iOS/en.lproj/Localizable.strings
This commit is contained in:
commit
bdfcc56613
@ -14507,9 +14507,6 @@ Sorry for the inconvenience.";
|
||||
|
||||
"Attachment.DiscardTodoAlertText" = "Discard checklist items?";
|
||||
|
||||
"Auth.PremiumSignUp.ActionTitle" = "Sign up for %@";
|
||||
"Auth.PremiumSignUp.ActionSubtitle" = "Get Telegram Premium for 1 week";
|
||||
|
||||
"Chat.PostApproval.Status.AdminApproved" = "The message was approved";
|
||||
"Chat.PostApproval.Status.AdminRejected" = "The message was rejected";
|
||||
"Chat.PostApproval.Status.UserApproved" = "Your message was approved";
|
||||
|
@ -1644,8 +1644,10 @@ public struct TranslationConfiguration {
|
||||
public static func with(appConfiguration: AppConfiguration) -> TranslationConfiguration {
|
||||
if let data = appConfiguration.data {
|
||||
let manualValue = data["translations_manual_enabled"] as? String ?? "disabled"
|
||||
let autoValue = data["translations_auto_enabled"] as? String ?? "disabled"
|
||||
|
||||
var autoValue = data["translations_auto_enabled"] as? String ?? "disabled"
|
||||
if autoValue == "alternative" {
|
||||
autoValue = "disabled"
|
||||
}
|
||||
return TranslationConfiguration(manual: TranslationAvailability(string: manualValue), auto: TranslationAvailability(string: autoValue))
|
||||
} else {
|
||||
return .defaultValue
|
||||
|
@ -1126,6 +1126,7 @@ private final class DemoSheetContent: CombinedComponent {
|
||||
content: AnyComponent(PhoneDemoComponent(
|
||||
context: component.context,
|
||||
position: .top,
|
||||
model: .island,
|
||||
videoFile: configuration.videos["todo"],
|
||||
decoration: .todo
|
||||
)),
|
||||
|
@ -870,6 +870,7 @@ public class PremiumLimitsListScreen: ViewController {
|
||||
content: AnyComponent(PhoneDemoComponent(
|
||||
context: context,
|
||||
position: .top,
|
||||
model: .island,
|
||||
videoFile: videos["todo"],
|
||||
decoration: .todo
|
||||
)),
|
||||
|
@ -6616,7 +6616,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
|
||||
}
|
||||
}
|
||||
|
||||
if let cachedData = data.cachedData as? CachedUserData, cachedData.flags.contains(.translationHidden) {
|
||||
if let cachedData = data.cachedData as? CachedUserData, canTranslateChats(context: strongSelf.context), cachedData.flags.contains(.translationHidden) {
|
||||
items.append(.action(ContextMenuActionItem(text: presentationData.strings.Conversation_ContextMenuTranslate, icon: { theme in
|
||||
generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Translate"), color: theme.contextMenu.primaryColor)
|
||||
}, action: { [weak self] _, f in
|
||||
|
@ -193,6 +193,10 @@ public func chatTranslationState(context: AccountContext, peerId: EnginePeer.Id,
|
||||
return .single(nil)
|
||||
}
|
||||
|
||||
guard canTranslateChats(context: context) else {
|
||||
return .single(nil)
|
||||
}
|
||||
|
||||
let loggingEnabled = context.sharedContext.immediateExperimentalUISettings.logLanguageRecognition
|
||||
|
||||
if #available(iOS 12.0, *) {
|
||||
|
@ -171,6 +171,23 @@ public func normalizeTranslationLanguage(_ code: String) -> String {
|
||||
return code
|
||||
}
|
||||
|
||||
public func canTranslateChats(context: AccountContext) -> Bool {
|
||||
let translationConfiguration = TranslationConfiguration.with(appConfiguration: context.currentAppConfiguration.with { $0 })
|
||||
var chatTranslationAvailable = true
|
||||
switch translationConfiguration.auto {
|
||||
case .system:
|
||||
if #available(iOS 18.0, *) {
|
||||
} else {
|
||||
chatTranslationAvailable = false
|
||||
}
|
||||
case .alternative, .disabled:
|
||||
chatTranslationAvailable = false
|
||||
default:
|
||||
break
|
||||
}
|
||||
return chatTranslationAvailable
|
||||
}
|
||||
|
||||
public func canTranslateText(context: AccountContext, text: String, showTranslate: Bool, showTranslateIfTopical: Bool = false, ignoredLanguages: [String]?) -> (canTranslate: Bool, language: String?) {
|
||||
guard showTranslate || showTranslateIfTopical, text.count > 0 else {
|
||||
return (false, nil)
|
||||
@ -298,7 +315,7 @@ private struct TranslationViewImpl: View {
|
||||
var resultMap: [AnyHashable: String] = [:]
|
||||
for response in responses {
|
||||
if let clientIdentifier = response.clientIdentifier, let originalKey = clientIdentifierMap[clientIdentifier] {
|
||||
resultMap[originalKey] = "<L>\(response.targetText)"
|
||||
resultMap[originalKey] = "\(response.targetText)"
|
||||
}
|
||||
}
|
||||
|
||||
@ -494,11 +511,6 @@ func alternativeTranslateText(text: String, fromLang: String?, toLang: String) -
|
||||
return
|
||||
}
|
||||
|
||||
// var sourceLanguage: String? = nil
|
||||
// if jsonArray.count > 2, let lang = jsonArray[2] as? String {
|
||||
// sourceLanguage = lang.contains("-") ? String(lang.prefix(while: { $0 != "-" })) : lang
|
||||
// }
|
||||
|
||||
var result = ""
|
||||
for element in translationArray {
|
||||
if let translationBlock = element as? [Any],
|
||||
@ -530,8 +542,6 @@ func alternativeTranslateText(text: String, fromLang: String?, toLang: String) -
|
||||
|
||||
func getRandomUserAgent() -> String {
|
||||
let userAgents = [
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15",
|
||||
"Mozilla/5.0 (iPhone; CPU iPhone OS 18_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.4 Mobile/15E148 Safari/604.1"
|
||||
]
|
||||
return userAgents.randomElement() ?? userAgents[0]
|
||||
|
Loading…
x
Reference in New Issue
Block a user