initial localization setup

This commit is contained in:
Jussi Kuokkanen 2023-10-05 17:33:11 +03:00
parent a370dc9fa9
commit d9b3db6c0c
9 changed files with 336 additions and 40 deletions

View File

@ -6,4 +6,5 @@ cppc = meson.get_compiler('cpp')
incdir = include_directories('src/include', 'src/include/deps')
subdir('po')
subdir('src')

1
po/LINGUAS Normal file
View File

@ -0,0 +1 @@
fi

1
po/POTFILES Normal file
View File

@ -0,0 +1 @@
src/plugins/Nvidia.cpp

136
po/fi.po Normal file
View File

@ -0,0 +1,136 @@
# Finnish translations for tuxclocker package.
# Copyright (C) 2023 THE tuxclocker'S COPYRIGHT HOLDER
# This file is distributed under the same license as the tuxclocker package.
# Automatically generated, 2023.
#
msgid ""
msgstr ""
"Project-Id-Version: tuxclocker\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-05 18:07+0300\n"
"PO-Revision-Date: 2023-10-05 11:07+0300\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: fi\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: src/plugins/Nvidia.cpp:149 src/plugins/Nvidia.cpp:197
#: src/plugins/Nvidia.cpp:216 src/plugins/Nvidia.cpp:237
msgid "MHz"
msgstr ""
#: src/plugins/Nvidia.cpp:153
msgid "Memory Clock Offset"
msgstr "Muistikellon taajuuspoikkeama"
#: src/plugins/Nvidia.cpp:200
#, fuzzy
msgid "Core Clock Offset"
msgstr "Muistikellon taajuuspoikkeama"
#: src/plugins/Nvidia.cpp:220
msgid "Core Clock"
msgstr ""
#: src/plugins/Nvidia.cpp:241
#, fuzzy
msgid "Memory Clock"
msgstr "Muistikellon taajuuspoikkeama"
#: src/plugins/Nvidia.cpp:255
msgid "Clocks"
msgstr ""
#: src/plugins/Nvidia.cpp:275 src/plugins/Nvidia.cpp:310
#: src/plugins/Nvidia.cpp:372 src/plugins/Nvidia.cpp:392
#: src/plugins/Nvidia.cpp:428
msgid "%"
msgstr ""
#: src/plugins/Nvidia.cpp:280 src/plugins/Nvidia.cpp:315
msgid "Fan Speed"
msgstr ""
#: src/plugins/Nvidia.cpp:351
msgid "Automatic"
msgstr ""
#: src/plugins/Nvidia.cpp:351
msgid "Manual"
msgstr ""
#: src/plugins/Nvidia.cpp:357
msgid "Fan Mode"
msgstr ""
#: src/plugins/Nvidia.cpp:376
msgid "Core Utilization"
msgstr ""
#: src/plugins/Nvidia.cpp:396
msgid "Memory Utilization"
msgstr ""
#: src/plugins/Nvidia.cpp:432
msgid "PCIe Bandwidth Utilization"
msgstr ""
#: src/plugins/Nvidia.cpp:448 src/plugins/Nvidia.cpp:489
msgid "W"
msgstr ""
#: src/plugins/Nvidia.cpp:452
msgid "Power Usage"
msgstr ""
#: src/plugins/Nvidia.cpp:492
msgid "Power Limit"
msgstr ""
#: src/plugins/Nvidia.cpp:507 src/plugins/Nvidia.cpp:524
#: src/plugins/Nvidia.cpp:539
msgid "°C"
msgstr ""
#: src/plugins/Nvidia.cpp:511
msgid "Temperature"
msgstr ""
#: src/plugins/Nvidia.cpp:527
msgid "Slowdown Temperature"
msgstr ""
#: src/plugins/Nvidia.cpp:542
msgid "Shutdown Temperature"
msgstr ""
#: src/plugins/Nvidia.cpp:557 src/plugins/Nvidia.cpp:601
msgid "mV"
msgstr ""
#: src/plugins/Nvidia.cpp:561
msgid "Core Voltage"
msgstr ""
#: src/plugins/Nvidia.cpp:605
msgid "Core Voltage Offset"
msgstr ""
#: src/plugins/Nvidia.cpp:622
msgid "Fan"
msgstr ""
#: src/plugins/Nvidia.cpp:652
msgid "Temperatures"
msgstr ""
#: src/plugins/Nvidia.cpp:660
msgid "Fans"
msgstr ""
#: src/plugins/Nvidia.cpp:668
msgid "Utilizations"
msgstr ""

