Skip to content

Commit

Permalink
Translations (PR #2505)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikjuvonen committed Apr 7, 2023
1 parent 7f802e6 commit 73c6457
Show file tree
Hide file tree
Showing 879 changed files with 148,847 additions and 125,011 deletions.
20 changes: 17 additions & 3 deletions Client/core/CLocalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ SString CLocalization::ValidateLocale(SString strLocale)
{
if (strLocale.empty() && (CClientVariables::GetSingletonPtr() == nullptr || !CVARS_GET("locale", strLocale)))
strLocale = "en_US";

// NOTE(patrik): Convert old two letter language to locale to fix any issues with flags
if (strLocale == "en")
strLocale = "en_US";
else if (strLocale == "fi")
strLocale = "fi_FI";
else if (strLocale == "az")
strLocale = "az_AZ";
else if (strLocale == "ka")
strLocale = "ka_GE";

Language Lang = Language::from_name(strLocale);
Lang = Lang ? Lang : Language::from_name("en_US");
return Lang.str();
Expand Down Expand Up @@ -128,7 +139,9 @@ std::vector<SString> CLocalization::GetAvailableLocales()
{
std::vector<SString> localeList = {"en_US"};
for (const auto& language : m_DictManager.get_languages(MTA_LOCALE_TEXTDOMAIN))
localeList.push_back(language.str());
// To avoid duplicates
if (std::find(localeList.begin(), localeList.end(), language.str()) == localeList.end())
localeList.push_back(language.str());
// Alpha sort
std::sort(localeList.begin(), localeList.end());
return localeList;
Expand All @@ -153,9 +166,10 @@ SString CLocalization::GetLanguageName()
}

// Get the file directory of the current language
SString CLocalization::GetLanguageDirectory()
SString CLocalization::GetLanguageDirectory(CLanguage* pLanguage)
{
SString strFullPath = m_pCurrentLang->GetDictionary().get_filepath();
CLanguage* pSelectLang = pLanguage != nullptr ? pLanguage : m_pCurrentLang;
SString strFullPath = pSelectLang->GetDictionary().get_filepath();

// Replace all backslashes with forward slashes
int idx = 0;
Expand Down
2 changes: 1 addition & 1 deletion Client/core/CLocalization.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CLocalization : public CLocalizationInterface
SString GetTranslators();
std::vector<SString> GetAvailableLocales();
bool IsLocalized();
SString GetLanguageDirectory();
SString GetLanguageDirectory(CLanguage* pLanguage = nullptr);
SString GetLanguageCode();
SString GetLanguageName();
SString ValidateLocale(SString strLocale);
Expand Down
33 changes: 19 additions & 14 deletions Client/core/CMainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#define CORE_MTA_LOGO "cgui\\images\\background_logo.png"
#define CORE_MTA_FILLER "cgui\\images\\mta_filler.png"
#define CORE_MTA_VERSION "cgui\\images\\version.png"
#define CORE_MTA_LATEST_NEWS "cgui\\images\\latest_news.png"

static int WaitForMenu = 0;
static const SColor headlineColors[] = {SColorRGBA(233, 234, 106, 255), SColorRGBA(233 / 6 * 4, 234 / 6 * 4, 106 / 6 * 4, 255),
Expand Down Expand Up @@ -209,21 +208,28 @@ CMainMenu::CMainMenu(CGUI* pManager)
m_pMenuArea->SetMouseEnterHandler(GUI_CALLBACK(&CMainMenu::OnMenuEnter, this));
m_pMenuArea->SetMouseLeaveHandler(GUI_CALLBACK(&CMainMenu::OnMenuExit, this));

float fDrawSizeX = (335 / NATIVE_RES_X) * m_iMenuSizeX; // Right aligned
float fDrawSizeY = (53 / NATIVE_RES_Y) * m_iMenuSizeY;
float fDrawPosX = 0.83f * m_iMenuSizeX - fDrawSizeX;
float fDrawPosY = 0.60f * m_iMenuSizeY;
m_pLatestNews = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
m_pLatestNews->LoadFromFile(CORE_MTA_LATEST_NEWS);
if (!m_pLatestNews->LoadFromFile(PathJoin(g_pCore->GetLocalization()->GetLanguageDirectory(), "latest_news.png")))
{
// Load en_US if no localization is available
auto pLanguage = g_pLocalization->GetLanguage("en_US");
m_pLatestNews->LoadFromFile(PathJoin(g_pCore->GetLocalization()->GetLanguageDirectory(pLanguage), "latest_news.png"));
}
m_pLatestNews->SetParent(m_pCanvas);
m_pLatestNews->SetPosition(CVector2D(fDrawPosX, fDrawPosY), false);
m_pLatestNews->SetSize(CVector2D(fDrawSizeX, fDrawSizeY), false);
m_pLatestNews->SetProperty("InheritsAlpha", "False");
CVector2D vecNativeSize;
m_pLatestNews->GetNativeSize(vecNativeSize);
float fDrawSizeX = (vecNativeSize.fX / NATIVE_RES_X) * m_iMenuSizeX;
float fDrawSizeY = (vecNativeSize.fY / NATIVE_RES_Y) * m_iMenuSizeY;
m_pLatestNews->SetSize(CVector2D(fDrawSizeX, fDrawSizeY), false);
float fDrawPosX = 0.83f * m_iMenuSizeX - fDrawSizeX; // Right aligned
float fDrawPosY = 0.61f * m_iMenuSizeY;
m_pLatestNews->SetPosition(CVector2D(fDrawPosX, fDrawPosY), false);
m_pLatestNews->SetVisible(false);

// Create news item stuff
fDrawPosX -= 25;
fDrawPosY += fDrawSizeY - 8;
fDrawPosY += fDrawSizeY + 3;
for (uint i = 0; i < CORE_MTA_NEWS_ITEMS; i++)
{
fDrawPosY += 20;
Expand Down Expand Up @@ -1007,13 +1013,12 @@ sMenuItem* CMainMenu::CreateItem(unsigned char menuType, const char* szFilename,
{
CGUIStaticImage* pImage = reinterpret_cast<CGUIStaticImage*>(m_pManager->CreateStaticImage());

if (g_pCore->GetLocalization()->IsLocalized())
if (!pImage->LoadFromFile(PathJoin(g_pCore->GetLocalization()->GetLanguageDirectory(), szFilename)))
{
if (!pImage->LoadFromFile(PathJoin(g_pCore->GetLocalization()->GetLanguageDirectory(), szFilename)))
pImage->LoadFromFile(PathJoin("cgui/images", szFilename));
// Load en_US if no localization is available
auto pLanguage = g_pLocalization->GetLanguage("en_US");
pImage->LoadFromFile(PathJoin(g_pCore->GetLocalization()->GetLanguageDirectory(pLanguage), szFilename));
}
else
pImage->LoadFromFile(PathJoin("cgui/images", szFilename));

// Make our positions absolute
int iPosX = vecRelPosition.fX * m_iMenuSizeX;
Expand Down
49 changes: 24 additions & 25 deletions Client/core/CSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void CSettings::CreateGUI()
// Mouse Options
m_pControlsMouseLabel = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(pTabControls, _("Mouse options")));
m_pControlsMouseLabel->SetPosition(CVector2D(vecTemp.fX + 11, vecTemp.fY));
m_pControlsMouseLabel->AutoSize(NULL, 5.0f);
m_pControlsMouseLabel->AutoSize(NULL, 20.0f);
m_pControlsMouseLabel->SetFont("default-bold-small");
vecTemp.fY += 18;

Expand All @@ -177,7 +177,7 @@ void CSettings::CreateGUI()
m_pFlyWithMouse->AutoSize(NULL, 20.0f);

// MouseSensitivity
vecTemp.fY += 52.0f;
vecTemp.fY += 54.0f;
m_pLabelMouseSensitivity = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(pTabControls, _("Mouse sensitivity:")));
m_pLabelMouseSensitivity->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY));
m_pLabelMouseSensitivity->AutoSize();
Expand All @@ -193,7 +193,7 @@ void CSettings::CreateGUI()
m_pLabelMouseSensitivityValue->SetPosition(CVector2D(vecTemp.fX + vecSize.fX + 5.0f, vecTemp.fY));
m_pLabelMouseSensitivityValue->AutoSize("100%");
vecTemp.fX = 16;
vecTemp.fY += 26.f;
vecTemp.fY += 24.f;

// VerticalAimSensitivity
m_pLabelVerticalAimSensitivity = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(pTabControls, _("Vertical aim sensitivity:")));
Expand Down Expand Up @@ -272,12 +272,12 @@ void CSettings::CreateGUI()
m_pEditSaturation->SetTextChangedHandler(GUI_CALLBACK(&CSettings::OnJoypadTextChanged, this));

CGUILabel* pLabelDeadZone = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(pTabControls, _("Dead Zone")));
pLabelDeadZone->SetPosition(m_pEditDeadzone->GetPosition() + CVector2D(52.f, -1.f));
pLabelDeadZone->SetPosition(m_pEditDeadzone->GetPosition() + CVector2D(52.f, 1.f));
pLabelDeadZone->AutoSize();
pLabelDeadZone->SetVerticalAlign(CGUI_ALIGN_VERTICALCENTER);

CGUILabel* pLabelSaturation = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(pTabControls, _("Saturation")));
pLabelSaturation->SetPosition(m_pEditSaturation->GetPosition() + CVector2D(52.f, -1.f));
pLabelSaturation->SetPosition(m_pEditSaturation->GetPosition() + CVector2D(52.f, 1.f));
pLabelSaturation->AutoSize();
pLabelSaturation->SetVerticalAlign(CGUI_ALIGN_VERTICALCENTER);
vecTemp.fY += 106;
Expand Down Expand Up @@ -526,7 +526,7 @@ void CSettings::CreateGUI()
m_pAudioRadioLabel = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(pTabAudio, _("Radio options")));
m_pAudioRadioLabel->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 30.0f), false);
m_pAudioRadioLabel->GetPosition(vecTemp, false);
m_pAudioRadioLabel->AutoSize(NULL, 10.0f);
m_pAudioRadioLabel->AutoSize(NULL, 20.0f);
m_pAudioRadioLabel->SetFont("default-bold-small");

