mirror of https://github.com/nirenjan/libx52.git
Add string representations and associated i18n
parent
a0b7769dab
commit
62894dea43
|
@ -13,7 +13,7 @@ lib_LTLIBRARIES = libx52io.la
|
||||||
libx52io_v_CUR=0
|
libx52io_v_CUR=0
|
||||||
libx52io_v_AGE=0
|
libx52io_v_AGE=0
|
||||||
libx52io_v_REV=0
|
libx52io_v_REV=0
|
||||||
libx52io_la_SOURCES = io_core.c io_axis.c io_parser.c
|
libx52io_la_SOURCES = io_core.c io_axis.c io_parser.c io_strings.c
|
||||||
libx52io_la_CFLAGS = @HIDAPI_CFLAGS@ -DLOCALEDIR=\"$(localedir)\" -I $(top_srcdir) $(WARN_CFLAGS)
|
libx52io_la_CFLAGS = @HIDAPI_CFLAGS@ -DLOCALEDIR=\"$(localedir)\" -I $(top_srcdir) $(WARN_CFLAGS)
|
||||||
libx52io_la_LDFLAGS = \
|
libx52io_la_LDFLAGS = \
|
||||||
-export-symbols-regex '^libx52io_' \
|
-export-symbols-regex '^libx52io_' \
|
||||||
|
|
|
@ -6,10 +6,12 @@
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0
|
* SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "io_common.h"
|
#include "io_common.h"
|
||||||
#include "usb-ids.h"
|
#include "usb-ids.h"
|
||||||
|
#include "gettext.h"
|
||||||
|
|
||||||
int libx52io_init(libx52io_context **ctx)
|
int libx52io_init(libx52io_context **ctx)
|
||||||
{
|
{
|
||||||
|
@ -30,6 +32,12 @@ int libx52io_init(libx52io_context **ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
*ctx = tmp;
|
*ctx = tmp;
|
||||||
|
|
||||||
|
#if ENABLE_NLS
|
||||||
|
/* Setup the gettext utilities */
|
||||||
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||||
|
#endif
|
||||||
|
|
||||||
return LIBX52IO_SUCCESS;
|
return LIBX52IO_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,134 @@
|
||||||
|
/*
|
||||||
|
* Saitek X52 IO driver - string representations
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012-2020 Nirenjan Krishnan (nirenjan@nirenjan.org)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "libx52io.h"
|
||||||
|
#include "gettext.h"
|
||||||
|
|
||||||
|
/* The strings corresponding to the axis and button enumerations are
|
||||||
|
* deliberately left untranslated, as they essentially correspond one
|
||||||
|
* on one to the enumeration definitions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* String mapping for axis */
|
||||||
|
static const char * _x52io_axis_str[LIBX52IO_AXIS_MAX] = {
|
||||||
|
[LIBX52IO_AXIS_X] = "ABS_X",
|
||||||
|
[LIBX52IO_AXIS_Y] = "ABS_Y",
|
||||||
|
[LIBX52IO_AXIS_RZ] = "ABS_RZ",
|
||||||
|
[LIBX52IO_AXIS_Z] = "ABS_Z",
|
||||||
|
[LIBX52IO_AXIS_RX] = "ABS_RX",
|
||||||
|
[LIBX52IO_AXIS_RY] = "ABS_RY",
|
||||||
|
[LIBX52IO_AXIS_SLIDER] = "ABS_SLIDER",
|
||||||
|
[LIBX52IO_AXIS_THUMBX] = "ABS_THUMBX",
|
||||||
|
[LIBX52IO_AXIS_THUMBY] = "ABS_THUMBY",
|
||||||
|
[LIBX52IO_AXIS_HATX] = "ABS_HATX",
|
||||||
|
[LIBX52IO_AXIS_HATY] = "ABS_HATY",
|
||||||
|
};
|
||||||
|
|
||||||
|
const char * libx52io_axis_to_str(libx52io_axis axis)
|
||||||
|
{
|
||||||
|
if (axis >= LIBX52IO_AXIS_X && axis < LIBX52IO_AXIS_MAX) {
|
||||||
|
return _x52io_axis_str[axis];
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* String mapping for button */
|
||||||
|
static const char * _x52io_button_str[LIBX52IO_BUTTON_MAX] = {
|
||||||
|
[LIBX52IO_BTN_TRIGGER] = "BTN_TRIGGER",
|
||||||
|
[LIBX52IO_BTN_TRIGGER_2] = "BTN_TRIGGER_2",
|
||||||
|
[LIBX52IO_BTN_FIRE] = "BTN_FIRE",
|
||||||
|
[LIBX52IO_BTN_PINKY] = "BTN_PINKY",
|
||||||
|
[LIBX52IO_BTN_A] = "BTN_A",
|
||||||
|
[LIBX52IO_BTN_B] = "BTN_B",
|
||||||
|
[LIBX52IO_BTN_C] = "BTN_C",
|
||||||
|
[LIBX52IO_BTN_D] = "BTN_D",
|
||||||
|
[LIBX52IO_BTN_E] = "BTN_E",
|
||||||
|
[LIBX52IO_BTN_T1_UP] = "BTN_T1_UP",
|
||||||
|
[LIBX52IO_BTN_T1_DN] = "BTN_T1_DN",
|
||||||
|
[LIBX52IO_BTN_T2_UP] = "BTN_T2_UP",
|
||||||
|
[LIBX52IO_BTN_T2_DN] = "BTN_T2_DN",
|
||||||
|
[LIBX52IO_BTN_T3_UP] = "BTN_T3_UP",
|
||||||
|
[LIBX52IO_BTN_T3_DN] = "BTN_T3_DN",
|
||||||
|
[LIBX52IO_BTN_POV_1_N] = "BTN_POV_1_N",
|
||||||
|
[LIBX52IO_BTN_POV_1_E] = "BTN_POV_1_E",
|
||||||
|
[LIBX52IO_BTN_POV_1_S] = "BTN_POV_1_S",
|
||||||
|
[LIBX52IO_BTN_POV_1_W] = "BTN_POV_1_W",
|
||||||
|
[LIBX52IO_BTN_POV_2_N] = "BTN_POV_2_N",
|
||||||
|
[LIBX52IO_BTN_POV_2_E] = "BTN_POV_2_E",
|
||||||
|
[LIBX52IO_BTN_POV_2_S] = "BTN_POV_2_S",
|
||||||
|
[LIBX52IO_BTN_POV_2_W] = "BTN_POV_2_W",
|
||||||
|
[LIBX52IO_BTN_CLUTCH] = "BTN_CLUTCH",
|
||||||
|
[LIBX52IO_BTN_MOUSE_PRIMARY] = "BTN_MOUSE_PRIMARY",
|
||||||
|
[LIBX52IO_BTN_MOUSE_SECONDARY] = "BTN_MOUSE_SECONDARY",
|
||||||
|
[LIBX52IO_BTN_MOUSE_SCROLL_UP] = "BTN_MOUSE_SCROLL_UP",
|
||||||
|
[LIBX52IO_BTN_MOUSE_SCROLL_DN] = "BTN_MOUSE_SCROLL_DN",
|
||||||
|
[LIBX52IO_BTN_FUNCTION] = "BTN_FUNCTION",
|
||||||
|
[LIBX52IO_BTN_START_STOP] = "BTN_START_STOP",
|
||||||
|
[LIBX52IO_BTN_RESET] = "BTN_RESET",
|
||||||
|
[LIBX52IO_BTN_PG_UP] = "BTN_PG_UP",
|
||||||
|
[LIBX52IO_BTN_PG_DN] = "BTN_PG_DN",
|
||||||
|
[LIBX52IO_BTN_UP] = "BTN_UP",
|
||||||
|
[LIBX52IO_BTN_DN] = "BTN_DN",
|
||||||
|
[LIBX52IO_BTN_SELECT] = "BTN_SELECT",
|
||||||
|
[LIBX52IO_BTN_MODE_1] = "BTN_MODE_1",
|
||||||
|
[LIBX52IO_BTN_MODE_2] = "BTN_MODE_2",
|
||||||
|
[LIBX52IO_BTN_MODE_3] = "BTN_MODE_3",
|
||||||
|
};
|
||||||
|
|
||||||
|
const char * libx52io_button_to_str(libx52io_button button)
|
||||||
|
{
|
||||||
|
if (button >= LIBX52IO_BTN_TRIGGER && button < LIBX52IO_BUTTON_MAX) {
|
||||||
|
return _x52io_button_str[button];
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Error buffer used for building custom error strings */
|
||||||
|
static char error_buffer[256];
|
||||||
|
|
||||||
|
#define _(str) dgettext(PACKAGE, str)
|
||||||
|
|
||||||
|
const char * libx52io_strerror(libx52io_error_code code)
|
||||||
|
{
|
||||||
|
switch (code) {
|
||||||
|
case LIBX52IO_SUCCESS:
|
||||||
|
return _("Success");
|
||||||
|
|
||||||
|
case LIBX52IO_ERROR_INIT_FAILURE:
|
||||||
|
return _("Initialization failure");
|
||||||
|
|
||||||
|
case LIBX52IO_ERROR_NO_DEVICE:
|
||||||
|
return _("No device");
|
||||||
|
|
||||||
|
case LIBX52IO_ERROR_INVALID:
|
||||||
|
return _("Invalid arguments");
|
||||||
|
|
||||||
|
case LIBX52IO_ERROR_CONN:
|
||||||
|
return _("Connection failure");
|
||||||
|
|
||||||
|
case LIBX52IO_ERROR_IO:
|
||||||
|
return _("I/O error");
|
||||||
|
|
||||||
|
case LIBX52IO_ERROR_TIMEOUT:
|
||||||
|
return _("Read timeout");
|
||||||
|
|
||||||
|
default:
|
||||||
|
snprintf(error_buffer, sizeof(error_buffer), _("Unknown error %d"), code);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)_x52io_axis_str;
|
||||||
|
(void)_x52io_button_str;
|
||||||
|
|
||||||
|
return error_buffer;
|
||||||
|
}
|
||||||
|
|
|
@ -395,6 +395,36 @@ int libx52io_read(libx52io_context *ctx, libx52io_report *report);
|
||||||
* - \ref LIBX52IO_ERROR_NO_DEVICE if the device is disconnected
|
* - \ref LIBX52IO_ERROR_NO_DEVICE if the device is disconnected
|
||||||
*/
|
*/
|
||||||
int libx52io_get_axis_range(libx52io_context *ctx, libx52io_axis axis, int32_t *min, int32_t *max);
|
int libx52io_get_axis_range(libx52io_context *ctx, libx52io_axis axis, int32_t *min, int32_t *max);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the string representation of an error code
|
||||||
|
*
|
||||||
|
* @param[in] code Return code from one of the libx52io APIs
|
||||||
|
*
|
||||||
|
* @returns String representation of the error. This pointer must not be freed.
|
||||||
|
*/
|
||||||
|
const char * libx52io_strerror(libx52io_error_code code);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the string representation of an axis.
|
||||||
|
*
|
||||||
|
* @param[in] axis Axis ID - see \ref libx52io_axis
|
||||||
|
*
|
||||||
|
* @returns String representation of the axis. This pointer must not be freed.
|
||||||
|
* If axis is outside the defined range, then this returns NULL.
|
||||||
|
*/
|
||||||
|
const char * libx52io_axis_to_str(libx52io_axis axis);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the string representation of a button.
|
||||||
|
*
|
||||||
|
* @param[in] button Button ID - see \ref libx52io_button
|
||||||
|
*
|
||||||
|
* @returns String representation of the button. This pointer must not be freed.
|
||||||
|
* If button is outside the defined range, then this returns NULL.
|
||||||
|
*/
|
||||||
|
const char * libx52io_button_to_str(libx52io_button button);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# List of source files which contain translatable strings.
|
# List of source files which contain translatable strings.
|
||||||
lib/libx52/x52_strerror.c
|
lib/libx52/x52_strerror.c
|
||||||
|
|
||||||
|
lib/libx52io/io_strings.c
|
||||||
|
|
||||||
utils/test/x52_test.c
|
utils/test/x52_test.c
|
||||||
utils/test/x52_test_clock.c
|
utils/test/x52_test_clock.c
|
||||||
utils/test/x52_test_common.h
|
utils/test/x52_test_common.h
|
||||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: x52pro-linux 0.2.1\n"
|
"Project-Id-Version: x52pro-linux 0.2.1\n"
|
||||||
"Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n"
|
"Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n"
|
||||||
"POT-Creation-Date: 2020-06-12 23:15-0700\n"
|
"POT-Creation-Date: 2020-07-10 17:55-0700\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
@ -17,11 +17,11 @@ msgstr ""
|
||||||
"Content-Type: text/plain; charset=CHARSET\n"
|
"Content-Type: text/plain; charset=CHARSET\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
|
||||||
#: lib/libx52/x52_strerror.c:25
|
#: lib/libx52/x52_strerror.c:25 lib/libx52io/io_strings.c:104
|
||||||
msgid "Success"
|
msgid "Success"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/libx52/x52_strerror.c:28
|
#: lib/libx52/x52_strerror.c:28 lib/libx52io/io_strings.c:107
|
||||||
msgid "Initialization failure"
|
msgid "Initialization failure"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -85,11 +85,31 @@ msgstr ""
|
||||||
msgid "System call interrupted"
|
msgid "System call interrupted"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/libx52/x52_strerror.c:77
|
#: lib/libx52/x52_strerror.c:77 lib/libx52io/io_strings.c:125
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Unknown error %d"
|
msgid "Unknown error %d"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/libx52io/io_strings.c:110
|
||||||
|
msgid "No device"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/libx52io/io_strings.c:113
|
||||||
|
msgid "Invalid arguments"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/libx52io/io_strings.c:116
|
||||||
|
msgid "Connection failure"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/libx52io/io_strings.c:119
|
||||||
|
msgid "I/O error"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/libx52io/io_strings.c:122
|
||||||
|
msgid "Read timeout"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: utils/test/x52_test.c:97
|
#: utils/test/x52_test.c:97
|
||||||
msgid "Test brightness scale (~ 1m)"
|
msgid "Test brightness scale (~ 1m)"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
30
po/xx_PL.po
30
po/xx_PL.po
|
@ -7,8 +7,8 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: x52pro-linux 0.2.1\n"
|
"Project-Id-Version: x52pro-linux 0.2.1\n"
|
||||||
"Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n"
|
"Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n"
|
||||||
"POT-Creation-Date: 2020-06-12 23:15-0700\n"
|
"POT-Creation-Date: 2020-07-10 17:55-0700\n"
|
||||||
"PO-Revision-Date: 2020-05-22 13:25-0700\n"
|
"PO-Revision-Date: 2020-07-10 15:04-0700\n"
|
||||||
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
|
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
|
||||||
"Language-Team: Dummy Language for testing i18n\n"
|
"Language-Team: Dummy Language for testing i18n\n"
|
||||||
"Language: xx_PL\n"
|
"Language: xx_PL\n"
|
||||||
|
@ -17,11 +17,11 @@ msgstr ""
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
"X-Generator: Poedit 2.3.1\n"
|
"X-Generator: Poedit 2.3.1\n"
|
||||||
|
|
||||||
#: lib/libx52/x52_strerror.c:25
|
#: lib/libx52/x52_strerror.c:25 lib/libx52io/io_strings.c:104
|
||||||
msgid "Success"
|
msgid "Success"
|
||||||
msgstr "Uccesssay"
|
msgstr "Uccesssay"
|
||||||
|
|
||||||
#: lib/libx52/x52_strerror.c:28
|
#: lib/libx52/x52_strerror.c:28 lib/libx52io/io_strings.c:107
|
||||||
msgid "Initialization failure"
|
msgid "Initialization failure"
|
||||||
msgstr "Initializationay ailurefay"
|
msgstr "Initializationay ailurefay"
|
||||||
|
|
||||||
|
@ -85,11 +85,31 @@ msgstr "Ipepay erroray"
|
||||||
msgid "System call interrupted"
|
msgid "System call interrupted"
|
||||||
msgstr "Ystemsay allcay interrupteday"
|
msgstr "Ystemsay allcay interrupteday"
|
||||||
|
|
||||||
#: lib/libx52/x52_strerror.c:77
|
#: lib/libx52/x52_strerror.c:77 lib/libx52io/io_strings.c:125
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Unknown error %d"
|
msgid "Unknown error %d"
|
||||||
msgstr "Unknownay erroray %d"
|
msgstr "Unknownay erroray %d"
|
||||||
|
|
||||||
|
#: lib/libx52io/io_strings.c:110
|
||||||
|
msgid "No device"
|
||||||
|
msgstr "Onay eviceday"
|
||||||
|
|
||||||
|
#: lib/libx52io/io_strings.c:113
|
||||||
|
msgid "Invalid arguments"
|
||||||
|
msgstr "Invaliday argumentsay"
|
||||||
|
|
||||||
|
#: lib/libx52io/io_strings.c:116
|
||||||
|
msgid "Connection failure"
|
||||||
|
msgstr "Onnectioncay ailurefay"
|
||||||
|
|
||||||
|
#: lib/libx52io/io_strings.c:119
|
||||||
|
msgid "I/O error"
|
||||||
|
msgstr "I/O erroray"
|
||||||
|
|
||||||
|
#: lib/libx52io/io_strings.c:122
|
||||||
|
msgid "Read timeout"
|
||||||
|
msgstr "Eadray imeouttay"
|
||||||
|
|
||||||
#: utils/test/x52_test.c:97
|
#: utils/test/x52_test.c:97
|
||||||
msgid "Test brightness scale (~ 1m)"
|
msgid "Test brightness scale (~ 1m)"
|
||||||
msgstr "Esttay ightnessbray alescay (~ 1m)"
|
msgstr "Esttay ightnessbray alescay (~ 1m)"
|
||||||
|
|
Loading…
Reference in New Issue