6
po/meson.build Normal file
View File

@ -0,0 +1,6 @@
i18n = import('i18n')
# define GETTEXT_PACKAGE
add_project_arguments('-DGETTEXT_PACKAGE="tuxclocker"', language:'cpp')
i18n.gettext(
meson.project_name(),
args : '--from-code=UTF-8')

134
po/tuxclocker.pot Normal file
View File

@ -0,0 +1,134 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the tuxclocker package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: tuxclocker\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-05 18:07+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: src/plugins/Nvidia.cpp:149 src/plugins/Nvidia.cpp:197
#: src/plugins/Nvidia.cpp:216 src/plugins/Nvidia.cpp:237
msgid "MHz"
msgstr ""
#: src/plugins/Nvidia.cpp:153
msgid "Memory Clock Offset"
msgstr ""
#: src/plugins/Nvidia.cpp:200
msgid "Core Clock Offset"
msgstr ""
#: src/plugins/Nvidia.cpp:220
msgid "Core Clock"
msgstr ""
#: src/plugins/Nvidia.cpp:241
msgid "Memory Clock"
msgstr ""
#: src/plugins/Nvidia.cpp:255
msgid "Clocks"
msgstr ""
#: src/plugins/Nvidia.cpp:275 src/plugins/Nvidia.cpp:310
#: src/plugins/Nvidia.cpp:372 src/plugins/Nvidia.cpp:392
#: src/plugins/Nvidia.cpp:428
msgid "%"
msgstr ""
#: src/plugins/Nvidia.cpp:280 src/plugins/Nvidia.cpp:315
msgid "Fan Speed"
msgstr ""
#: src/plugins/Nvidia.cpp:351
msgid "Automatic"
msgstr ""
#: src/plugins/Nvidia.cpp:351
msgid "Manual"
msgstr ""
#: src/plugins/Nvidia.cpp:357
msgid "Fan Mode"
msgstr ""
#: src/plugins/Nvidia.cpp:376
msgid "Core Utilization"
msgstr ""
#: src/plugins/Nvidia.cpp:396
msgid "Memory Utilization"
msgstr ""
#: src/plugins/Nvidia.cpp:432
msgid "PCIe Bandwidth Utilization"
msgstr ""
#: src/plugins/Nvidia.cpp:448 src/plugins/Nvidia.cpp:489
msgid "W"
msgstr ""
#: src/plugins/Nvidia.cpp:452
msgid "Power Usage"
msgstr ""
#: src/plugins/Nvidia.cpp:492
msgid "Power Limit"
msgstr ""
#: src/plugins/Nvidia.cpp:507 src/plugins/Nvidia.cpp:524
#: src/plugins/Nvidia.cpp:539
msgid "°C"
msgstr ""
#: src/plugins/Nvidia.cpp:511
msgid "Temperature"
msgstr ""
#: src/plugins/Nvidia.cpp:527
msgid "Slowdown Temperature"
msgstr ""
#: src/plugins/Nvidia.cpp:542
msgid "Shutdown Temperature"
msgstr ""
#: src/plugins/Nvidia.cpp:557 src/plugins/Nvidia.cpp:601
msgid "mV"
msgstr ""
#: src/plugins/Nvidia.cpp:561
msgid "Core Voltage"
msgstr ""
#: src/plugins/Nvidia.cpp:605
msgid "Core Voltage Offset"
msgstr ""
#: src/plugins/Nvidia.cpp:622
msgid "Fan"
msgstr ""
#: src/plugins/Nvidia.cpp:652
msgid "Temperatures"
msgstr ""
#: src/plugins/Nvidia.cpp:660
msgid "Fans"
msgstr ""
#: src/plugins/Nvidia.cpp:668
msgid "Utilizations"
msgstr ""

View File

