aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ephy-langs.c
blob: dee178846d045a3fd1501dad1fd342bf18550517 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 *  Copyright (C) 2003 Christian Persch
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *  $Id$
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "ephy-langs.h"
#include "ephy-string.h"
#include <bonobo/bonobo-i18n.h>
#include <string.h>

static const FontsLanguageInfo font_languages[] =
{
    { N_("Arabic"),                 "ar" },
    { N_("Baltic"),                 "x-baltic" },
    { N_("Central European"),           "x-central-euro" },
    { N_("Cyrillic"),               "x-cyrillic" },
    { N_("Devanagari"),             "x-devanagari" },
    { N_("Greek"),                  "el" },
    { N_("Hebrew"),                 "he" },
    { N_("Japanese"),               "ja" },
    { N_("Korean"),                 "ko" },
    { N_("Simplified Chinese"),         "zh-CN" },
    { N_("Tamil"),                  "x-tamil" },
    { N_("Thai"),                   "th" },
    { N_("Traditional Chinese"),            "zh-TW" },
#if MOZILLA_SNAPSHOT >= 11
    { N_("Traditional Chinese (Hong Kong)"),    "zh-HK" },
#endif
    { N_("Turkish"),                "tr" },
    { N_("Unicode"),                "x-unicode" },
    { N_("Western"),                "x-western" }
};
static const guint n_font_languages = G_N_ELEMENTS (font_languages);

static const
struct
{
    EphyLanguageGroup group;
    char *title;
}
lang_group_names[] =
{
        { LG_ARABIC,        N_("_Arabic")       },
        { LG_BALTIC,        N_("_Baltic")       },
        { LG_CENTRAL_EUROPEAN,  N_("Central _European") },
        { LG_CHINESE,       N_("Chi_nese")      },
        { LG_CYRILLIC,      N_("_Cyrillic")     },
        { LG_GREEK,     N_("_Greek")        },
        { LG_HEBREW,        N_("_Hebrew")       },
        { LG_INDIAN,        N_("_Indian")       },
        { LG_JAPANESE,      N_("_Japanese")     },
        { LG_KOREAN,        N_("_Korean")       },
        { LG_TURKISH,       N_("_Turkish")      },
        { LG_UNICODE,       N_("_Unicode")      },
        { LG_VIETNAMESE,    N_("_Vietnamese")   },
        { LG_WESTERN,       N_("_Western")      },
        { LG_OTHER,     N_("_Other")        }
};
static const guint n_lang_group_names = G_N_ELEMENTS (lang_group_names);

void
ephy_lang_group_info_free (EphyLanguageGroupInfo *info)
{
    g_return_if_fail (info != NULL);

    g_free (info->title);
    g_free (info->key);

    g_free (info);
}

static gint
lang_group_info_cmp (const EphyLanguageGroupInfo *i1, const EphyLanguageGroupInfo *i2)
{
    return strcmp (i1->key, i2->key);
}

GList *
ephy_lang_get_group_list (void)
{
    GList *list = NULL;
    guint i;

    for (i = 0; i < n_lang_group_names; i++)
    {
        EphyLanguageGroupInfo *info;
        char *elided = NULL;

        info = g_new0 (EphyLanguageGroupInfo, 1);

        info->title = g_strdup (_(lang_group_names[i].title));
        info->group = lang_group_names[i].group;

        /* collate without underscores */
        elided = ephy_string_elide_underscores (info->title);
        info->key = g_utf8_collate_key (elided, -1);
        g_free (elided);

        list = g_list_prepend (list, info);
    }

    return g_list_sort (list, (GCompareFunc) lang_group_info_cmp);
}

static int
fonts_language_info_cmp (const FontsLanguageInfo *i1, const FontsLanguageInfo *i2)
{
    return g_utf8_collate (i1->title, i2->title);
}

GList *
ephy_font_langs_get_codes_list (void)
{
    guint i;
    GList *list = NULL;

    for (i=0; i < n_font_languages; i++)
    {
        list = g_list_prepend (list, font_languages[i].code);
    }

    return list;
}

GList *
ephy_font_langs_get_list (void)
{
    GList *list = NULL;
    guint i;

    for (i = 0; i < n_font_languages; i++)
    {
        FontsLanguageInfo *info;

        info = g_new0 (FontsLanguageInfo, 1);
        info->title = _(font_languages[i].title);
        info->code = font_languages[i].code;

        list = g_list_prepend (list, info);
    }

    return g_list_sort (list, (GCompareFunc) fonts_language_info_cmp);
}