From 8865c4b685e8af646ee0517c3c2ab6e53daf7782 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Wed, 28 Aug 2019 16:19:46 +0200 Subject: [PATCH] Plurals for number of Undo / Redo actions. --- CMakeLists.txt | 2 +- resources/localization/PrusaSlicer.pot | 25 ++++++++------------ src/slic3r/GUI/GLCanvas3D.cpp | 2 +- src/slic3r/GUI/I18N.hpp | 32 +++++++++++++++++++------- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25612e34d..3fac3daaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -368,7 +368,7 @@ target_include_directories(cereal INTERFACE include) # l10n set(L10N_DIR "${SLIC3R_RESOURCES_DIR}/localization") add_custom_target(pot - COMMAND xgettext --keyword=L --keyword=L_CONTEXT:1,2c --add-comments=TRN --from-code=UTF-8 --debug + COMMAND xgettext --keyword=L --keyword=L_CONTEXT:1,2c --keyword=_L_PLURAL:1,2 --add-comments=TRN --from-code=UTF-8 --debug -f "${L10N_DIR}/list.txt" -o "${L10N_DIR}/PrusaSlicer.pot" WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} diff --git a/resources/localization/PrusaSlicer.pot b/resources/localization/PrusaSlicer.pot index 78028a691..1e4fc404d 100644 --- a/resources/localization/PrusaSlicer.pot +++ b/resources/localization/PrusaSlicer.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-28 15:34+0200\n" +"POT-Creation-Date: 2019-08-28 16:09+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -16,6 +16,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" #: src/slic3r/GUI/AboutDialog.cpp:39 src/slic3r/GUI/AboutDialog.cpp:291 msgid "Portions copyright" @@ -831,23 +832,17 @@ msgstr "" #: src/slic3r/GUI/GLCanvas3D.cpp:3497 #, possible-c-format -msgid "Undo %d Actions" -msgstr "" +msgid "Undo %1$d Action" +msgid_plural "Undo %1$d Actions" +msgstr[0] "" +msgstr[1] "" #: src/slic3r/GUI/GLCanvas3D.cpp:3497 #, possible-c-format -msgid "Redo %d Actions" -msgstr "" - -#: src/slic3r/GUI/GLCanvas3D.cpp:3497 -#, possible-c-format -msgid "Undo %d Action" -msgstr "" - -#: src/slic3r/GUI/GLCanvas3D.cpp:3497 -#, possible-c-format -msgid "Redo %d Action" -msgstr "" +msgid "Redo %1$d Action" +msgid_plural "Redo %1$d Actions" +msgstr[0] "" +msgstr[1] "" #: src/slic3r/GUI/GLCanvas3D.cpp:3544 msgid "Add..." diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index d9b948c2f..8527a2f43 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3494,7 +3494,7 @@ void GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x) if (selected >= 0) is_undo ? wxGetApp().plater()->undo_to(selected) : wxGetApp().plater()->redo_to(selected); - imgui->text(wxString::Format(_(hovered ? (is_undo ? L("Undo %d Actions") : L("Redo %d Actions")) : (is_undo ? L("Undo %d Action") : L("Redo %d Action"))), hovered + 1)); + imgui->text(wxString::Format(is_undo ? _L_PLURAL("Undo %1$d Action", "Undo %1$d Actions", hovered + 1) : _L_PLURAL("Redo %1$d Action", "Redo %1$d Actions", hovered + 1), hovered + 1)); imgui->end(); } diff --git a/src/slic3r/GUI/I18N.hpp b/src/slic3r/GUI/I18N.hpp index 13c119b99..bf3103f77 100644 --- a/src/slic3r/GUI/I18N.hpp +++ b/src/slic3r/GUI/I18N.hpp @@ -36,16 +36,26 @@ namespace Slic3r { namespace GUI { namespace I18N { - inline wxString translate(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)); } - inline wxString translate(const wchar_t *s) { return wxGetTranslation(s); } - inline wxString translate(const std::string &s) { return wxGetTranslation(wxString(s.c_str(), wxConvUTF8)); } + inline wxString translate(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)); } + inline wxString translate(const wchar_t *s) { return wxGetTranslation(s); } + inline wxString translate(const std::string &s) { return wxGetTranslation(wxString(s.c_str(), wxConvUTF8)); } inline wxString translate(const std::wstring &s) { return wxGetTranslation(s.c_str()); } - inline std::string translate_utf8(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)).ToUTF8().data(); } - inline std::string translate_utf8(const wchar_t *s) { return wxGetTranslation(s).ToUTF8().data(); } - inline std::string translate_utf8(const std::string &s) { return wxGetTranslation(wxString(s.c_str(), wxConvUTF8)).ToUTF8().data(); } + inline wxString translate(const char *s, const char *plural, unsigned int n) { return wxGetTranslation(wxString(s, wxConvUTF8), wxString(plural, wxConvUTF8), n); } + inline wxString translate(const wchar_t *s, const wchar_t *plural, unsigned int n) { return wxGetTranslation(s, plural, n); } + inline wxString translate(const std::string &s, const std::string &plural, unsigned int n) { return wxGetTranslation(wxString(s.c_str(), wxConvUTF8), wxString(plural.c_str(), wxConvUTF8), n); } + inline wxString translate(const std::wstring &s, const std::wstring &plural, unsigned int n) { return wxGetTranslation(s.c_str(), plural.c_str(), n); } + + inline std::string translate_utf8(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)).ToUTF8().data(); } + inline std::string translate_utf8(const wchar_t *s) { return wxGetTranslation(s).ToUTF8().data(); } + inline std::string translate_utf8(const std::string &s) { return wxGetTranslation(wxString(s.c_str(), wxConvUTF8)).ToUTF8().data(); } inline std::string translate_utf8(const std::wstring &s) { return wxGetTranslation(s.c_str()).ToUTF8().data(); } + inline std::string translate_utf8(const char *s, const char *plural, unsigned int n) { return translate(s, plural, n).ToUTF8().data(); } + inline std::string translate_utf8(const wchar_t *s, const wchar_t *plural, unsigned int n) { return translate(s, plural, n).ToUTF8().data(); } + inline std::string translate_utf8(const std::string &s, const std::string &plural, unsigned int n) { return translate(s, plural, n).ToUTF8().data(); } + inline std::string translate_utf8(const std::wstring &s, const std::wstring &plural, unsigned int n) { return translate(s, plural, n).ToUTF8().data(); } + #if wxCHECK_VERSION(3, 1, 1) #define _wxGetTranslation_ctx(S, CTX) wxGetTranslation((S), wxEmptyString, (CTX)) #else @@ -63,11 +73,17 @@ namespace I18N { inline wxString translate_utf8(const std::wstring &s, const char* ctx) { return _wxGetTranslation_ctx(s.c_str(), ctx).ToUTF8().data(); } #undef _wxGetTranslation_ctx -} +} // namespace I18N // Return translated std::string as a wxString wxString L_str(const std::string &str); -} } +} // namespace GUI +} // namespace Slic3r + +// Macro to function both as a marker for xgettext and to actually perform the translation. +#ifndef _L_PLURAL +#define _L_PLURAL(s, plural, n) Slic3r::GUI::I18N::translate(s, plural, n) +#endif /* L */ #endif /* slic3r_GUI_I18N_hpp_ */