From 2eb55d48c7bc96eb68aa932aee8a338fa82b9acd Mon Sep 17 00:00:00 2001 From: Kuzemko Alexsandr <1382812+Kuzma30@users.noreply.github.com> Date: Fri, 21 Oct 2022 05:35:09 +0300 Subject: [PATCH] [App] Fix of untranslated first document's name (#7156) * Change no need function newDocument("Unnamed") call to variant without parameter. "Unnamed" set in App newDocument function instead. * Refactor New Document command to run without parameter. * Translate new document's userName. Internal name = "Unnamed". * Crowdin Add to updatets.py App.ts. Create new file App.ts * Fix error where document name is set with one function parameter. In this situation set internal and user name to string variable. For default function call (without parameter) set internal name to Unnamed, userName = translate ("Unnamed") --- src/App/Application.cpp | 13 ++++++++++++- src/App/Resources/translations/App.ts | 21 +++++++++++++++++++++ src/Gui/CommandDoc.cpp | 3 +-- src/Mod/Fem/App/AppFemPy.cpp | 2 +- src/Mod/Import/App/AppImportPy.cpp | 2 +- src/Mod/Import/Gui/AppImportGuiPy.cpp | 2 +- src/Mod/Mesh/App/AppMeshPy.cpp | 2 +- src/Mod/Part/App/AppPartPy.cpp | 4 ++-- src/Mod/Path/Gui/AppPathGuiPy.cpp | 2 +- src/Mod/Points/App/AppPointsPy.cpp | 2 +- src/Tools/updatets.py | 1 + 11 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 src/App/Resources/translations/App.ts diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 084388fbe9..30ebb0d7f8 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -407,9 +407,13 @@ void Application::renameDocument(const char *OldName, const char *NewName) Document* Application::newDocument(const char * Name, const char * UserName, bool createView, bool tempDoc) { + bool defaultConstructor= false; // get a valid name anyway! if (!Name || Name[0] == '\0') + { Name = "Unnamed"; + defaultConstructor= true; //we have function call like newDocument(); + } string name = getUniqueDocumentName(Name, tempDoc); // return the temporary document if it exists @@ -424,7 +428,14 @@ Document* Application::newDocument(const char * Name, const char * UserName, boo userName = UserName; } else { - userName = Name; + if (defaultConstructor) //we have function call newDocument() thus set internal name to "Unnamed" and userName to translated string "Unnamed" + { + QString L10nUserName = QObject::tr("Unnamed"); + userName = L10nUserName.toStdString().c_str(); + } + else { + userName = Name; + } std::vector names; names.reserve(DocMap.size()); std::map::const_iterator pos; diff --git a/src/App/Resources/translations/App.ts b/src/App/Resources/translations/App.ts new file mode 100644 index 0000000000..54d30d1e2c --- /dev/null +++ b/src/App/Resources/translations/App.ts @@ -0,0 +1,21 @@ + + + + + LinkParams + + + Stores the last user choice of whether to apply CopyOnChange setup to all link +that links to the same configurable object + + + + + QObject + + + Unnamed + + + + diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index 2b4feb1cde..ff1d0a78fc 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -603,8 +603,7 @@ void StdCmdNew::activated(int iMsg) { Q_UNUSED(iMsg); QString cmd; - cmd = QString::fromLatin1("App.newDocument(\"%1\")") - .arg(qApp->translate("StdCmdNew","Unnamed")); + cmd = QString::fromLatin1("App.newDocument()"); runCommand(Command::Doc,cmd.toUtf8()); doCommand(Command::Gui,"Gui.activeDocument().activeView().viewDefaultOrientation()"); diff --git a/src/Mod/Fem/App/AppFemPy.cpp b/src/Mod/Fem/App/AppFemPy.cpp index 937d99fb30..ef692999a1 100644 --- a/src/Mod/Fem/App/AppFemPy.cpp +++ b/src/Mod/Fem/App/AppFemPy.cpp @@ -112,7 +112,7 @@ private: mesh->read(EncodedName.c_str()); Base::FileInfo file(EncodedName.c_str()); // create new document and add Import feature - App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); + App::Document *pcDoc = App::GetApplication().newDocument(); FemMeshObject *pcFeature = static_cast (pcDoc->addObject("Fem::FemMeshObject", file.fileNamePure().c_str())); pcFeature->Label.setValue(file.fileNamePure().c_str()); diff --git a/src/Mod/Import/App/AppImportPy.cpp b/src/Mod/Import/App/AppImportPy.cpp index 4c4b671da8..0eda0a087d 100644 --- a/src/Mod/Import/App/AppImportPy.cpp +++ b/src/Mod/Import/App/AppImportPy.cpp @@ -159,7 +159,7 @@ private: pcDoc = App::GetApplication().getDocument(DocName); } if (!pcDoc) { - pcDoc = App::GetApplication().newDocument("Unnamed"); + pcDoc = App::GetApplication().newDocument(); } Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication(); diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index c8d61826a1..0bf09ed12f 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -424,7 +424,7 @@ private: pcDoc = App::GetApplication().getDocument(DocName); } if (!pcDoc) { - pcDoc = App::GetApplication().newDocument("Unnamed"); + pcDoc = App::GetApplication().newDocument(); } Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication(); diff --git a/src/Mod/Mesh/App/AppMeshPy.cpp b/src/Mod/Mesh/App/AppMeshPy.cpp index e88848231d..9196910800 100644 --- a/src/Mod/Mesh/App/AppMeshPy.cpp +++ b/src/Mod/Mesh/App/AppMeshPy.cpp @@ -175,7 +175,7 @@ private: PyMem_Free(Name); // create new document and add Import feature - App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); + App::Document *pcDoc = App::GetApplication().newDocument(); Mesh::Importer import(pcDoc); import.load(EncodedName); diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index 7e0df3738b..ca9ce43b56 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -735,7 +735,7 @@ private: if (file.hasExtension("stp") || file.hasExtension("step")) { // create new document and add Import feature - App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); + App::Document *pcDoc = App::GetApplication().newDocument(); #if 1 ImportStepParts(pcDoc,EncodedName.c_str()); #else @@ -746,7 +746,7 @@ private: } #if 1 else if (file.hasExtension("igs") || file.hasExtension("iges")) { - App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); + App::Document *pcDoc = App::GetApplication().newDocument(); ImportIgesParts(pcDoc,EncodedName.c_str()); pcDoc->recompute(); } diff --git a/src/Mod/Path/Gui/AppPathGuiPy.cpp b/src/Mod/Path/Gui/AppPathGuiPy.cpp index 5772dccbd5..8077b8dd7a 100644 --- a/src/Mod/Path/Gui/AppPathGuiPy.cpp +++ b/src/Mod/Path/Gui/AppPathGuiPy.cpp @@ -104,7 +104,7 @@ private: std::ostringstream pre; std::ostringstream cmd; if (processor.empty()) { - App::Document *pcDoc = App::GetApplication().newDocument("Unnamed"); + App::Document *pcDoc = App::GetApplication().newDocument(); Gui::Command::runCommand(Gui::Command::Gui,"import Path"); cmd << "Path.read(\"" << EncodedName << "\",\"" << pcDoc->getName() << "\")"; Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str()); diff --git a/src/Mod/Points/App/AppPointsPy.cpp b/src/Mod/Points/App/AppPointsPy.cpp index aba6213f94..751af38549 100644 --- a/src/Mod/Points/App/AppPointsPy.cpp +++ b/src/Mod/Points/App/AppPointsPy.cpp @@ -113,7 +113,7 @@ private: reader->read(EncodedName); - App::Document* pcDoc = App::GetApplication().newDocument("Unnamed"); + App::Document* pcDoc = App::GetApplication().newDocument(); Points::Feature* pcFeature = nullptr; if (reader->hasProperties()) { diff --git a/src/Tools/updatets.py b/src/Tools/updatets.py index 99a13e44c3..8977e86a95 100755 --- a/src/Tools/updatets.py +++ b/src/Tools/updatets.py @@ -57,6 +57,7 @@ import re import pathlib directories = [ + {"tsname":"App", "workingdir":"./src/App", "tsdir":"Resources/translations"}, {"tsname":"FreeCAD", "workingdir":"./src/Gui", "tsdir":"Language"}, {"tsname":"AddonManager", "workingdir":"./src/Mod/AddonManager/", "tsdir":"Resources/translations"}, {"tsname":"Arch", "workingdir":"./src/Mod/Arch/", "tsdir":"Resources/translations"},