Fix translate: working default backend, settings UI, outgoing translation#203
Fix translate: working default backend, settings UI, outgoing translation#203MaikCZE wants to merge 1 commit into
Conversation
…orking default backend - FreeTranslateAPI's hosting (ftapi.pythonanywhere.com) is defunct, so the default backend never worked. Add a new "google" backend that talks directly to the free, unofficial Google Translate endpoint FTAPI itself used to wrap, and make it the default. - Add a full Translate section to the TClient settings menu (previously the feature was config-var only, with no UI at all): backend/language dropdowns, incoming auto-translate toggle, and a LibreTranslate endpoint/key section shown only when relevant. - Add outgoing translation: optionally translate your own messages into another language before sending, via a new tc_translate_outgoing / tc_translate_outgoing_target config pair and CTranslate::TranslateOutgoing(). Falls back to sending the original text if translation fails, and skips "/"-prefixed messages so it doesn't mangle commands like /w.
|
|
||
| // Translate | ||
| MACRO_CONFIG_STR(TcTranslateBackend, tc_translate_backend, 32, "ftapi", CFGFLAG_CLIENT | CFGFLAG_SAVE, "Translate backends (ftapi, libretranslate)") | ||
| MACRO_CONFIG_STR(TcTranslateBackend, tc_translate_backend, 32, "google", CFGFLAG_CLIENT | CFGFLAG_SAVE, "Translate backends (google, ftapi, libretranslate). ftapi's hosting is defunct as of 2026, kept for people running their own instance") |
There was a problem hiding this comment.
People running their own stuff will just use libretranslate. You can remove this comment and the ftapi backend
| "Finnish", "French", "German", "Greek", "Hebrew", "Hindi", "Hungarian", "Italian", | ||
| "Japanese", "Korean", "Polish", "Portuguese", "Romanian", "Russian", "Spanish", "Swedish", | ||
| "Thai", "Turkish", "Ukrainian", "Vietnamese"}; | ||
| static const char *s_apTranslateLanguageCodes[] = { |
There was a problem hiding this comment.
The backend should determine the language options. Google has many more than libretranslate
| for(int i = 0; i < NumTranslateLanguages; i++) | ||
| if(str_comp_nocase(pCode, s_apTranslateLanguageCodes[i]) == 0) | ||
| return i; | ||
| return 5; // Fall back to English if unset or a custom code we don't have a name for |
There was a problem hiding this comment.
Magic number! (don't fix by static asserting english is 5)
| }; | ||
|
|
||
| // Talks directly to Google's free, unofficial (undocumented) translate endpoint. | ||
| // This is the same endpoint FreeTranslateAPI (ftapi.pythonanywhere.com, now dead) used to wrap. |
There was a problem hiding this comment.
Link to the repository or a more alive one
| }; | ||
|
|
||
| { | ||
| static std::vector<const char *> s_TranslateBackendNames = {"Google", "FreeTranslateAPI (defunct)", "LibreTranslate"}; |
There was a problem hiding this comment.
These values are duplicated from ibackend::name
| { | ||
| if(m_vJobs.size() > 15) | ||
| { | ||
| // Too many jobs in flight, don't make the player wait: send untranslated |
There was a problem hiding this comment.
, don't make the player wait
The game is an unrelated concept from the chat
| else | ||
| SendChatQueued(m_Input.GetString()); | ||
| { | ||
| const char *pMessage = m_Input.GetString(); |
There was a problem hiding this comment.
To reduce diff, make translate outgoing swallow messages like ChatDoSpecId above it
|
Once you've fixed these please rebase onto master_new |
Summary
The translate feature (
translate.cpp) had no settings UI at all (config-var only), no way to translate your own outgoing messages, and its default backend was silently dead:ftapi.pythonanywhere.com(the defaultftapibackend's hosting) is defunct — it now 404s to a generic PythonAnywhere placeholder page. So out of the box, translation simply didn't work, with no indication why.Changes
googlebackend (CTranslateBackendGoogle) that talks directly to the free, unofficial Google Translate endpoint thatftapiitself used to wrap under the hood. No API key, no self-hosting required. Made it the new default (tc_translate_backenddefault changed fromftapitogoogle).ftapibackend, since that backend intentionally can't auto-translate (rate-limit protection, left unchanged).tc_translate_outgoing/tc_translate_outgoing_targetconfig vars andCTranslate::TranslateOutgoing(). Hooked into the chat send path inchat.cpp— translates your typed message before sending so other players see it in the target language. Skips/-prefixed messages so it doesn't mangle server commands (e.g./w name msg). Falls back to sending the original text if translation fails, so a message is never silently lost.g_Config.m_TcTranslateTarget), since incoming and outgoing now have independent target languages.Test plan
ftapias default for users who self-host a mirror🤖 Generated with Claude Code