summaryrefslogtreecommitdiff
path: root/intl.c
diff options
context:
space:
mode:
authorSimon Quigley <tsimonq2@ubuntu.com>2017-06-19 14:38:30 -0500
committerSimon Quigley <tsimonq2@ubuntu.com>2017-06-19 14:38:30 -0500
commit8c1612d32c5682a86216adb8c8d11ce715fe5475 (patch)
tree2a51954d577955c8ad19e517e4c7b6b8972982e4 /intl.c
parent0864b0a8e6f0b0983c3536931cfbad1414137d6b (diff)
Import Upstream version 0.3.6
Diffstat (limited to 'intl.c')
-rw-r--r--intl.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/intl.c b/intl.c
new file mode 100644
index 00000000..e0817b51
--- /dev/null
+++ b/intl.c
@@ -0,0 +1,111 @@
+/*
+ * ToscoIntl version 0.1
+ * Copyright (c) 2002-2003 Leandro Pereira <leandro@linuxmag.com.br>
+ * All rights reserved.
+ *
+ * This script is in the Tosco Public License. It may be copied and/or
+ * modified, in whole or in part, provided that all copies and related
+ * documentation includes the above copyright notice, this condition
+ * and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *
+ * (yes, the disclaimer is a copy from the BSD license, eat me!)
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+#include "hardinfo.h"
+
+#ifdef ENABLE_NLS
+
+void intl_init(void)
+{
+ const gchar *by;
+
+ g_print("Translation module registered.\n");
+
+ by = intl_translate("translated-by", "Translation");
+ if (strcmp(by, "translated-by")) {
+ g_print("Translated by: %s\n", by);
+ }
+}
+
+/*
+ * GNU's gettext is cool and all... but hey, this is smaller :)
+ */
+const gchar *
+intl_translate(const gchar * string, const gchar * source) __THROW
+{
+ FILE *file;
+ gchar buffer[256], *keyname, *lang = NULL, *langenv = NULL;
+ const gchar *retval, *langvars[] =
+ {"LANG", "LC_MESSAGES", "LC_ALL", NULL};
+ gboolean found;
+ struct stat st;
+ gint i = 0;
+
+ keyname = g_strdup_printf("[%s]", source);
+
+ for (; langvars[i]; i++)
+ if (getenv(langvars[i])) {
+ langenv = getenv(langvars[i]);
+ goto langenv_ok;
+ }
+
+ goto not_found;
+
+ langenv_ok:
+ lang = g_strconcat(INTL_PREFIX, langenv, ".lang", NULL);
+ if (stat(lang, &st)) {
+ lang = g_strconcat(INTL_PREFIX, "default.lang", NULL);
+ if (stat(lang, &st)) {
+ not_found:
+ retval = string;
+ goto finished;
+ }
+ }
+
+ retval = string;
+
+ file = fopen(lang, "r");
+ if (!file)
+ goto finished;
+
+ while (fgets(buffer, 256, file)) {
+ const gchar *buf = buffer;
+
+ buf = g_strstrip(buf);
+
+ if (*buf == '[' && !found &&
+ !strncmp(buf, keyname, strlen(keyname)))
+ found = TRUE;
+ if (found && !strncmp(buf, string, strlen(string)) &&
+ *(buf + strlen(string)) == '=') {
+ walk_until_inclusive('=');
+ retval = g_strdup(buf);
+
+ fclose(file);
+
+ goto finished;
+ }
+ }
+ fclose(file);
+
+ finished:
+ g_free(keyname);
+ g_free(lang);
+
+ return retval;
+}
+
+#endif