summaryrefslogtreecommitdiff
path: root/src/langs.c
blob: e1cf156794a9a92c9df30dbe705eaa537ae9a713 (plain)
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
/*
 *  pwlock
 *
 * Copyright 2012  Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.tizenopensource.org/license
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <locale.h>
#include <vconf.h>
#include <appcore-efl.h>

#include "util.h"
#include "langs.h"

struct lang langs[_L_MAX] = {
	{_L_AUTO, N_("IDS_IDLE_BODY_AUTOMATIC"), NULL, 0,},
	{_L_EN, "English", "en_US.UTF-8", SETTING_LANG_ENGLISH,},
	{_L_DE, "Deutsch", "de_DE.UTF-8", SETTING_LANG_GERMAN,},
	{_L_NL, "Nederlands", "nl_NL.UTF-8", 0,},
	{_L_ES, "Español", "es_ES.UTF-8", SETTING_LANG_SPAINISH,},
	{_L_PT, "português", "pt_PT.UTF-8", SETTING_LANG_PORTUGUESE,},
	{_L_EL, "ελληνικά", "el_GR.UTF-8", SETTING_LANG_GREEK,},
	{_L_IT, "Italiano", "it_IT.UTF-8", SETTING_LANG_ITALIAN,},
	{_L_FR, "Français", "fr_FR.UTF-8", SETTING_LANG_FRENCH,},
	{_L_TR, "Türkçe", "tr_TR.UTF-8", SETTING_LANG_TURKISH,},
	{_L_KO, "한국어", "ko_KR.UTF-8", SETTING_LANG_KOREA,},
	{_L_CN, "简体中文", "zh_CN.UTF-8", SETTING_LANG_CHINA,},
	{_L_HK, "繁體中文(香港)", "zh_HK.UTF-8", SETTING_LANG_CANTONESE,},
	{_L_TW, "繁體中文(台灣)", "zh_TW.UTF-8", SETTING_LANG_TAIWAN,},
	{_L_JP, "にほんご", "ja_JP.UTF-8", SETTING_LANG_JAPAN,},
	{_L_RU, "Россию", "ru_RU.UTF-8", SETTING_LANG_RUSSIAN,},
	{_L_GR, "Eλληνικά", "el_GR.UTF-8", SETTING_LANG_GREEK,}
};

static struct lang *_get_lang(int v)
{
	int i;
	struct lang *r;

	if (v < _L_AUTO || v >= _L_MAX) {
		_ERR("Get LANG: Invalid code");
		return NULL;
	}

	r = NULL;
	for (i = 0; i < sizeof(langs) / sizeof(langs[0]); i++) {
		if (langs[i].value == v) {
			r = &langs[i];
			break;
		}
	}

	return r;
}

const char *get_lang_name(int v)
{
	struct lang *l;

	l = _get_lang(v);
	if (!l)
		return NULL;

	return l->name;
}

static const char *_get_code(int v)
{
	struct lang *l;

	l = _get_lang(v);
	if (!l)
		return NULL;

	return l->code;
}

static int _get_ival(int v)
{
	struct lang *l;

	l = _get_lang(v);
	if (!l)
		return 0;

	return l->ival;
}

static int _set_lang(const char *code, int ival)
{
	int r;

	_DBG("set language: %s", code);
	r = vconf_set_str(VCONFKEY_LANGSET, code);
	if (r) {
		_ERR("Set language: vconf error");
		return -1;
	}

	r = vconf_set_int(VCONFKEY_SETAPPL_LANG_INT, ival);
	if (r) {
		_ERR("Set language: vconf error");
		return -1;
	}

	return 0;
}

int set_lang(int v)
{
	int ival;
	const char *code;

	code = _get_code(v);
	if (!code) {
		_ERR("Set language: Unknown LANG code");
		return -1;
	}

	code = setlocale(LC_ALL, code);
	if (!code) {
		_ERR("Set language: Unsupported LANG code");
		return -1;
	}

	ival = _get_ival(v);
	return _set_lang(code, ival);
}

const char *get_lang_name_by_path(char *path)
{
	int i = 0;

	if (path == NULL) return NULL;

	for (i = 0 ; i < _L_MAX ; i++) {

		if (langs[i].code == NULL) continue;

		if (strncasecmp(langs[i].code, path, MIN(strlen(langs[i].code), strlen(path))) == 0) {
			return get_lang_name(i);
		}
	}

	return NULL;
}