m_pCheckBoxAudioEqualizer = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabAudio, _("Radio Equalizer"), true));
Expand All @@ -542,7 +542,7 @@ void CSettings::CreateGUI()
m_pAudioUsertrackLabel = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(pTabAudio, _("Usertrack options")));
m_pAudioUsertrackLabel->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 30.0f), false);
m_pAudioUsertrackLabel->GetPosition(vecTemp, false);
m_pAudioUsertrackLabel->AutoSize(NULL, 10.0f);
m_pAudioUsertrackLabel->AutoSize(NULL, 20.0f);
m_pAudioUsertrackLabel->SetFont("default-bold-small");

m_pLabelUserTrackMode = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(pTabAudio, _("Play mode:")));
Expand All @@ -568,7 +568,7 @@ void CSettings::CreateGUI()
m_pAudioMuteLabel = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(pTabAudio, _("Mute options")));
m_pAudioMuteLabel->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 52.0f));
m_pAudioMuteLabel->GetPosition(vecTemp, false);
m_pAudioMuteLabel->AutoSize(NULL, 5.0f);
m_pAudioMuteLabel->AutoSize(NULL, 20.0f);
m_pAudioMuteLabel->SetFont("default-bold-small");

m_pCheckBoxMuteMaster = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabAudio, _("Mute All sounds when minimized"), true));
Expand Down Expand Up @@ -903,16 +903,16 @@ void CSettings::CreateGUI()
m_pLabelBrowserCustomBlacklist = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pTabBrowser, _("Custom blacklist")));
m_pLabelBrowserCustomBlacklist->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 30.0f));
m_pLabelBrowserCustomBlacklist->GetPosition(vecTemp);
m_pLabelBrowserCustomBlacklist->AutoSize(NULL, 5.0f);
m_pLabelBrowserCustomBlacklist->AutoSize(NULL, 20.0f);
m_pLabelBrowserCustomBlacklist->SetFont("default-bold-small");

