Add SetLocale action

This commit is contained in:
SweetId 2023-10-21 16:43:57 -04:00
parent e3c0f72d53
commit 71f257d1ed
5 changed files with 50 additions and 3 deletions

View File

@ -12,4 +12,29 @@ namespace Nz
public:
void Execute() override;
};
class NAZARAEDITOR_CORE_API EditorAction_SetLocale final
: public EditorAction
{
public:
EditorAction_SetLocale(const Properties& properties, std::string_view locale)
: EditorAction(properties)
, m_locale(locale)
{}
EditorAction_SetLocale(const std::shared_ptr<Properties>& properties, std::string_view locale)
: EditorAction(properties)
, m_locale(locale)
{}
~EditorAction_SetLocale() = default;
std::unique_ptr<EditorAction> Clone() const override { return std::make_unique<EditorAction_SetLocale>(m_properties, m_locale); }
const std::string& GetName() const override { return m_properties->className; }
bool IsUndoRedoable() const override { return false; }
static const char* GetClassName() { return "EditorAction_SetLocale"; }
void Execute() override;
protected:
std::string m_locale;
};
}

View File

@ -8,6 +8,8 @@ namespace NzEditor
: public Nz::EditorBaseApplication
{
public:
Application();
virtual bool NewLevel() override;
};
}

View File

@ -1,6 +1,7 @@
#include <NazaraEditor/Core/Application/Actions/EditorAction_Editor.hpp>
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
#include <NazaraEditor/Core/UI/PopupManager.hpp>
#include <NazaraLocalization/Localization.hpp>
namespace Nz
{
@ -21,4 +22,9 @@ namespace Nz
});
}
void EditorAction_SetLocale::Execute()
{
Nz::Localization::Instance()->SetLocale(m_locale);
}
}

View File

@ -1,7 +1,21 @@
#include <NazaraEditor/Editor/Application.hpp>
#include <NazaraLocalization/Localization.hpp>
namespace NzEditor
{
Application::Application()
{
Nz::Localization::OnLocaleInstalled.Connect([this](std::string_view locale) {
RegisterAction<Nz::EditorAction_SetLocale>({
.className = std::format("{}_{}", Nz::EditorAction_SetLocale::GetClassName(), locale),
.description = locale,
.path = { "LOC_EDITOR_MENU_TOOLS", "LOC_EDITOR_MENU_LANGUAGE", locale },
.category = "Tools",
}, locale);
});
}
bool Application::NewLevel()
{
bool bResult = EditorBaseApplication::NewLevel();

View File

@ -36,9 +36,6 @@ 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<NzEditor::MainWindow>();
@ -47,6 +44,9 @@ int WinMain(int argc, char* argv[])
app.RegisterWindow<NzEditor::InspectorWindow>();
app.RegisterWindow<NzEditor::OutputWindow>();
Nz::Localization::Instance()->LoadLocalizationFile(resourceDir / "localization.csv");
Nz::Localization::Instance()->SetLocale("en-US");
Nz::TextureParams texParams;
texParams.renderDevice = Nz::Graphics::Instance()->GetRenderDevice();
texParams.loadFormat = Nz::PixelFormat::RGBA8_SRGB;