@ -1,5 +1,6 @@
#include <Crypto.hpp>
#include <Device.hpp>
#include <libintl.h>
#include <NVCtrl/NVCtrl.h>
#include <Plugin.hpp>
@ -14,6 +15,8 @@
#include <NVCtrl/NVCtrlLib.h>
#include <nvml.h>
#define _(String) gettext(String)
using namespace TuxClocker;
using namespace TuxClocker::Crypto;
using namespace TuxClocker::Device;
@ -143,11 +146,11 @@ std::vector<TreeNode<DeviceNode>> getMemClockWrite(NvidiaGPUData data) {
return fromNVMLRet(ret);
};
Assignable a{setFunc, range, getFunc, "MHz"};
Assignable a{setFunc, range, getFunc, _("MHz")};
if (getFunc().has_value())
return {DeviceNode{
.name = "Memory Clock Offset",
.name = _("Memory Clock Offset"),
.interface = a,
.hash = md5(data.uuid + "Memory Clock Offset"),
}};
@ -191,10 +194,10 @@ std::vector<TreeNode<DeviceNode>> getCoreClockWrite(NvidiaGPUData data) {
return std::nullopt;
};
Assignable a{setFunc, range, getFunc, "MHz"};
Assignable a{setFunc, range, getFunc, _("MHz")};
return {DeviceNode{
.name = "Core Clock Offset",
.name = _("Core Clock Offset"),
.interface = a,
.hash = md5(data.uuid + "Core Clock Offset"),
}};
@ -210,11 +213,11 @@ std::vector<TreeNode<DeviceNode>> getCoreClockRead(NvidiaGPUData data) {
return fromNVMLError(ret);
};
DynamicReadable dr{func, "MHz"};
DynamicReadable dr{func, _("MHz")};
if (hasReadableValue(func()))
return {DeviceNode{
.name = "Core Clock",
.name = _("Core Clock"),
.interface = dr,
.hash = md5(data.uuid + "Core Clock"),
}};
@ -231,11 +234,11 @@ std::vector<TreeNode<DeviceNode>> getMemClockRead(NvidiaGPUData data) {
return fromNVMLError(ret);
};
DynamicReadable dr{func, "MHz"};
DynamicReadable dr{func, _("MHz")};
if (hasReadableValue(func()))
return {DeviceNode{
.name = "Memory Clock",
.name = _("Memory Clock"),
.interface = dr,
.hash = md5(data.uuid + "Memory Clock"),
}};
@ -249,7 +252,7 @@ std::vector<TreeNode<DeviceNode>> getClocksRoot(NvidiaGPUData data) {
// Another option would be to check from here if any children would get added,
// but that's spaghetti and inefficient.
return {DeviceNode{
.name = "Clocks",
.name = _("Clocks"),
.interface = std::nullopt,
.hash = md5(data.uuid + "Clocks"),
}};
@ -269,12 +272,12 @@ std::vector<TreeNode<DeviceNode>> getFanSpeedRead(NvidiaGPUData data) {
return fromNVMLError(ret);
};
DynamicReadable dr{func, "%"};
DynamicReadable dr{func, _("%")};
fanId++;
if (hasReadableValue(func()))
return {DeviceNode{
.name = "Fan Speed",
.name = _("Fan Speed"),
.interface = dr,
.hash = md5(data.uuid + "Fan Speed Read" + std::to_string(id)),
}};
@ -304,12 +307,12 @@ std::vector<TreeNode<DeviceNode>> getFanSpeedWrite(NvidiaGPUData data) {
return fromNVMLRet(ret);
};
Assignable a{setFunc, Range<int>{0, 100}, getFunc, "%"};
Assignable a{setFunc, Range<int>{0, 100}, getFunc, _("%")};
fanId++;
if (getFunc().has_value())
return {DeviceNode{
.name = "Fan Speed",
.name = _("Fan Speed"),
.interface = a,
.hash = md5(data.uuid + "Fan Speed Write" + std::to_string(id)),
}};
@ -345,13 +348,13 @@ std::vector<TreeNode<DeviceNode>> getFanMode(NvidiaGPUData data) {
auto ret = nvmlDeviceSetFanSpeed_v2(data.devHandle, id, current);
return fromNVMLRet(ret);
};
EnumerationVec opts = {{"Automatic", 0}, {"Manual", 1}};
EnumerationVec opts = {{_("Automatic"), 0}, {_("Manual"), 1}};
Assignable a{setFunc, opts, getFunc, std::nullopt};
fanId++;
return {DeviceNode{
.name = "Fan Mode",
.name = _("Fan Mode"),
.interface = a,
.hash = md5(data.uuid + "Fan Mode" + std::to_string(id)),
}};
@ -366,11 +369,11 @@ std::vector<TreeNode<DeviceNode>> getCoreUtilization(NvidiaGPUData data) {
return value.gpu;
};
DynamicReadable dr{func, "%"};
DynamicReadable dr{func, _("%")};
if (hasReadableValue(func()))
return {DeviceNode{
.name = "Core Utilization",
.name = _("Core Utilization"),
.interface = dr,
.hash = md5(data.uuid + "Core Utilization"),
}};
@ -386,11 +389,11 @@ std::vector<TreeNode<DeviceNode>> getMemoryUtilization(NvidiaGPUData data) {
return value.memory;
};
DynamicReadable dr{func, "%"};
DynamicReadable dr{func, _("%")};
if (hasReadableValue(func()))
return {DeviceNode{
.name = "Memory Utilization",
.name = _("Memory Utilization"),
.interface = dr,
.hash = md5(data.uuid + "Memory Utilization"),
}};
@ -422,11 +425,11 @@ std::vector<TreeNode<DeviceNode>> getPcieUtilization(NvidiaGPUData data) {
return ReadError::UnknownError;
};
DynamicReadable dr{func, "%"};
DynamicReadable dr{func, _("%")};
if (hasReadableValue(func()))
return {DeviceNode{
.name = "PCIe Bandwidth Utilization",
.name = _("PCIe Bandwidth Utilization"),
.interface = dr,
.hash = md5(data.uuid + "PCIe Bandwidth Utilization"),
}};
@ -442,11 +445,11 @@ std::vector<TreeNode<DeviceNode>> getPowerUsage(NvidiaGPUData data) {
return static_cast<double>(value) / 1000;
};
DynamicReadable dr{func, "W"};
DynamicReadable dr{func, _("W")};
if (hasReadableValue(func()))
return {DeviceNode{
.name = "Power Usage",
.name = _("Power Usage"),
.interface = dr,
.hash = md5(data.uuid + "Power Usage"),
}};
@ -483,10 +486,10 @@ std::vector<TreeNode<DeviceNode>> getPowerLimit(NvidiaGPUData data) {
return fromNVMLRet(ret);
};
Assignable a{setFunc, range, getFunc, "W"};
Assignable a{setFunc, range, getFunc, _("W")};
return {DeviceNode{
.name = "Power Limit",
.name = _("Power Limit"),
.interface = a,
.hash = md5(data.uuid + "Power Limit"),
}};
@ -501,11 +504,11 @@ std::vector<TreeNode<DeviceNode>> getTemperature(NvidiaGPUData data) {
return temp;
};
DynamicReadable dr{func, "°C"};
DynamicReadable dr{func, _("°C")};
if (hasReadableValue(func()))
return {DeviceNode{
.name = "Temperature",
.name = _("Temperature"),
.interface = dr,
.hash = md5(data.uuid + "Temperature"),
}};
@ -518,10 +521,10 @@ std::vector<TreeNode<DeviceNode>> getSlowdownTemperature(NvidiaGPUData data) {
data.devHandle, NVML_TEMPERATURE_THRESHOLD_SLOWDOWN, &temp) != NVML_SUCCESS)
return {};
StaticReadable sr{temp, "°C"};
StaticReadable sr{temp, _("°C")};
return {DeviceNode{
.name = "Slowdown Temperature",
.name = _("Slowdown Temperature"),
.interface = sr,
.hash = md5(data.uuid + "Slowdown Temperature"),
}};
@ -533,10 +536,10 @@ std::vector<TreeNode<DeviceNode>> getShutdownTemperature(NvidiaGPUData data) {
data.devHandle, NVML_TEMPERATURE_THRESHOLD_SHUTDOWN, &temp) != NVML_SUCCESS)
return {};
StaticReadable sr{temp, "°C"};
StaticReadable sr{temp, _("°C")};
return {DeviceNode{
.name = "Shutdown Temperature",
.name = _("Shutdown Temperature"),
.interface = sr,
.hash = md5(data.uuid + "Shutdown Temperature"),
}};
@ -551,11 +554,11 @@ std::vector<TreeNode<DeviceNode>> getVoltage(NvidiaGPUData data) {
return static_cast<double>(value) / 1000;
};
DynamicReadable dr{func, "mV"};
DynamicReadable dr{func, _("mV")};
if (hasReadableValue(func()))
return {DeviceNode{
.name = "Core Voltage",
.name = _("Core Voltage"),
.interface = dr,
.hash = md5(data.uuid + "Core Voltage"),
}};
@ -595,11 +598,11 @@ std::vector<TreeNode<DeviceNode>> getVoltageOffset(NvidiaGPUData data) {
return std::nullopt;
};
Assignable a{setFunc, range, getFunc, "mV"};
Assignable a{setFunc, range, getFunc, _("mV")};
if (getFunc().has_value())
return {DeviceNode{
.name = "Core Voltage Offset",
.name = _("Core Voltage Offset"),
.interface = a,
.hash = md5(data.uuid + "Core Voltage Offset"),
}};
@ -616,7 +619,7 @@ std::vector<TreeNode<DeviceNode>> getMultiFanRoots(NvidiaGPUData data) {
nodes.push_back(DeviceNode{
.name = index,
.interface = std::nullopt,
.hash = md5(data.uuid + "Fan" + index),
.hash = md5(data.uuid + _("Fan") + index),
});
}
return nodes;
@ -646,7 +649,7 @@ std::vector<TreeNode<DeviceNode>> getSingleFanMode(NvidiaGPUData data) {
std::vector<TreeNode<DeviceNode>> getTemperaturesRoot(NvidiaGPUData data) {
return {DeviceNode{
.name = "Temperatures",
.name = _("Temperatures"),
.interface = std::nullopt,
.hash = md5(data.uuid + "Temperatures"),
}};
@ -654,7 +657,7 @@ std::vector<TreeNode<DeviceNode>> getTemperaturesRoot(NvidiaGPUData data) {
std::vector<TreeNode<DeviceNode>> getFanRoot(NvidiaGPUData data) {
return {DeviceNode{
.name = "Fans",
.name = _("Fans"),
.interface = std::nullopt,
.hash = md5(data.uuid + "Fans"),
}};
@ -662,7 +665,7 @@ std::vector<TreeNode<DeviceNode>> getFanRoot(NvidiaGPUData data) {
std::vector<TreeNode<DeviceNode>> getUtilizationsRoot(NvidiaGPUData data) {
return {DeviceNode{
.name = "Utilizations",
.name = _("Utilizations"),
.interface = std::nullopt,
.hash = md5(data.uuid + "Utilizations"),
}};
@ -723,6 +726,8 @@ NvidiaPlugin::~NvidiaPlugin() {
}
NvidiaPlugin::NvidiaPlugin() : m_dpy() {
// NOTE: we don't seem to need to do any locale stuff here,
// since the daemon does and loads us
if (nvmlInit_v2() != NVML_SUCCESS)
std::cout << "nvidia: couldn't initialize NVML!\n";

View File

@ -1,5 +1,6 @@
#include <DBusTypes.hpp>
#include <iostream>
#include <libintl.h>
#include <QCoreApplication>
#include <QDBusConnection>
#include <QDBusError>
@ -21,6 +22,12 @@ namespace TCDBus = TuxClocker::DBus;
int main(int argc, char **argv) {
QCoreApplication a(argc, argv);
// TODO: should numbers here be localized or not?
setlocale(LC_MESSAGES, "");
bindtextdomain("tuxclocker", TUXCLOCKER_LOCALE_PATH);
bind_textdomain_codeset("tuxclocker", "UTF-8");
textdomain("tuxclocker");
auto connection = QDBusConnection::systemBus();
auto plugins = DevicePlugin::loadPlugins();
QVector<QDBusAbstractAdaptor *> adaptors;

View File

@ -8,7 +8,11 @@ patterns_inc = include_directories('../include/deps/patterns/include/mpark')
moc_files = qt5.preprocess(moc_headers : ['Adaptors.hpp'],
dependencies : qt5_dep)
# Compile time definition for locale path
locale_path_def_template = '-DTUXCLOCKER_LOCALE_PATH="@0@/@1@/locale"'
locale_path_def = locale_path_def_template.format(get_option('prefix'), get_option('datadir'))
sources = ['main.cpp']
executable('tuxclockerd',
@ -18,6 +22,7 @@ executable('tuxclockerd',
include_directories : [incdir, patterns_inc],
dependencies : [qt5_dep, boost_dep],
link_with : libtuxclocker,
cpp_args : locale_path_def,
install : true)
# DBus data directories