m_pEditBrowserBlacklistAdd = reinterpret_cast<CGUIEdit*>(pManager->CreateEdit(m_pTabBrowser));
m_pEditBrowserBlacklistAdd->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 25.0f));
m_pEditBrowserBlacklistAdd->GetPosition(vecTemp);
m_pEditBrowserBlacklistAdd->SetSize(CVector2D(191.0f, 22.0f));
m_pEditBrowserBlacklistAdd->SetSize(CVector2D(209.0f, 22.0f));

m_pLabelBrowserBlacklistAdd = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pEditBrowserBlacklistAdd, _("Enter a domain e.g. google.com")));
m_pLabelBrowserBlacklistAdd->SetPosition(CVector2D(10, 3), false);
m_pLabelBrowserBlacklistAdd->SetPosition(CVector2D(10.0f, 3.0f), false);
m_pLabelBrowserBlacklistAdd->SetTextColor(0, 0, 0);
m_pLabelBrowserBlacklistAdd->SetSize(CVector2D(1, 1), true);
m_pLabelBrowserBlacklistAdd->SetAlpha(0.7f);
Expand All @@ -921,12 +921,12 @@ void CSettings::CreateGUI()

m_pButtonBrowserBlacklistAdd = reinterpret_cast<CGUIButton*>(pManager->CreateButton(m_pTabBrowser, _("Block")));
m_pButtonBrowserBlacklistAdd->SetPosition(CVector2D(vecTemp.fX + m_pEditBrowserBlacklistAdd->GetSize().fX + 2.0f, vecTemp.fY));
m_pButtonBrowserBlacklistAdd->SetSize(CVector2D(64.0f, 22.0f));
m_pButtonBrowserBlacklistAdd->SetSize(CVector2D(90.0f, 22.0f));

