Add i18n support for some more user-visible strings

This commit is contained in:
Wim Taymans 2021-04-15 17:42:02 +02:00
parent c90332a6bf
commit 036c54b043
5 changed files with 39 additions and 33 deletions

View file

@ -37,6 +37,7 @@
#include <spa/node/node.h> #include <spa/node/node.h>
#include <spa/support/loop.h> #include <spa/support/loop.h>
#include <spa/support/plugin.h> #include <spa/support/plugin.h>
#include <spa/support/i18n.h>
#include <spa/monitor/device.h> #include <spa/monitor/device.h>
#include <spa/monitor/utils.h> #include <spa/monitor/utils.h>
#include <spa/monitor/event.h> #include <spa/monitor/event.h>
@ -59,6 +60,11 @@
#define DEVICE_ID_SINK 1 #define DEVICE_ID_SINK 1
#define DYNAMIC_NODE_ID_FLAG 0x1000 #define DYNAMIC_NODE_ID_FLAG 0x1000
static struct spa_i18n *_i18n;
#define _(_str) spa_i18n_text(_i18n,(_str))
#define N_(_str) (_str)
enum { enum {
DEVICE_PROFILE_OFF = 0, DEVICE_PROFILE_OFF = 0,
DEVICE_PROFILE_AG = 1, DEVICE_PROFILE_AG = 1,
@ -836,7 +842,7 @@ static struct spa_pod *build_profile(struct impl *this, struct spa_pod_builder *
switch (profile_index) { switch (profile_index) {
case DEVICE_PROFILE_OFF: case DEVICE_PROFILE_OFF:
name = "off"; name = "off";
desc = "Off"; desc = _("Off");
break; break;
case DEVICE_PROFILE_AG: case DEVICE_PROFILE_AG:
{ {
@ -846,7 +852,7 @@ static struct spa_pod *build_profile(struct impl *this, struct spa_pod_builder *
return NULL; return NULL;
} else { } else {
name = "audio-gateway"; name = "audio-gateway";
desc = "Audio Gateway (A2DP Source & HSP/HFP AG)"; desc = _("Audio Gateway (A2DP Source & HSP/HFP AG)");
} }
break; break;
} }
@ -858,9 +864,9 @@ static struct spa_pod *build_profile(struct impl *this, struct spa_pod_builder *
if (!(profile & SPA_BT_PROFILE_A2DP_SINK)) { if (!(profile & SPA_BT_PROFILE_A2DP_SINK)) {
return NULL; return NULL;
} else if (profile == SPA_BT_PROFILE_A2DP_SINK) { } else if (profile == SPA_BT_PROFILE_A2DP_SINK) {
desc = "High Fidelity Playback (A2DP Sink%s%s)"; desc = _("High Fidelity Playback (A2DP Sink%s%s)");
} else { } else {
desc = "High Fidelity Duplex (A2DP Source/Sink%s%s)"; desc = _("High Fidelity Duplex (A2DP Source/Sink%s%s)");
} }
name = spa_bt_profile_name(profile); name = spa_bt_profile_name(profile);
n_sink++; n_sink++;
@ -888,7 +894,7 @@ static struct spa_pod *build_profile(struct impl *this, struct spa_pod_builder *
if (profile == 0) { if (profile == 0) {
return NULL; return NULL;
} else { } else {
desc = "Headset Head Unit (HSP/HFP%s%s)"; desc = _("Headset Head Unit (HSP/HFP%s%s)");
} }
name = spa_bt_profile_name(profile); name = spa_bt_profile_name(profile);
n_source++; n_source++;
@ -967,53 +973,53 @@ static struct spa_pod *build_route(struct impl *this, struct spa_pod_builder *b,
switch (ff) { switch (ff) {
case SPA_BT_FORM_FACTOR_HEADSET: case SPA_BT_FORM_FACTOR_HEADSET:
name_prefix = "headset"; name_prefix = "headset";
description = "Headset"; description = _("Headset");
port_type = "headset"; port_type = "headset";
break; break;
case SPA_BT_FORM_FACTOR_HANDSFREE: case SPA_BT_FORM_FACTOR_HANDSFREE:
name_prefix = "handsfree"; name_prefix = "handsfree";
description = "Handsfree"; description = _("Handsfree");
port_type = "handsfree"; port_type = "handsfree";
break; break;
case SPA_BT_FORM_FACTOR_MICROPHONE: case SPA_BT_FORM_FACTOR_MICROPHONE:
name_prefix = "microphone"; name_prefix = "microphone";
description = "Microphone"; description = _("Microphone");
port_type = "mic"; port_type = "mic";
break; break;
case SPA_BT_FORM_FACTOR_SPEAKER: case SPA_BT_FORM_FACTOR_SPEAKER:
name_prefix = "speaker"; name_prefix = "speaker";
description = "Speaker"; description = _("Speaker");
port_type = "speaker"; port_type = "speaker";
break; break;
case SPA_BT_FORM_FACTOR_HEADPHONE: case SPA_BT_FORM_FACTOR_HEADPHONE:
name_prefix = "headphone"; name_prefix = "headphone";
description = "Headphone"; description = _("Headphone");
port_type = "headphones"; port_type = "headphones";
break; break;
case SPA_BT_FORM_FACTOR_PORTABLE: case SPA_BT_FORM_FACTOR_PORTABLE:
name_prefix = "portable"; name_prefix = "portable";
description = "Portable"; description = _("Portable");
port_type = "portable"; port_type = "portable";
break; break;
case SPA_BT_FORM_FACTOR_CAR: case SPA_BT_FORM_FACTOR_CAR:
name_prefix = "car"; name_prefix = "car";
description = "Car"; description = _("Car");
port_type = "car"; port_type = "car";
break; break;
case SPA_BT_FORM_FACTOR_HIFI: case SPA_BT_FORM_FACTOR_HIFI:
name_prefix = "hifi"; name_prefix = "hifi";
description = "HiFi"; description = _("HiFi");
port_type = "hifi"; port_type = "hifi";
break; break;
case SPA_BT_FORM_FACTOR_PHONE: case SPA_BT_FORM_FACTOR_PHONE:
name_prefix = "phone"; name_prefix = "phone";
description = "Phone"; description = _("Phone");
port_type = "phone"; port_type = "phone";
break; break;
case SPA_BT_FORM_FACTOR_UNKNOWN: case SPA_BT_FORM_FACTOR_UNKNOWN:
default: default:
name_prefix = "bluetooth"; name_prefix = "bluetooth";
description = "Bluetooth"; description = _("Bluetooth");
port_type = "bluetooth"; port_type = "bluetooth";
break; break;
} }
@ -1683,6 +1689,7 @@ impl_init(const struct spa_handle_factory *factory,
this = (struct impl *) handle; this = (struct impl *) handle;
this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log);
_i18n = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_I18N);
if (info && (str = spa_dict_lookup(info, SPA_KEY_API_BLUEZ5_DEVICE))) if (info && (str = spa_dict_lookup(info, SPA_KEY_API_BLUEZ5_DEVICE)))
sscanf(str, "pointer:%p", &this->bt_dev); sscanf(str, "pointer:%p", &this->bt_dev);

View file

@ -40,10 +40,10 @@ static void do_quit(void *data, int signal_number)
static void show_help(const char *name, const char *config_name) static void show_help(const char *name, const char *config_name)
{ {
fprintf(stdout, "%s [options]\n" fprintf(stdout, _("%s [options]\n"
" -h, --help Show this help\n" " -h, --help Show this help\n"
" --version Show version\n" " --version Show version\n"
" -c, --config Load config (Default %s)\n", " -c, --config Load config (Default %s)\n"),
name, name,
config_name); config_name);
} }

View file

@ -523,11 +523,11 @@ static int update_device_props(struct device *device)
if ((s = pw_properties_get(p, PW_KEY_DEVICE_FORM_FACTOR))) if ((s = pw_properties_get(p, PW_KEY_DEVICE_FORM_FACTOR)))
if (strcmp(s, "internal") == 0) if (strcmp(s, "internal") == 0)
d = "Built-in Audio"; d = _("Built-in Audio");
if (!d) if (!d)
if ((s = pw_properties_get(p, PW_KEY_DEVICE_CLASS))) if ((s = pw_properties_get(p, PW_KEY_DEVICE_CLASS)))
if (strcmp(s, "modem") == 0) if (strcmp(s, "modem") == 0)
d = "Modem"; d = _("Modem");
if (!d) if (!d)
d = pw_properties_get(p, PW_KEY_DEVICE_PRODUCT_NAME); d = pw_properties_get(p, PW_KEY_DEVICE_PRODUCT_NAME);
@ -536,7 +536,7 @@ static int update_device_props(struct device *device)
if (!d) if (!d)
d = pw_properties_get(p, "alsa.card_name"); d = pw_properties_get(p, "alsa.card_name");
if (!d) if (!d)
d = "Unknown device"; d = _("Unknown device");
pw_properties_set(p, PW_KEY_DEVICE_DESCRIPTION, d); pw_properties_set(p, PW_KEY_DEVICE_DESCRIPTION, d);
} }

View file

@ -987,16 +987,15 @@ static void show_usage(const char *name, bool is_error)
fp = is_error ? stderr : stdout; fp = is_error ? stderr : stdout;
fprintf(fp, "%s [options] <file>\n", name); fprintf(fp,
_("%s [options] <file>\n"
fprintf(fp,
" -h, --help Show this help\n" " -h, --help Show this help\n"
" --version Show version\n" " --version Show version\n"
" -v, --verbose Enable verbose operations\n" " -v, --verbose Enable verbose operations\n"
"\n"); "\n"), name);
fprintf(fp, fprintf(fp,
" -R, --remote Remote daemon name\n" _(" -R, --remote Remote daemon name\n"
" --media-type Set media type (default %s)\n" " --media-type Set media type (default %s)\n"
" --media-category Set media category (default %s)\n" " --media-category Set media category (default %s)\n"
" --media-role Set media role (default %s)\n" " --media-role Set media role (default %s)\n"
@ -1007,14 +1006,14 @@ static void show_usage(const char *name, bool is_error)
" or direct samples (256)\n" " or direct samples (256)\n"
" the rate is the one of the source file\n" " the rate is the one of the source file\n"
" --list-targets List available targets for --target\n" " --list-targets List available targets for --target\n"
"\n", "\n"),
DEFAULT_MEDIA_TYPE, DEFAULT_MEDIA_TYPE,
DEFAULT_MEDIA_CATEGORY_PLAYBACK, DEFAULT_MEDIA_CATEGORY_PLAYBACK,
DEFAULT_MEDIA_ROLE, DEFAULT_MEDIA_ROLE,
DEFAULT_TARGET, DEFAULT_LATENCY_PLAY); DEFAULT_TARGET, DEFAULT_LATENCY_PLAY);
fprintf(fp, fprintf(fp,
" --rate Sample rate (req. for rec) (default %u)\n" _(" --rate Sample rate (req. for rec) (default %u)\n"
" --channels Number of channels (req. for rec) (default %u)\n" " --channels Number of channels (req. for rec) (default %u)\n"
" --channel-map Channel map\n" " --channel-map Channel map\n"
" one of: \"stereo\", \"surround-51\",... or\n" " one of: \"stereo\", \"surround-51\",... or\n"
@ -1022,7 +1021,7 @@ static void show_usage(const char *name, bool is_error)
" --format Sample format %s (req. for rec) (default %s)\n" " --format Sample format %s (req. for rec) (default %s)\n"
" --volume Stream volume 0-1.0 (default %.3f)\n" " --volume Stream volume 0-1.0 (default %.3f)\n"
" -q --quality Resampler quality (0 - 15) (default %d)\n" " -q --quality Resampler quality (0 - 15) (default %d)\n"
"\n", "\n"),
DEFAULT_RATE, DEFAULT_RATE,
DEFAULT_CHANNELS, DEFAULT_CHANNELS,
STR_FMTS, DEFAULT_FORMAT, STR_FMTS, DEFAULT_FORMAT,
@ -1030,11 +1029,11 @@ static void show_usage(const char *name, bool is_error)
DEFAULT_QUALITY); DEFAULT_QUALITY);
if (!strcmp(name, "pw-cat")) { if (!strcmp(name, "pw-cat")) {
fprintf(fp, fputs(
" -p, --playback Playback mode\n" _(" -p, --playback Playback mode\n"
" -r, --record Recording mode\n" " -r, --record Recording mode\n"
" -m, --midi Midi mode\n" " -m, --midi Midi mode\n"
"\n"); "\n"), fp);
} }
} }

View file

@ -2929,11 +2929,11 @@ static void do_quit(void *data, int signal_number)
static void show_help(struct data *data, const char *name) static void show_help(struct data *data, const char *name)
{ {
fprintf(stdout, "%s [options] [command]\n" fprintf(stdout, _("%s [options] [command]\n"
" -h, --help Show this help\n" " -h, --help Show this help\n"
" --version Show version\n" " --version Show version\n"
" -d, --daemon Start as daemon (Default false)\n" " -d, --daemon Start as daemon (Default false)\n"
" -r, --remote Remote daemon name\n\n", " -r, --remote Remote daemon name\n\n"),
name); name);
do_help(data, "help", "", NULL); do_help(data, "help", "", NULL);