summaryrefslogtreecommitdiff
path: root/source3/intl
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-10-14 12:10:29 +0000
committerAndrew Tridgell <tridge@samba.org>2001-10-14 12:10:29 +0000
commita689b24db14436ab1faa2f2f79b9f27b777b1fdb (patch)
tree7195ae4dc635d1f2e18b44ae57408b03e99e7c63 /source3/intl
parent47a0b69029857e92703ca5b00022dcfcb179c9c7 (diff)
downloadsamba-a689b24db14436ab1faa2f2f79b9f27b777b1fdb.tar.gz
samba-a689b24db14436ab1faa2f2f79b9f27b777b1fdb.tar.bz2
samba-a689b24db14436ab1faa2f2f79b9f27b777b1fdb.zip
the next step in the intl changeover. This should get us compiling agian,
and also completes the switch to lang_tdb.c. SWAT should now work with a po file in the lib/ directory also removed useless SYSLOG defines in many files (This used to be commit 5296b20ad85d7519c870768455cb4d8df048c55a)
Diffstat (limited to 'source3/intl')
-rw-r--r--source3/intl/lang_tdb.c67
1 files changed, 53 insertions, 14 deletions
diff --git a/source3/intl/lang_tdb.c b/source3/intl/lang_tdb.c
index 52a84d59a2..8d514c5e7d 100644
--- a/source3/intl/lang_tdb.c
+++ b/source3/intl/lang_tdb.c
@@ -23,6 +23,10 @@
static TDB_CONTEXT *tdb;
+/* the currently selected language */
+static char *current_lang;
+
+
/* load a po file into the tdb */
static BOOL load_po(const char *po_file)
{
@@ -84,23 +88,44 @@ static char *get_lang(void)
return NULL;
}
-/* initialise the message translation subsystem */
-void lang_tdb_init(void)
+/* initialise the message translation subsystem. If the "lang" argument
+ is NULL then get the language from the normal environment variables */
+BOOL lang_tdb_init(const char *lang)
{
- char *lang;
char *path = NULL;
+ char *po_path = NULL;
struct stat st;
static int initialised;
time_t loadtime;
- /* we only want to init once per process */
- if (initialised) return;
+ /* we only want to init once per process, unless given
+ an override */
+ if (initialised && !lang) return True;
+
+ if (initialised) {
+ /* we are re-initialising, free up any old init */
+ tdb_close(tdb);
+ tdb = NULL;
+ SAFE_FREE(current_lang);
+ }
+
initialised = 1;
- lang = get_lang();
+ if (!lang) {
+ /* no lang given, use environment */
+ lang = get_lang();
+ }
/* if no lang then we don't translate */
- if (!lang) return;
+ if (!lang) return True;
+
+ asprintf(&po_path, "%s.po", lib_path(lang));
+ if (stat(po_path, &st) != 0) {
+ /* the po file isn't available */
+ free(po_path);
+ return False;
+ }
+
asprintf(&path, "%s%s.tdb", lock_path("lang_"), lang);
@@ -108,20 +133,25 @@ void lang_tdb_init(void)
if (!tdb) {
tdb = tdb_open_log(path, 0, TDB_DEFAULT, O_RDONLY, 0);
free(path);
- return;
+ free(po_path);
+ if (!tdb) return False;
+ current_lang = strdup(lang);
+ return True;
}
free(path);
- asprintf(&path, "%s.po", lock_path(lang));
-
loadtime = tdb_fetch_int(tdb, "/LOADTIME/");
- if (stat(path, &st) == 0 && (loadtime == -1 || loadtime < st.st_mtime)) {
- load_po(path);
+ if (loadtime == -1 || loadtime < st.st_mtime) {
+ load_po(po_path);
tdb_store_int(tdb, "/LOADTIME/", (int)time(NULL));
}
- free(path);
+ free(po_path);
+
+ current_lang = strdup(lang);
+
+ return True;
}
/* translate a msgid to a message string in the current language
@@ -131,7 +161,7 @@ const char *lang_msg(const char *msgid)
{
TDB_DATA key, data;
- lang_tdb_init();
+ lang_tdb_init(NULL);
if (!tdb) return msgid;
@@ -179,3 +209,12 @@ const char *lang_msg_rotate(const char *msgid)
return msgstr;
}
+
+
+/*
+ return the current language - needed for language file mappings
+*/
+char *lang_tdb_current(void)
+{
+ return current_lang;
+}