overtake / TelegramSwift

Source code of Telegram for macos on Swift 5.0
https://macos.telegram.org
GNU General Public License v2.0
4.9k stars 815 forks source link

Persistent Access to Live Translation Button for Premium Users #1093

Open kithawk opened 3 months ago

kithawk commented 3 months ago

Description

Telegram Premium's live translate feature is a key benefit for users who frequently engage in multilingual communication. However, the current implementation's inconsistency in displaying the 'Translate' button significantly hampers the user experience. The button to translate entire chats is not consistently visible, appearing in only a fraction of chats despite the presence of languages different from the user's 'Do Not Translate' setting. This issue has been observed across various languages, with English provided as an example. To enhance usability and ensure Premium users can fully leverage this feature, I propose a modification to make the translation option persistently accessible.

Expected Behavior

The 'Translate' button should be persistently accessible, regardless of the detected language in a chat. Ideally, this could be implemented via a permanent placement in the chat's three-dot menu. Such a change would ensure that users can always initiate a translation when needed, without relying on the automatic detection system's accuracy.

Actual Behavior

Currently, the 'Translate' button appears sporadically in chats, visible in only about 5 to 20% of them. This inconsistency occurs across both private and group chats and does not reliably correspond with the presence of a language different from the 'Do Not Translate' setting. The issue persists despite troubleshooting efforts, including clean reinstalls and configuration file deletions (e.g., 6N38VWS5BX.ru.keepcoder.Telegram).

Steps to Reproduce

  1. Upgrade to Telegram Premium.
  2. In Settings, set 'Do Not Translate' to a rarely used language (for testing purposes) and set 'Translate to' to a commonly used language (e.g., English).
  3. Navigate to a chat in a language different from the 'Do Not Translate' setting.
  4. Note the intermittent appearance of the 'Translate' button, despite differing chat language.

Proposed Enhancement

To address this inconsistency and improve the feature's reliability, I suggest making the 'Translate' button permanently accessible within the chat's three-dot menu. This adjustment would guarantee that users have the option to translate messages at any time, enhancing the value of the Telegram Premium subscription.

kithawk commented 1 month ago

I have discovered some related insights that might shed light on the inconsistent behavior of the 'Translate' button. It appears that the issue may stem from specific parts of the code in the ChatLiveTranslateContext.swift file:

  1. https://github.com/overtake/TelegramSwift/blob/master/Telegram-Mac/ChatLiveTranslateContext.swift#L250

            if !isHidden && translationState?.fromLang != translationState?.toLang  {
                return (translationState, appearance, peer?.isPremium == true)
            } else {
                return (nil, appearance, peer?.isPremium == true)
            }
  2. https://github.com/overtake/TelegramSwift/blob/master/Telegram-Mac/ChatLiveTranslateContext.swift#L263

                if let state = state, state.fromLang != to, state.fromLang != "" {
                    current.from = state.fromLang
                    current.to = to
                    current.canTranslate = true
                } else {
                    current.canTranslate = false
                }

Based on these code snippets, it seems that if the fromLang is the same as the toLang, the translate bar disappears. This behavior could explain the inconsistency in the appearance of the 'Translate' button.

Consider the following scenario:

In this scenario, the translation will only work for the person writing in Polish (and translating to Polish) because the language detected in the chat will be English for both users. For the person trying to translate to English, it won't work because the source and destination languages will be detected as the same, causing the translate bar to be disabled.

This behavior aligns with the steps to reproduce the issue, where setting the interface language to one of the languages used in the chat causes the translation bar to disappear.

In addition to the proposed enhancement of making the 'Translate' button permanently accessible within the chat's three-dot menu, it may be worth considering modifications to the code to handle cases where the source and destination languages are the same, but the user still desires to have the translation feature available. One possible approach could be to allow the user to manually select the source language if the automatic detection fails to distinguish between the languages used in the chat.

I hope this information helps in identifying the root cause of the issue and finding a suitable solution to improve the user experience of the live translate feature for Telegram Premium users.