Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pkg_check_modules(
hyprtoolkit
pixman-1
libdrm
hyprutils
hyprutils>=0.10.2
hyprwire
icu-uc
hyprlang
Expand Down
36 changes: 18 additions & 18 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ CConfigManager::CConfigManager() : m_inotifyFd(inotify_init()) {

m_config->addConfigValue("general:grab_focus", Hyprlang::INT{1});

m_config->addConfigValue("locale:override", Hyprlang::STRING{""});

m_config->addConfigValue("cache:enabled", Hyprlang::INT{1});

m_config->addConfigValue("finders:default_finder", Hyprlang::STRING{"desktop"});
Expand Down
32 changes: 32 additions & 0 deletions src/i18n/Engine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "Engine.hpp"
#include "../config/ConfigManager.hpp"

static Hyprutils::I18n::CI18nEngine engine;

//
void I18n::initEngine() {
engine.setFallbackLocale("en_US");

// en_US (English)
engine.registerEntry("en_US", TXT_KEY_SEARCH_SOMETHING, "Search...");

// pl_PL (Polish)
engine.registerEntry("pl_PL", TXT_KEY_SEARCH_SOMETHING, "Szukaj...");

// ja_JP (Japanese)
engine.registerEntry("ja_JP", TXT_KEY_SEARCH_SOMETHING, "検索...");

// zh (Simplified Chinese)
engine.registerEntry("zh", TXT_KEY_SEARCH_SOMETHING, "搜索...");

// zh_Hant (Traditional Chinese)
engine.registerEntry("zh_Hant", TXT_KEY_SEARCH_SOMETHING, "搜尋...");
}

std::string I18n::localize(eTextKeys key, const Hyprutils::I18n::translationVarMap& vars) {
static auto POVERRIDELOCALE = Hyprlang::CSimpleConfigValue<Hyprlang::STRING>(g_configManager->m_config.get(), "locale:override");

const auto LOCALE = std::string_view{*POVERRIDELOCALE}.empty() ? engine.getSystemLocale().locale() : std::string{*POVERRIDELOCALE};

return engine.localizeEntry(LOCALE, key, vars);
}
15 changes: 15 additions & 0 deletions src/i18n/Engine.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <cstdint>
#include <string>
#include <hyprutils/i18n/I18nEngine.hpp>

namespace I18n {
//NOLINTNEXTLINE
enum eTextKeys : uint64_t {
TXT_KEY_SEARCH_SOMETHING = 0,
};

void initEngine();
std::string localize(eTextKeys key, const Hyprutils::I18n::translationVarMap& vars);
};
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "socket/ServerSocket.hpp"
#include "query/QueryProcessor.hpp"
#include "config/ConfigManager.hpp"
#include "i18n/Engine.hpp"

#include <iostream>

Expand Down Expand Up @@ -112,6 +113,8 @@ int main(int argc, char** argv, char** envp) {

socket.reset();

I18n::initEngine();

if (!explicitOptions.empty()) {
g_ipcFinder->setData(explicitOptions);
g_queryProcessor->overrideQueryProvider(g_ipcFinder);
Expand Down
3 changes: 2 additions & 1 deletion src/ui/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../socket/ServerSocket.hpp"
#include "../helpers/Log.hpp"
#include "../config/ConfigManager.hpp"
#include "../i18n/Engine.hpp"

#include <hyprutils/string/String.hpp>
#include <xkbcommon/xkbcommon-keysyms.h>
Expand Down Expand Up @@ -33,7 +34,7 @@ CUI::CUI(bool open) : m_openByDefault(open) {
m_layout->setMargin(4);

m_inputBox = Hyprtoolkit::CTextboxBuilder::begin()
->placeholder("Search something...")
->placeholder(I18n::localize(I18n::TXT_KEY_SEARCH_SOMETHING, {}))
->onTextEdited([](SP<Hyprtoolkit::CTextboxElement>, const std::string& query) { g_queryProcessor->scheduleQueryUpdate(query); })
->size({Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT, Hyprtoolkit::CDynamicSize::HT_SIZE_ABSOLUTE, {1.F, 28.F}})
->multiline(false)
Expand Down