aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-unicode-i18n.c
blob: 94cf05ecd9d08199f41d38d50054f617fd0beaf3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * e-unicode-i18n.c
 *
 * Author: Zbigniew Chyla  <cyba@gnome.pl>
 *
 * Copyright (C) 2001 Ximian, Inc.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <glib.h>
#include <gal/widgets/e-unicode.h>
#include "e-unicode-i18n.h"

static GHashTable *locale_to_utf8_hash = NULL;

static const char *
locale_to_utf8 (const char *string)
{
    char *utf;

    if (locale_to_utf8_hash == NULL) {
        locale_to_utf8_hash = g_hash_table_new (&g_str_hash, &g_str_equal);
    }

    utf = g_hash_table_lookup (locale_to_utf8_hash, string);
    if (utf == NULL) {
        utf = e_utf8_from_locale_string (string);
        g_hash_table_insert (locale_to_utf8_hash, g_strdup (string), utf);
    }

    return utf;
}

const char *
e_utf8_gettext (const char *string)
{
    if (string == NULL) {
        return NULL;
    } else if (string[0] == '\0') {
        return "";
    } else {
        return locale_to_utf8 (gettext (string));
    }
}

const char *
e_utf8_dgettext (const char *domain, const char *string)
{
    if (string == NULL) {
        return NULL;
    } else if (string[0] == '\0') {
        return "";
    } else {
        return locale_to_utf8 (dgettext (domain, string));
    }
}