Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/engine/shared/config_variables_tclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,13 @@ MACRO_CONFIG_COL(TcBgDrawColor, tc_bg_draw_color, 14024576, CFGFLAG_CLIENT | CFG
MACRO_CONFIG_INT(TcBgDrawAutoSaveLoad, tc_bg_draw_auto_save_load, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Automatically save and load background drawings")

// 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 backend to use (google, libretranslate)")
MACRO_CONFIG_STR(TcTranslateTarget, tc_translate_target, 16, "en", CFGFLAG_CLIENT | CFGFLAG_SAVE, "Translate target language (must be 2 character ISO 639 code)")
MACRO_CONFIG_STR(TcTranslateEndpoint, tc_translate_endpoint, 256, "", CFGFLAG_CLIENT | CFGFLAG_SAVE, "For backends which need it, endpoint to use (must be https)")
MACRO_CONFIG_STR(TcTranslateKey, tc_translate_key, 256, "", CFGFLAG_CLIENT | CFGFLAG_SAVE, "For backends which need it, api key to use")
MACRO_CONFIG_INT(TcTranslateAuto, tc_translate_auto, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Automatically translate messages, only some backends support this (FTApi does not)")
MACRO_CONFIG_INT(TcTranslateAuto, tc_translate_auto, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Automatically translate incoming messages")
MACRO_CONFIG_INT(TcTranslateOutgoing, tc_translate_outgoing, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Translate your own outgoing chat messages into another language before sending them")
MACRO_CONFIG_STR(TcTranslateOutgoingTarget, tc_translate_outgoing_target, 16, "en", CFGFLAG_CLIENT | CFGFLAG_SAVE, "Language to translate your outgoing messages into (must be 2 character ISO 639 code)")

// Animations
MACRO_CONFIG_INT(TcAnimateWheelTime, tc_animate_wheel_time, 80, 0, 1000, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Duration of emote and bind wheel animations, in milliseconds (0 == no animation, 1000 = 1 second)")
Expand Down
21 changes: 12 additions & 9 deletions src/game/client/components/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ bool CChat::OnInput(const IInput::CEvent &Event)
; // Do nothing as bindchat was executed
else if(GameClient()->m_TClient.ChatDoSpecId(m_Input.GetString()))
; // Do nothing as specid was executed
else if(GameClient()->m_Translate.ChatDoTranslateOutgoing(m_Mode == MODE_TEAM ? 1 : 0, m_Input.GetString()))
; // Do nothing as outgoing translate was queued
else
SendChatQueued(m_Input.GetString());
m_pHistoryEntry = nullptr;
Expand Down Expand Up @@ -680,15 +682,16 @@ void CChat::AddLine(int ClientId, int Team, const char *pLine)
return;

// TClient
if (([&]() {
if(ClientId == CLIENT_MSG || ClientId == SERVER_MSG)
return false;
for(const auto LocalClientId : GameClient()->m_aLocalIds)
if(LocalClientId == ClientId)
return false;
auto &Re = GameClient()->m_TClient.m_RegexChatIgnore;
return Re.error().empty() && Re.test(pLine);
})()) return;
if(([&]() {
if(ClientId == CLIENT_MSG || ClientId == SERVER_MSG)
return false;
for(const auto LocalClientId : GameClient()->m_aLocalIds)
if(LocalClientId == ClientId)
return false;
auto &Re = GameClient()->m_TClient.m_RegexChatIgnore;
return Re.error().empty() && Re.test(pLine);
})())
return;

// trim right and set maximum length to 256 utf8-characters
int Length = 0;
Expand Down
104 changes: 104 additions & 0 deletions src/game/client/components/tclient/menus_tclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,110 @@ void CMenus::RenderSettingsTClientSettings(CUIRect MainView)
Ui()->DoEditBox(&s_FinishName, &Button, EditBoxFontSize);
s_SectionBoxes.back().h = Column.y - s_SectionBoxes.back().y;

// ***** Translate ***** //
Column.HSplitTop(MarginBetweenSections, nullptr, &Column);
s_SectionBoxes.push_back(Column);
Column.HSplitTop(HeadlineHeight, &Label, &Column);
Ui()->DoLabel(&Label, TCLocalize("Translate"), HeadlineFontSize, TEXTALIGN_ML);
Column.HSplitTop(MarginSmall, nullptr, &Column);

// Current backend's language table -- Google and LibreTranslate genuinely
// support different language sets (see translate.h/.cpp's
// g_aTranslateBackends), so the dropdowns below are backend-scoped
// rather than one shared list.
int CurrentBackendIndex = 0;
for(size_t i = 0; i < g_aTranslateBackends.size(); i++)
{
if(str_comp_nocase(g_Config.m_TcTranslateBackend, g_aTranslateBackends[i].m_pValue) == 0)
CurrentBackendIndex = (int)i;
}
const STranslateBackendInfo &CurrentBackend = g_aTranslateBackends[CurrentBackendIndex];

{
static std::vector<const char *> s_TranslateBackendNames;
s_TranslateBackendNames.clear();
for(const STranslateBackendInfo &Backend : g_aTranslateBackends)
s_TranslateBackendNames.push_back(Backend.m_pName);

static CUi::SDropDownState s_TranslateBackendDropDownState;
static CScrollRegion s_TranslateBackendDropDownScrollRegion;
s_TranslateBackendDropDownState.m_SelectionPopupContext.m_pScrollRegion = &s_TranslateBackendDropDownScrollRegion;
CUIRect BackendDropDownRect;
Column.HSplitTop(LineSize, &BackendDropDownRect, &Column);
BackendDropDownRect.VSplitLeft(120.0f, &Label, &BackendDropDownRect);
Ui()->DoLabel(&Label, TCLocalize("Backend: "), FontSize, TEXTALIGN_ML);
const int BackendSelectedNew = Ui()->DoDropDown(&BackendDropDownRect, CurrentBackendIndex, s_TranslateBackendNames.data(), s_TranslateBackendNames.size(), s_TranslateBackendDropDownState);
if(BackendSelectedNew != CurrentBackendIndex)
str_copy(g_Config.m_TcTranslateBackend, g_aTranslateBackends[BackendSelectedNew].m_pValue);
}
Column.HSplitTop(MarginSmall, nullptr, &Column);

DoButton_CheckBoxAutoVMarginAndSet(&g_Config.m_TcTranslateAuto, TCLocalize("Automatically translate incoming messages"), &g_Config.m_TcTranslateAuto, &Column, LineSize);
CUIRect IncomingTargetBox;
Column.HSplitTop(LineSize + MarginExtraSmall, &IncomingTargetBox, &Column);
if(g_Config.m_TcTranslateAuto)
{
IncomingTargetBox.HSplitTop(MarginExtraSmall, nullptr, &IncomingTargetBox);
IncomingTargetBox.VSplitMid(&Label, &IncomingTargetBox);
Ui()->DoLabel(&Label, TCLocalize("Translate incoming to:"), FontSize, TEXTALIGN_ML);
static CUi::SDropDownState s_IncomingLangDropDownState;
static CScrollRegion s_IncomingLangDropDownScrollRegion;
s_IncomingLangDropDownState.m_SelectionPopupContext.m_pScrollRegion = &s_IncomingLangDropDownScrollRegion;
static std::vector<const char *> s_IncomingLangNames;
s_IncomingLangNames.clear();
for(const STranslateLanguage &Language : CurrentBackend.m_vLanguages)
s_IncomingLangNames.push_back(Language.m_pName);
const int IncomingLangOld = TranslateLanguageIndex(CurrentBackend.m_vLanguages, g_Config.m_TcTranslateTarget);
const int IncomingLangNew = Ui()->DoDropDown(&IncomingTargetBox, IncomingLangOld, s_IncomingLangNames.data(), s_IncomingLangNames.size(), s_IncomingLangDropDownState);
if(IncomingLangOld != IncomingLangNew)
str_copy(g_Config.m_TcTranslateTarget, CurrentBackend.m_vLanguages[IncomingLangNew].m_pCode);
}
Column.HSplitTop(MarginSmall, nullptr, &Column);

DoButton_CheckBoxAutoVMarginAndSet(&g_Config.m_TcTranslateOutgoing, TCLocalize("Translate your outgoing messages"), &g_Config.m_TcTranslateOutgoing, &Column, LineSize);
CUIRect OutgoingTargetBox;
Column.HSplitTop(LineSize + MarginExtraSmall, &OutgoingTargetBox, &Column);
if(g_Config.m_TcTranslateOutgoing)
{
OutgoingTargetBox.HSplitTop(MarginExtraSmall, nullptr, &OutgoingTargetBox);
OutgoingTargetBox.VSplitMid(&Label, &OutgoingTargetBox);
Ui()->DoLabel(&Label, TCLocalize("Translate outgoing to:"), FontSize, TEXTALIGN_ML);
static CUi::SDropDownState s_OutgoingLangDropDownState;
static CScrollRegion s_OutgoingLangDropDownScrollRegion;
s_OutgoingLangDropDownState.m_SelectionPopupContext.m_pScrollRegion = &s_OutgoingLangDropDownScrollRegion;
static std::vector<const char *> s_OutgoingLangNames;
s_OutgoingLangNames.clear();
for(const STranslateLanguage &Language : CurrentBackend.m_vLanguages)
s_OutgoingLangNames.push_back(Language.m_pName);
const int OutgoingLangOld = TranslateLanguageIndex(CurrentBackend.m_vLanguages, g_Config.m_TcTranslateOutgoingTarget);
const int OutgoingLangNew = Ui()->DoDropDown(&OutgoingTargetBox, OutgoingLangOld, s_OutgoingLangNames.data(), s_OutgoingLangNames.size(), s_OutgoingLangDropDownState);
if(OutgoingLangOld != OutgoingLangNew)
str_copy(g_Config.m_TcTranslateOutgoingTarget, CurrentBackend.m_vLanguages[OutgoingLangNew].m_pCode);
}
Column.HSplitTop(MarginSmall, nullptr, &Column);

if(CurrentBackend.m_NeedsEndpointConfig)
{
CUIRect EndpointBox;
Column.HSplitTop(LineSize + MarginExtraSmall, &EndpointBox, &Column);
EndpointBox.VSplitMid(&Label, &EndpointBox);
Ui()->DoLabel(&Label, TCLocalize("LibreTranslate endpoint:"), FontSize, TEXTALIGN_ML);
static CLineInput s_TranslateEndpoint(g_Config.m_TcTranslateEndpoint, sizeof(g_Config.m_TcTranslateEndpoint));
s_TranslateEndpoint.SetEmptyText("localhost:5000/translate");
Ui()->DoEditBox(&s_TranslateEndpoint, &EndpointBox, EditBoxFontSize);
Column.HSplitTop(MarginExtraSmall, nullptr, &Column);

CUIRect KeyBox;
Column.HSplitTop(LineSize + MarginExtraSmall, &KeyBox, &Column);
KeyBox.VSplitMid(&Label, &KeyBox);
Ui()->DoLabel(&Label, TCLocalize("LibreTranslate API key:"), FontSize, TEXTALIGN_ML);
static CLineInput s_TranslateKey(g_Config.m_TcTranslateKey, sizeof(g_Config.m_TcTranslateKey));
s_TranslateKey.SetEmptyText(TCLocalize("Optional"));
Ui()->DoEditBox(&s_TranslateKey, &KeyBox, EditBoxFontSize);
}
Column.HSplitTop(MarginExtraSmall, nullptr, &Column);
s_SectionBoxes.back().h = Column.y - s_SectionBoxes.back().y;

// ***** END OF PAGE 1 SETTINGS ***** //
RightView = Column;

Expand Down
Loading
Loading