From 77d4c747ef332b317b1daf53161cbc3242aeab00 Mon Sep 17 00:00:00 2001 From: SweetId <2630750+SweetId@users.noreply.github.com> Date: Fri, 20 Oct 2023 23:25:53 -0400 Subject: [PATCH] use Nz::LocalizedText instead of std::string for text displayed to users --- .../NazaraEditor/Core/Application/Action.hpp | 5 +++-- .../Core/Application/BaseApplication.hpp | 3 ++- include/NazaraEditor/Core/UI/MainWindow.hpp | 2 +- include/NazaraEditor/Core/UI/Window.hpp | 5 +++-- src/NazaraEditor/Core/UI/MainWindow.cpp | 2 +- src/NazaraEditor/Core/UI/Window.cpp | 4 ++-- src/NazaraEditor/Editor/UI/AssetsWindow.cpp | 2 +- .../Editor/UI/InspectorWindow.cpp | 2 +- src/NazaraEditor/Editor/UI/LevelWindow.cpp | 2 +- src/NazaraEditor/Editor/UI/MainWindow.cpp | 2 +- src/NazaraEditor/Editor/UI/OutputWindow.cpp | 2 +- src/NazaraEditor/Editor/main.cpp | 19 +++++++++++-------- 12 files changed, 28 insertions(+), 22 deletions(-) diff --git a/include/NazaraEditor/Core/Application/Action.hpp b/include/NazaraEditor/Core/Application/Action.hpp index fbf6e1c..af76f1c 100644 --- a/include/NazaraEditor/Core/Application/Action.hpp +++ b/include/NazaraEditor/Core/Application/Action.hpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -17,8 +18,8 @@ namespace Nz struct Properties { std::string className; - std::string description; - std::string path; + Nz::LocalizedText description; + Nz::LocalizedText path; std::string category; Nz::Shortcut shortcut; diff --git a/include/NazaraEditor/Core/Application/BaseApplication.hpp b/include/NazaraEditor/Core/Application/BaseApplication.hpp index c6f058f..aa2cb6e 100644 --- a/include/NazaraEditor/Core/Application/BaseApplication.hpp +++ b/include/NazaraEditor/Core/Application/BaseApplication.hpp @@ -14,11 +14,12 @@ #include #include #include +#include namespace Nz { class NAZARAEDITOR_CORE_API EditorBaseApplication - : public Nz::Application + : public Nz::Application { public: NazaraSignal(OnLevelChanged, Nz::Level&); diff --git a/include/NazaraEditor/Core/UI/MainWindow.hpp b/include/NazaraEditor/Core/UI/MainWindow.hpp index e2d432d..342392f 100644 --- a/include/NazaraEditor/Core/UI/MainWindow.hpp +++ b/include/NazaraEditor/Core/UI/MainWindow.hpp @@ -8,7 +8,7 @@ namespace Nz : public EditorWindow { public: - EditorMainWindow(EditorBaseApplication* app, const std::string& name = "", const std::vector& categories = {}); + EditorMainWindow(EditorBaseApplication* app, const Nz::LocalizedText& name, const std::vector& categories = {}); virtual ~EditorMainWindow() = default; protected: diff --git a/include/NazaraEditor/Core/UI/Window.hpp b/include/NazaraEditor/Core/UI/Window.hpp index 81f7c58..5145ea1 100644 --- a/include/NazaraEditor/Core/UI/Window.hpp +++ b/include/NazaraEditor/Core/UI/Window.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace Nz { @@ -14,7 +15,7 @@ namespace Nz : private Nz::ImguiHandler { public: - EditorWindow(EditorBaseApplication* app, const std::string& name = "", const std::vector& categories = {}); + EditorWindow(EditorBaseApplication* app, const Nz::LocalizedText& name, const std::vector& categories = {}); virtual ~EditorWindow(); EditorWindow(const EditorWindow&) = delete; @@ -40,7 +41,7 @@ namespace Nz private: EditorBaseApplication* m_application; - std::string m_windowName; + Nz::LocalizedText m_windowName; std::vector m_categories; struct MenuAction diff --git a/src/NazaraEditor/Core/UI/MainWindow.cpp b/src/NazaraEditor/Core/UI/MainWindow.cpp index 3884c61..40504eb 100644 --- a/src/NazaraEditor/Core/UI/MainWindow.cpp +++ b/src/NazaraEditor/Core/UI/MainWindow.cpp @@ -2,7 +2,7 @@ namespace Nz { - EditorMainWindow::EditorMainWindow(EditorBaseApplication* app, const std::string& name, const std::vector& categories) + EditorMainWindow::EditorMainWindow(EditorBaseApplication* app, const Nz::LocalizedText& name, const std::vector& categories) : EditorWindow(app, name, categories) { } diff --git a/src/NazaraEditor/Core/UI/Window.cpp b/src/NazaraEditor/Core/UI/Window.cpp index 4e2f7e6..dac3798 100644 --- a/src/NazaraEditor/Core/UI/Window.cpp +++ b/src/NazaraEditor/Core/UI/Window.cpp @@ -5,7 +5,7 @@ namespace Nz { - EditorWindow::EditorWindow(EditorBaseApplication* app, const std::string& name, const std::vector& categories) + EditorWindow::EditorWindow(EditorBaseApplication* app, const Nz::LocalizedText& name, const std::vector& categories) : m_application(app) , m_windowName(name) , m_categories(categories) @@ -18,7 +18,7 @@ namespace Nz return; auto name = prop.className; - AddMenuAction(prop.path, prop.shortcut.ToString(), [name]() { Nz::EditorBaseApplication::Instance()->GetActionStack().ExecuteAction(name); }, prop.icon); + AddMenuAction(prop.path.ToString(), prop.shortcut.ToString(), [name]() { Nz::EditorBaseApplication::Instance()->GetActionStack().ExecuteAction(name); }, prop.icon); }); } diff --git a/src/NazaraEditor/Editor/UI/AssetsWindow.cpp b/src/NazaraEditor/Editor/UI/AssetsWindow.cpp index 7debb21..7bb2382 100644 --- a/src/NazaraEditor/Editor/UI/AssetsWindow.cpp +++ b/src/NazaraEditor/Editor/UI/AssetsWindow.cpp @@ -3,7 +3,7 @@ namespace NzEditor { AssetsWindow::AssetsWindow(Nz::EditorBaseApplication* app) - : Nz::EditorWindow(app, "Assets Browser", { "Assets" }) + : Nz::EditorWindow(app, Nz::LocalizedText("LOC_EDITOR_WINDOW_ASSET_BROWSER_TITLE"), { "Assets" }) { BuildMenuBar(); } diff --git a/src/NazaraEditor/Editor/UI/InspectorWindow.cpp b/src/NazaraEditor/Editor/UI/InspectorWindow.cpp index ba40010..87a03cc 100644 --- a/src/NazaraEditor/Editor/UI/InspectorWindow.cpp +++ b/src/NazaraEditor/Editor/UI/InspectorWindow.cpp @@ -5,7 +5,7 @@ namespace NzEditor { InspectorWindow::InspectorWindow(Nz::EditorBaseApplication* app) - : Nz::EditorWindow(app, "Inspector") + : Nz::EditorWindow(app, Nz::LocalizedText("LOC_EDITOR_WINDOW_INSPECTOR_TITLE")) { app->OnEntitySelected.Connect(this, &InspectorWindow::OnEntitySelected); } diff --git a/src/NazaraEditor/Editor/UI/LevelWindow.cpp b/src/NazaraEditor/Editor/UI/LevelWindow.cpp index c4256d7..88f5952 100644 --- a/src/NazaraEditor/Editor/UI/LevelWindow.cpp +++ b/src/NazaraEditor/Editor/UI/LevelWindow.cpp @@ -6,7 +6,7 @@ namespace NzEditor { LevelWindow::LevelWindow(Nz::EditorBaseApplication* app) - : Nz::EditorWindow(app, "Level") + : Nz::EditorWindow(app, Nz::LocalizedText("LOC_EDITOR_WINDOW_LEVEL_TITLE")) , m_currentLevel(app->GetLevel()) , m_dirty(true) { diff --git a/src/NazaraEditor/Editor/UI/MainWindow.cpp b/src/NazaraEditor/Editor/UI/MainWindow.cpp index 96ad79d..2dfb85a 100644 --- a/src/NazaraEditor/Editor/UI/MainWindow.cpp +++ b/src/NazaraEditor/Editor/UI/MainWindow.cpp @@ -3,7 +3,7 @@ namespace NzEditor { MainWindow::MainWindow(Nz::EditorBaseApplication* app) - : Nz::EditorMainWindow(app, "MainWindow", { "General", "Plugins" }) + : Nz::EditorMainWindow(app, Nz::LocalizedText("LOC_EDITOR_WINDOW_MAIN_TITLE"), { "General", "Plugins" }) { } } \ No newline at end of file diff --git a/src/NazaraEditor/Editor/UI/OutputWindow.cpp b/src/NazaraEditor/Editor/UI/OutputWindow.cpp index 5b46e02..6585ce6 100644 --- a/src/NazaraEditor/Editor/UI/OutputWindow.cpp +++ b/src/NazaraEditor/Editor/UI/OutputWindow.cpp @@ -6,7 +6,7 @@ namespace NzEditor { OutputWindow::OutputWindow(Nz::EditorBaseApplication* app) - : Nz::EditorWindow(app, "Output", { "Output" }) + : Nz::EditorWindow(app, Nz::LocalizedText("LOC_EDITOR_WINDOW_OUTPUT_TITLE"), { "Output" }) , m_bScrollToBottom(true) , m_bScrollToTop(false) { diff --git a/src/NazaraEditor/Editor/main.cpp b/src/NazaraEditor/Editor/main.cpp index 466dc7b..e7c99b2 100644 --- a/src/NazaraEditor/Editor/main.cpp +++ b/src/NazaraEditor/Editor/main.cpp @@ -36,6 +36,9 @@ int WinMain(int argc, char* argv[]) app.SetResourceFolder(resourceDir); app.SetLogger(logger); + Nz::Localization::Instance()->LoadLocalizationFile(resourceDir / "localization.csv"); + Nz::Localization::Instance()->SetLocale("en-US"); + ImGui::EnsureContextOnThisThread(); app.RegisterWindow(); @@ -49,25 +52,25 @@ int WinMain(int argc, char* argv[]) texParams.loadFormat = Nz::PixelFormat::RGBA8_SRGB; app.RegisterAction({ - .description = "Create new level", - .path = "File|Level|New", + .description = Nz::LocalizedText("LOC_EDITOR_ACTION_LEVEL_NEW_DESC"), + .path = Nz::LocalizedText("LOC_EDITOR_ACTION_LEVEL_NEW_PATH"), .category = "General", .shortcut = Nz::Shortcut::Create(Nz::Keyboard::VKey::N, true, true), .icon = Nz::Texture::LoadFromFile(app.GetResourceFolder() / "file_new.png", texParams) }); app.RegisterAction({ - .description = "Clears log output", - .path = "Clear", + .description = Nz::LocalizedText("LOC_EDITOR_ACTION_LOG_CLEAR_DESC"), + .path = Nz::LocalizedText("LOC_EDITOR_ACTION_LOG_CLEAR_PATH"), .category = "Output", }); app.RegisterAction({ - .description = "Copies log output to clipboard", - .path = "Copy to Clipboard", + .description = Nz::LocalizedText("LOC_EDITOR_ACTION_LOG_COPY_DESC"), + .path = Nz::LocalizedText("LOC_EDITOR_ACTION_LOG_COPY_PATH"), .category = "Output", }); app.RegisterAction({ - .description = "Exits the editor", - .path = "File|Exit", + .description = Nz::LocalizedText("LOC_EDITOR_ACTION_QUIT_DESC"), + .path = Nz::LocalizedText("LOC_EDITOR_ACTION_QUIT_PATH"), .category = "General", .shortcut = Nz::Shortcut::Create(Nz::Keyboard::VKey::F4, false, false, true), });