Skip to content

Commit

Permalink
Add feature for marking string translatable/non-translatable in the e…
Browse files Browse the repository at this point in the history
…ditor
Blake-Madden committed Dec 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 4e6a290 commit 86060f5
Showing 5 changed files with 307 additions and 0 deletions.
121 changes: 121 additions & 0 deletions gui/images/dt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
124 changes: 124 additions & 0 deletions gui/images/gettext.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/gui/i18napp.cpp
Original file line number Diff line number Diff line change
@@ -38,6 +38,8 @@ I18NArtProvider::I18NArtProvider()
{ L"ID_CODE", L"images/code.svg" },
{ L"ID_TRANSLATIONS", L"images/translations.svg" },
{ L"ID_CONVERT_TO_ENCODED_UNICODE", L"images/unicode-encoded.svg" },
{ L"ID_INSERT_DT", L"images/dt.svg" },
{ L"ID_INSERT_GETTEXT", L"images/gettext.svg" },
{ L"ID_CHECK", L"images/check.svg" },
{ L"ID_FORMAT", L"images/format.svg" },
{ L"ID_DEBUG", L"images/bug.svg" },
58 changes: 58 additions & 0 deletions src/gui/i18nframe.cpp
Original file line number Diff line number Diff line change
@@ -433,6 +433,12 @@ void I18NFrame::InitControls()
Bind(
wxEVT_MENU, [this](wxCommandEvent& event) { OnInsertEncodedUnicode(event); },
XRCID("ID_CONVERT_TO_ENCODED_UNICODE"));
Bind(
wxEVT_MENU, [this](wxCommandEvent& event) { OnInsertDTMacro(event); },
XRCID("ID_INSERT_DT"));
Bind(
wxEVT_MENU, [this](wxCommandEvent& event) { OnInsertTGetTextMacro(event); },
XRCID("ID_INSERT_GETTEXT"));
Bind(
wxEVT_MENU,
[this]([[maybe_unused]] wxCommandEvent&)
@@ -816,6 +822,17 @@ void I18NFrame::OnInsert(wxRibbonButtonBarEvent& event)
menuItem->SetBitmap(wxArtProvider::GetBitmap(L"ID_CONVERT_TO_ENCODED_UNICODE", wxART_OTHER,
FromDIP(wxSize{ 16, 16 })));
menu.Append(menuItem);
menu.AppendSeparator();

menuItem = new wxMenuItem(&menu, XRCID("ID_INSERT_GETTEXT"), _(L"Mark for Translation..."));
menuItem->SetBitmap(
wxArtProvider::GetBitmap(L"ID_INSERT_GETTEXT", wxART_OTHER, FromDIP(wxSize{ 16, 16 })));
menu.Append(menuItem);

menuItem = new wxMenuItem(&menu, XRCID("ID_INSERT_DT"), _(L"Mark as Non-translatable..."));
menuItem->SetBitmap(
wxArtProvider::GetBitmap(L"ID_INSERT_DT", wxART_OTHER, FromDIP(wxSize{ 16, 16 })));
menu.Append(menuItem);

event.PopupMenu(&menu);
}
@@ -1112,6 +1129,47 @@ void I18NFrame::OnInsertEncodedUnicode([[maybe_unused]] wxCommandEvent&)
}
}

//------------------------------------------------------
void I18NFrame::OnInsertTGetTextMacro([[maybe_unused]] wxCommandEvent&)
{
const wxString selText{ m_editor->GetSelectedText() };
if (selText.empty())
{
wxMessageBox(_(L"No selection found. Please select a quoted string in the editor."),
_(L"No Selection"));
return;
}
else if (!selText.starts_with(L'"') || !selText.ends_with(L'"'))
{
wxMessageBox(_(L"Please select a quoted string in the editor to wrap within a _() macro."),
_(L"No Quote Selected"));
return;
}

m_editor->ReplaceSelection(L"_(" + selText + ")");
}

//------------------------------------------------------
void I18NFrame::OnInsertDTMacro([[maybe_unused]] wxCommandEvent&)
{
const wxString selText{ m_editor->GetSelectedText() };
if (selText.empty())
{
wxMessageBox(_(L"No selection found. Please select a quoted string in the editor."),
_(L"No Selection"));
return;
}
else if (!selText.starts_with(L'"') || !selText.ends_with(L'"'))
{
wxMessageBox(
_(L"Please select a quoted string in the editor to wrap within a _DT() macro."),
_(L"No Quote Selected"));
return;
}

m_editor->ReplaceSelection(L"_DT(" + selText + ")");
}

//------------------------------------------------------
void I18NFrame::OnExportResults([[maybe_unused]] wxCommandEvent&)
{
2 changes: 2 additions & 0 deletions src/gui/i18nframe.h
Original file line number Diff line number Diff line change
@@ -63,6 +63,8 @@ class I18NFrame : public wxFrame
void OnExportResults([[maybe_unused]] wxCommandEvent&);
void OnInsertTranslatorComment([[maybe_unused]] wxCommandEvent&);
void OnInsertEncodedUnicode([[maybe_unused]] wxCommandEvent&);
void OnInsertTGetTextMacro([[maybe_unused]] wxCommandEvent&);
void OnInsertDTMacro([[maybe_unused]] wxCommandEvent&);
void OnSaveMenu(wxRibbonButtonBarEvent& event);
void OnRefresh([[maybe_unused]] wxCommandEvent&);
void OnOpenSelectedFile([[maybe_unused]] wxCommandEvent&);

0 comments on commit 86060f5

Please sign in to comment.