add i18n support

This commit is contained in:
Lennart Poettering 2008-08-06 18:54:13 +02:00
parent c4a953dc96
commit f1d2bf8408
35 changed files with 816 additions and 414 deletions

View file

@ -29,6 +29,7 @@
#include <string.h>
#include <pulse/xmalloc.h>
#include <pulse/i18n.h>
#include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
@ -98,66 +99,66 @@ const char *const table[PA_CHANNEL_POSITION_MAX] = {
};
const char *const pretty_table[PA_CHANNEL_POSITION_MAX] = {
[PA_CHANNEL_POSITION_MONO] = "Mono",
[PA_CHANNEL_POSITION_MONO] = N_("Mono"),
[PA_CHANNEL_POSITION_FRONT_CENTER] = "Front Center",
[PA_CHANNEL_POSITION_FRONT_LEFT] = "Front Left",
[PA_CHANNEL_POSITION_FRONT_RIGHT] = "Front Right",
[PA_CHANNEL_POSITION_FRONT_CENTER] = N_("Front Center"),
[PA_CHANNEL_POSITION_FRONT_LEFT] = N_("Front Left"),
[PA_CHANNEL_POSITION_FRONT_RIGHT] = N_("Front Right"),
[PA_CHANNEL_POSITION_REAR_CENTER] = "Rear Center",
[PA_CHANNEL_POSITION_REAR_LEFT] = "Rear Left",
[PA_CHANNEL_POSITION_REAR_RIGHT] = "Rear Right",
[PA_CHANNEL_POSITION_REAR_CENTER] = N_("Rear Center"),
[PA_CHANNEL_POSITION_REAR_LEFT] = N_("Rear Left"),
[PA_CHANNEL_POSITION_REAR_RIGHT] = N_("Rear Right"),
[PA_CHANNEL_POSITION_LFE] = "Low Frequency Emmiter",
[PA_CHANNEL_POSITION_LFE] = N_("Low Frequency Emmiter"),
[PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER] = "Front Left-of-center",
[PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER] = "Front Right-of-center",
[PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER] = N_("Front Left-of-center"),
[PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER] = N_("Front Right-of-center"),
[PA_CHANNEL_POSITION_SIDE_LEFT] = "Side Left",
[PA_CHANNEL_POSITION_SIDE_RIGHT] = "Side Right",
[PA_CHANNEL_POSITION_SIDE_LEFT] = N_("Side Left"),
[PA_CHANNEL_POSITION_SIDE_RIGHT] = N_("Side Right"),
[PA_CHANNEL_POSITION_AUX0] = "Auxiliary 0",
[PA_CHANNEL_POSITION_AUX1] = "Auxiliary 1",
[PA_CHANNEL_POSITION_AUX2] = "Auxiliary 2",
[PA_CHANNEL_POSITION_AUX3] = "Auxiliary 3",
[PA_CHANNEL_POSITION_AUX4] = "Auxiliary 4",
[PA_CHANNEL_POSITION_AUX5] = "Auxiliary 5",
[PA_CHANNEL_POSITION_AUX6] = "Auxiliary 6",
[PA_CHANNEL_POSITION_AUX7] = "Auxiliary 7",
[PA_CHANNEL_POSITION_AUX8] = "Auxiliary 8",
[PA_CHANNEL_POSITION_AUX9] = "Auxiliary 9",
[PA_CHANNEL_POSITION_AUX10] = "Auxiliary 10",
[PA_CHANNEL_POSITION_AUX11] = "Auxiliary 11",
[PA_CHANNEL_POSITION_AUX12] = "Auxiliary 12",
[PA_CHANNEL_POSITION_AUX13] = "Auxiliary 13",
[PA_CHANNEL_POSITION_AUX14] = "Auxiliary 14",
[PA_CHANNEL_POSITION_AUX15] = "Auxiliary 15",
[PA_CHANNEL_POSITION_AUX16] = "Auxiliary 16",
[PA_CHANNEL_POSITION_AUX17] = "Auxiliary 17",
[PA_CHANNEL_POSITION_AUX18] = "Auxiliary 18",
[PA_CHANNEL_POSITION_AUX19] = "Auxiliary 19",
[PA_CHANNEL_POSITION_AUX20] = "Auxiliary 20",
[PA_CHANNEL_POSITION_AUX21] = "Auxiliary 21",
[PA_CHANNEL_POSITION_AUX22] = "Auxiliary 22",
[PA_CHANNEL_POSITION_AUX23] = "Auxiliary 23",
[PA_CHANNEL_POSITION_AUX24] = "Auxiliary 24",
[PA_CHANNEL_POSITION_AUX25] = "Auxiliary 25",
[PA_CHANNEL_POSITION_AUX26] = "Auxiliary 26",
[PA_CHANNEL_POSITION_AUX27] = "Auxiliary 27",
[PA_CHANNEL_POSITION_AUX28] = "Auxiliary 28",
[PA_CHANNEL_POSITION_AUX29] = "Auxiliary 29",
[PA_CHANNEL_POSITION_AUX30] = "Auxiliary 30",
[PA_CHANNEL_POSITION_AUX31] = "Auxiliary 31",
[PA_CHANNEL_POSITION_AUX0] = N_("Auxiliary 0"),
[PA_CHANNEL_POSITION_AUX1] = N_("Auxiliary 1"),
[PA_CHANNEL_POSITION_AUX2] = N_("Auxiliary 2"),
[PA_CHANNEL_POSITION_AUX3] = N_("Auxiliary 3"),
[PA_CHANNEL_POSITION_AUX4] = N_("Auxiliary 4"),
[PA_CHANNEL_POSITION_AUX5] = N_("Auxiliary 5"),
[PA_CHANNEL_POSITION_AUX6] = N_("Auxiliary 6"),
[PA_CHANNEL_POSITION_AUX7] = N_("Auxiliary 7"),
[PA_CHANNEL_POSITION_AUX8] = N_("Auxiliary 8"),
[PA_CHANNEL_POSITION_AUX9] = N_("Auxiliary 9"),
[PA_CHANNEL_POSITION_AUX10] = N_("Auxiliary 10"),
[PA_CHANNEL_POSITION_AUX11] = N_("Auxiliary 11"),
[PA_CHANNEL_POSITION_AUX12] = N_("Auxiliary 12"),
[PA_CHANNEL_POSITION_AUX13] = N_("Auxiliary 13"),
[PA_CHANNEL_POSITION_AUX14] = N_("Auxiliary 14"),
[PA_CHANNEL_POSITION_AUX15] = N_("Auxiliary 15"),
[PA_CHANNEL_POSITION_AUX16] = N_("Auxiliary 16"),
[PA_CHANNEL_POSITION_AUX17] = N_("Auxiliary 17"),
[PA_CHANNEL_POSITION_AUX18] = N_("Auxiliary 18"),
[PA_CHANNEL_POSITION_AUX19] = N_("Auxiliary 19"),
[PA_CHANNEL_POSITION_AUX20] = N_("Auxiliary 20"),
[PA_CHANNEL_POSITION_AUX21] = N_("Auxiliary 21"),
[PA_CHANNEL_POSITION_AUX22] = N_("Auxiliary 22"),
[PA_CHANNEL_POSITION_AUX23] = N_("Auxiliary 23"),
[PA_CHANNEL_POSITION_AUX24] = N_("Auxiliary 24"),
[PA_CHANNEL_POSITION_AUX25] = N_("Auxiliary 25"),
[PA_CHANNEL_POSITION_AUX26] = N_("Auxiliary 26"),
[PA_CHANNEL_POSITION_AUX27] = N_("Auxiliary 27"),
[PA_CHANNEL_POSITION_AUX28] = N_("Auxiliary 28"),
[PA_CHANNEL_POSITION_AUX29] = N_("Auxiliary 29"),
[PA_CHANNEL_POSITION_AUX30] = N_("Auxiliary 30"),
[PA_CHANNEL_POSITION_AUX31] = N_("Auxiliary 31"),
[PA_CHANNEL_POSITION_TOP_CENTER] = "Top Center",
[PA_CHANNEL_POSITION_TOP_CENTER] = N_("Top Center"),
[PA_CHANNEL_POSITION_TOP_FRONT_CENTER] = "Top Front Center",
[PA_CHANNEL_POSITION_TOP_FRONT_LEFT] = "Top Front Left",
[PA_CHANNEL_POSITION_TOP_FRONT_RIGHT] = "Top Front Right",
[PA_CHANNEL_POSITION_TOP_FRONT_CENTER] = N_("Top Front Center"),
[PA_CHANNEL_POSITION_TOP_FRONT_LEFT] = N_("Top Front Left"),
[PA_CHANNEL_POSITION_TOP_FRONT_RIGHT] = N_("Top Front Right"),
[PA_CHANNEL_POSITION_TOP_REAR_CENTER] = "Top Rear Center",
[PA_CHANNEL_POSITION_TOP_REAR_LEFT] = "Top Rear left",
[PA_CHANNEL_POSITION_TOP_REAR_RIGHT] = "Top Rear Right"
[PA_CHANNEL_POSITION_TOP_REAR_CENTER] = N_("Top Rear Center"),
[PA_CHANNEL_POSITION_TOP_REAR_LEFT] = N_("Top Rear left"),
[PA_CHANNEL_POSITION_TOP_REAR_RIGHT] = N_("Top Rear Right")
};
pa_channel_map* pa_channel_map_init(pa_channel_map *m) {
@ -432,10 +433,13 @@ const char* pa_channel_position_to_string(pa_channel_position_t pos) {
}
const char* pa_channel_position_to_pretty_string(pa_channel_position_t pos) {
pa_init_i18n();
if (pos < 0 || pos >= PA_CHANNEL_POSITION_MAX)
return NULL;
return pretty_table[pos];
return _(pretty_table[pos]);
}
int pa_channel_map_equal(const pa_channel_map *a, const pa_channel_map *b) {
@ -552,7 +556,6 @@ int pa_channel_map_valid(const pa_channel_map *map) {
if (map->map[c] < 0 ||map->map[c] >= PA_CHANNEL_POSITION_MAX)
return 0;
}
return 1;

View file

@ -29,6 +29,7 @@
#include <X11/Xatom.h>
#include <pulse/xmalloc.h>
#include <pulse/i18n.h>
#include <pulsecore/x11prop.h>
#include <pulsecore/log.h>
@ -51,7 +52,7 @@ int pa_client_conf_from_x11(pa_client_conf *c, const char *dname) {
goto finish;
if (!(d = XOpenDisplay(dname))) {
pa_log("XOpenDisplay() failed");
pa_log(_("XOpenDisplay() failed"));
goto finish;
}
@ -74,7 +75,7 @@ int pa_client_conf_from_x11(pa_client_conf *c, const char *dname) {
uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
if (pa_parsehex(t, cookie, sizeof(cookie)) != sizeof(cookie)) {
pa_log("failed to parse cookie data");
pa_log(_("Failed to parse cookie data"));
goto finish;
}

View file

@ -30,6 +30,7 @@
#include <string.h>
#include <pulse/xmalloc.h>
#include <pulse/i18n.h>
#include <pulsecore/macro.h>
#include <pulsecore/core-error.h>
@ -113,7 +114,7 @@ int pa_client_conf_load(pa_client_conf *c, const char *filename) {
if (filename) {
if (!(f = fopen(filename, "r"))) {
pa_log("Failed to open configuration file '%s': %s", fn, pa_cstrerror(errno));
pa_log(_("Failed to open configuration file '%s': %s"), fn, pa_cstrerror(errno));
goto finish;
}

View file

@ -53,6 +53,7 @@
#include <pulse/xmalloc.h>
#include <pulse/utf8.h>
#include <pulse/util.h>
#include <pulse/i18n.h>
#include <pulsecore/winsock.h>
#include <pulsecore/core-error.h>
@ -106,7 +107,7 @@ static void unlock_autospawn_lock_file(pa_context *c) {
char *lf;
if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK)))
pa_log_warn("Cannot unlock autospawn because runtime path is no more.");
pa_log_warn(_("Cannot unlock autospawn because runtime path is no more."));
pa_unlock_lockfile(lf, c->autospawn_lock_fd);
pa_xfree(lf);
@ -139,6 +140,8 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
pa_assert(mainloop);
pa_init_i18n();
if (!name && !pa_proplist_contains(p, PA_PROP_APPLICATION_NAME))
return NULL;
@ -530,7 +533,7 @@ static void setup_context(pa_context *c, pa_iochannel *io) {
c->pdispatch = pa_pdispatch_new(c->mainloop, command_table, PA_COMMAND_MAX);
if (!c->conf->cookie_valid)
pa_log_info("No cookie loaded. Attempting to connect without.");
pa_log_info(_("No cookie loaded. Attempting to connect without."));
t = pa_tagstruct_command(c, PA_COMMAND_AUTH, &tag);
@ -584,7 +587,7 @@ static int context_connect_spawn(pa_context *c) {
pa_context_ref(c);
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
pa_log_error("socketpair(): %s", pa_cstrerror(errno));
pa_log_error(_("socketpair(): %s"), pa_cstrerror(errno));
pa_context_fail(c, PA_ERR_INTERNAL);
goto fail;
}
@ -598,7 +601,7 @@ static int context_connect_spawn(pa_context *c) {
c->spawn_api.prefork();
if ((pid = fork()) < 0) {
pa_log_error("fork(): %s", pa_cstrerror(errno));
pa_log_error(_("fork(): %s"), pa_cstrerror(errno));
pa_context_fail(c, PA_ERR_INTERNAL);
if (c->spawn_api.postfork)
@ -661,7 +664,7 @@ static int context_connect_spawn(pa_context *c) {
c->spawn_api.postfork();
if (r < 0) {
pa_log("waitpid(): %s", pa_cstrerror(errno));
pa_log(_("waitpid(): %s"), pa_cstrerror(errno));
pa_context_fail(c, PA_ERR_INTERNAL);
goto fail;
} else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
@ -1259,7 +1262,7 @@ void pa_command_extension(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_t
if (!strcmp(name, "module-stream-restore"))
pa_ext_stream_restore_command(c, tag, t);
else
pa_log("Received message for unknown extension '%s'", name);
pa_log(_("Received message for unknown extension '%s'"), name);
finish:
pa_context_unref(c);

View file

@ -30,6 +30,7 @@
#include <string.h>
#include <pulse/xmalloc.h>
#include <pulse/i18n.h>
#include <pulsecore/core-util.h>
#include <pulsecore/native-common.h>
@ -39,32 +40,34 @@
const char*pa_strerror(int error) {
static const char* const errortab[PA_ERR_MAX] = {
[PA_OK] = "OK",
[PA_ERR_ACCESS] = "Access denied",
[PA_ERR_COMMAND] = "Unknown command",
[PA_ERR_INVALID] = "Invalid argument",
[PA_ERR_EXIST] = "Entity exists",
[PA_ERR_NOENTITY] = "No such entity",
[PA_ERR_CONNECTIONREFUSED] = "Connection refused",
[PA_ERR_PROTOCOL] = "Protocol error",
[PA_ERR_TIMEOUT] = "Timeout",
[PA_ERR_AUTHKEY] = "No authorization key",
[PA_ERR_INTERNAL] = "Internal error",
[PA_ERR_CONNECTIONTERMINATED] = "Connection terminated",
[PA_ERR_KILLED] = "Entity killed",
[PA_ERR_INVALIDSERVER] = "Invalid server",
[PA_ERR_MODINITFAILED] = "Module initalization failed",
[PA_ERR_BADSTATE] = "Bad state",
[PA_ERR_NODATA] = "No data",
[PA_ERR_VERSION] = "Incompatible protocol version",
[PA_ERR_TOOLARGE] = "Too large",
[PA_ERR_NOTSUPPORTED] = "Not supported",
[PA_ERR_UNKNOWN] = "Unknown error code",
[PA_ERR_NOEXTENSION] = "No such extension"
[PA_OK] = N_("OK"),
[PA_ERR_ACCESS] = N_("Access denied"),
[PA_ERR_COMMAND] = N_("Unknown command"),
[PA_ERR_INVALID] = N_("Invalid argument"),
[PA_ERR_EXIST] = N_("Entity exists"),
[PA_ERR_NOENTITY] = N_("No such entity"),
[PA_ERR_CONNECTIONREFUSED] = N_("Connection refused"),
[PA_ERR_PROTOCOL] = N_("Protocol error"),
[PA_ERR_TIMEOUT] = N_("Timeout"),
[PA_ERR_AUTHKEY] = N_("No authorization key"),
[PA_ERR_INTERNAL] = N_("Internal error"),
[PA_ERR_CONNECTIONTERMINATED] = N_("Connection terminated"),
[PA_ERR_KILLED] = N_("Entity killed"),
[PA_ERR_INVALIDSERVER] = N_("Invalid server"),
[PA_ERR_MODINITFAILED] = N_("Module initalization failed"),
[PA_ERR_BADSTATE] = N_("Bad state"),
[PA_ERR_NODATA] = N_("No data"),
[PA_ERR_VERSION] = N_("Incompatible protocol version"),
[PA_ERR_TOOLARGE] = N_("Too large"),
[PA_ERR_NOTSUPPORTED] = N_("Not supported"),
[PA_ERR_UNKNOWN] = N_("Unknown error code"),
[PA_ERR_NOEXTENSION] = N_("No such extension")
};
pa_init_i18n();
if (error < 0 || error >= PA_ERR_MAX)
return NULL;
return errortab[error];
return _(errortab[error]);
}

38
src/pulse/i18n.c Normal file
View file

@ -0,0 +1,38 @@
/***
This file is part of PulseAudio.
Copyright 2008 Lennart Poettering
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <pulsecore/once.h>
#include "i18n.h"
void pa_init_i18n(void) {
PA_ONCE_BEGIN {
bindtextdomain(GETTEXT_PACKAGE, PULSE_LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
} PA_ONCE_END;
}

62
src/pulse/i18n.h Normal file
View file

@ -0,0 +1,62 @@
#ifndef foopulsei18nhfoo
#define foopulsei18nhfoo
/***
This file is part of PulseAudio.
Copyright 2008 Lennart Poettering
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#include <pulse/cdecl.h>
#include <pulse/gccmacro.h>
PA_C_DECL_BEGIN
#if !defined(GETTEXT_PACKAGE)
#error "Something is very wrong here, config.h needs to be included first"
#endif
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(String) dgettext(GETTEXT_PACKAGE, String)
#ifdef gettext_noop
#define N_(String) gettext_noop(String)
#else
#define N_(String) (String)
#endif
#else /* NLS is disabled */
#define _(String) (String)
#define N_(String) (String)
#define textdomain(String) (String)
#define gettext(String) (String)
#define dgettext(Domain,String) (String)
#define dcgettext(Domain,String,Type) (String)
#define bindtextdomain(Domain,Directory) (Domain)
#define bind_textdomain_codeset(Domain,Codeset) (Codeset)
#endif /* ENABLE_NLS */
void pa_init_i18n(void);
PA_C_DECL_END
#endif

View file

@ -27,6 +27,7 @@
#include <pulse/xmalloc.h>
#include <pulse/gccmacro.h>
#include <pulse/i18n.h>
#include <pulsecore/macro.h>
@ -65,6 +66,8 @@ void pa_mainloop_api_once(pa_mainloop_api* m, void (*callback)(pa_mainloop_api *
pa_assert(m);
pa_assert(callback);
pa_init_i18n();
i = pa_xnew(struct once_info, 1);
i->callback = callback;
i->userdata = userdata;

View file

@ -38,6 +38,7 @@
#include <pulse/xmalloc.h>
#include <pulse/gccmacro.h>
#include <pulse/i18n.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
@ -165,6 +166,8 @@ pa_signal_event* pa_signal_new(int sig, pa_signal_cb_t _callback, void *userdata
pa_assert(sig > 0);
pa_assert(_callback);
pa_init_i18n();
for (e = signals; e; e = e->next)
if (e->sig == sig)
goto fail;

View file

@ -44,6 +44,7 @@
#include <pulse/timeval.h>
#include <pulse/xmalloc.h>
#include <pulse/i18n.h>
#include <pulsecore/core-util.h>
#include <pulsecore/llist.h>
@ -446,6 +447,8 @@ static const pa_mainloop_api vtable = {
pa_mainloop *pa_mainloop_new(void) {
pa_mainloop *m;
pa_init_i18n();
m = pa_xnew(pa_mainloop, 1);
m->wakeup_pipe_type = 0;

View file

@ -27,6 +27,7 @@
#include <pulse/xmalloc.h>
#include <pulse/utf8.h>
#include <pulse/i18n.h>
#include <pulsecore/hashmap.h>
#include <pulsecore/strbuf.h>
@ -63,6 +64,8 @@ static void property_free(struct property *prop) {
}
pa_proplist* pa_proplist_new(void) {
pa_init_i18n();
return MAKE_PROPLIST(pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func));
}

View file

@ -28,9 +28,11 @@
#include <math.h>
#include <string.h>
#include <pulse/timeval.h>
#include <pulse/i18n.h>
#include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
#include <pulse/timeval.h>
#include "sample.h"
@ -126,8 +128,10 @@ char *pa_sample_spec_snprint(char *s, size_t l, const pa_sample_spec *spec) {
pa_assert(l);
pa_assert(spec);
pa_init_i18n();
if (!pa_sample_spec_valid(spec))
pa_snprintf(s, l, "Invalid");
pa_snprintf(s, l, _("Invalid"));
else
pa_snprintf(s, l, "%s %uch %uHz", pa_sample_format_to_string(spec->format), spec->channels, spec->rate);

View file

@ -453,4 +453,3 @@ unlock_and_fail:
pa_threaded_mainloop_unlock(p->mainloop);
return (pa_usec_t) -1;
}

View file

@ -35,6 +35,7 @@
#include <pulse/xmalloc.h>
#include <pulse/mainloop.h>
#include <pulse/i18n.h>
#include <pulsecore/log.h>
#include <pulsecore/hashmap.h>
@ -94,6 +95,8 @@ static void thread(void *userdata) {
pa_threaded_mainloop *pa_threaded_mainloop_new(void) {
pa_threaded_mainloop *m;
pa_init_i18n();
m = pa_xnew(pa_threaded_mainloop, 1);
if (!(m->real_mainloop = pa_mainloop_new())) {