m_pGridBrowserBlacklist = reinterpret_cast<CGUIGridList*>(pManager->CreateGridList(m_pTabBrowser));
m_pGridBrowserBlacklist->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 32.0f));
m_pGridBrowserBlacklist->GetPosition(vecTemp);
m_pGridBrowserBlacklist->SetSize(CVector2D(256.0f, 150.0f));
m_pGridBrowserBlacklist->SetSize(CVector2D(300.0f, 150.0f));
m_pGridBrowserBlacklist->AddColumn(_("Domain"), 0.9f);

m_pButtonBrowserBlacklistRemove = reinterpret_cast<CGUIButton*>(pManager->CreateButton(m_pTabBrowser, _("Remove domain")));
Expand All @@ -936,18 +936,18 @@ void CSettings::CreateGUI()
m_pLabelBrowserCustomBlacklist->GetPosition(vecTemp); // Reset vecTemp

m_pLabelBrowserCustomWhitelist = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pTabBrowser, _("Custom whitelist")));
m_pLabelBrowserCustomWhitelist->SetPosition(CVector2D(292.0f, vecTemp.fY));
m_pLabelBrowserCustomWhitelist->SetPosition(CVector2D(vecTemp.fX + 300.0f + 19.0f, vecTemp.fY));
m_pLabelBrowserCustomWhitelist->GetPosition(vecTemp);
m_pLabelBrowserCustomWhitelist->AutoSize(NULL, 5.0f);
m_pLabelBrowserCustomWhitelist->AutoSize(NULL, 20.0f);
m_pLabelBrowserCustomWhitelist->SetFont("default-bold-small");

m_pEditBrowserWhitelistAdd = reinterpret_cast<CGUIEdit*>(pManager->CreateEdit(m_pTabBrowser));
m_pEditBrowserWhitelistAdd->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 25.0f));
m_pEditBrowserWhitelistAdd->GetPosition(vecTemp);
m_pEditBrowserWhitelistAdd->SetSize(CVector2D(191.0f, 22.0f));
m_pEditBrowserWhitelistAdd->SetSize(CVector2D(209.0f, 22.0f));

m_pLabelBrowserWhitelistAdd = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pEditBrowserWhitelistAdd, _("Enter a domain e.g. google.com")));
m_pLabelBrowserWhitelistAdd->SetPosition(CVector2D(10, 3), false);
m_pLabelBrowserWhitelistAdd->SetPosition(CVector2D(10.0f, 3.0f), false);
m_pLabelBrowserWhitelistAdd->SetTextColor(0, 0, 0);
m_pLabelBrowserWhitelistAdd->SetSize(CVector2D(1, 1), true);
m_pLabelBrowserWhitelistAdd->SetAlpha(0.7f);
Expand All @@ -956,12 +956,12 @@ void CSettings::CreateGUI()

m_pButtonBrowserWhitelistAdd = reinterpret_cast<CGUIButton*>(pManager->CreateButton(m_pTabBrowser, _("Allow")));
m_pButtonBrowserWhitelistAdd->SetPosition(CVector2D(vecTemp.fX + m_pEditBrowserWhitelistAdd->GetSize().fX + 2.0f, vecTemp.fY));
m_pButtonBrowserWhitelistAdd->SetSize(CVector2D(64.0f, 22.0f));
m_pButtonBrowserWhitelistAdd->SetSize(CVector2D(90.0f, 22.0f));

m_pGridBrowserWhitelist = reinterpret_cast<CGUIGridList*>(pManager->CreateGridList(m_pTabBrowser));
m_pGridBrowserWhitelist->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 32.0f));
m_pGridBrowserWhitelist->GetPosition(vecTemp);
m_pGridBrowserWhitelist->SetSize(CVector2D(256.0f, 150.0f));
m_pGridBrowserWhitelist->SetSize(CVector2D(300.0f, 150.0f));
m_pGridBrowserWhitelist->AddColumn(_("Domain"), 0.9f);

m_pButtonBrowserWhitelistRemove = reinterpret_cast<CGUIButton*>(pManager->CreateButton(m_pTabBrowser, _("Remove domain")));
Expand Down Expand Up @@ -1124,18 +1124,17 @@ void CSettings::CreateGUI()
m_pWin8Label = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(pTabAdvanced, _("Windows 8 compatibility:")));
m_pWin8Label->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY));
m_pWin8Label->AutoSize();
vecTemp.fX += 20;

m_pWin8ColorCheckBox = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabAdvanced, _("16-bit color")));
m_pWin8ColorCheckBox->SetPosition(CVector2D(vecTemp.fX + fIndentX, vecTemp.fY - 1.0f));
m_pWin8ColorCheckBox->SetPosition(CVector2D(vecTemp.fX + fIndentX, vecTemp.fY));
m_pWin8ColorCheckBox->AutoSize(NULL, 20.0f);
vecTemp.fX += 90;
vecTemp.fX += 140;

m_pWin8MouseCheckBox = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabAdvanced, _("Mouse fix")));
m_pWin8MouseCheckBox->SetPosition(CVector2D(vecTemp.fX + fIndentX, vecTemp.fY - 1.0f));
m_pWin8MouseCheckBox->SetPosition(CVector2D(vecTemp.fX + fIndentX, vecTemp.fY));
m_pWin8MouseCheckBox->AutoSize(NULL, 20.0f);
vecTemp.fY += fLineHeight;
vecTemp.fX -= 110;
vecTemp.fX -= 140;

// Hide if not Win8
if (atoi(GetApplicationSetting("real-os-version")) != 8)
Expand Down Expand Up @@ -2318,7 +2317,7 @@ void CSettings::CreateInterfaceTabGUI()
pLabel = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(pTabOptions, _("Options")));
pLabel->SetPosition(CVector2D(fMarginX, 10.0f));
pLabel->GetPosition(vecTemp);
pLabel->AutoSize(NULL, 5.0f);
pLabel->AutoSize(NULL, 20.0f);
pLabel->SetFont("default-bold-small");

m_pChatCssBackground = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabOptions, _("Hide background when not typing")));
Expand Down
2 changes: 1 addition & 1 deletion Client/loader/MainFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CLocalizationDummy : public CLocalizationInterface

virtual std::vector<SString> GetAvailableLocales() { return std::vector<SString>(); }
virtual bool IsLocalized() { return false; }
virtual SString GetLanguageDirectory() { return ""; }
virtual SString GetLanguageDirectory(CLanguage* pLanguage = nullptr) { return ""; }
virtual SString GetLanguageCode() { return "en_US"; }
virtual SString GetLanguageName() { return "English"; }
};
Expand Down
4 changes: 3 additions & 1 deletion Client/sdk/core/CLocalizationInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#define _tcn g_pLocalization->TranslatePluralWithContext
#define _td // Dummy translation tag for compile-time use only. Translation templates are generated by this, but no source code interaction

class CLanguage;

class CLocalizationInterface
{
public:
Expand All @@ -31,7 +33,7 @@ class CLocalizationInterface

virtual std::vector<SString> GetAvailableLocales() = 0;
virtual bool IsLocalized() = 0;
virtual SString GetLanguageDirectory() = 0;
virtual SString GetLanguageDirectory(CLanguage* pLanguage = nullptr) = 0;
virtual SString GetLanguageCode() = 0;
virtual SString GetLanguageName() = 0;
};
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 73c6457

Please sign in to comment.