Use elm api to get preinit_window
[platform/core/appfw/app-core.git] / src / appcore-i18n.c
1 /*
2  *  app-core
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22
23 #include <locale.h>
24 #include <libintl.h>
25 #include <stdlib.h>
26 #include <errno.h>
27
28 #include <vconf.h>
29
30 #include "appcore-internal.h"
31
32 static int _set;
33
34 void update_lang(void)
35 {
36         char *lang;
37         char *r;
38
39         lang = vconf_get_str(VCONFKEY_LANGSET);
40         if (lang) {
41                 setenv("LANG", lang, 1);
42                 setenv("LC_MESSAGES", lang, 1);
43                 r = setlocale(LC_ALL, "");
44                 if (r == NULL) {
45                         r = setlocale(LC_ALL, lang);
46                         if (r != NULL)
47                                 _DBG("*****appcore setlocale=%s\n", r);
48                 }
49                 free(lang);
50         }
51 }
52
53 void update_region(void)
54 {
55         char *region;
56         char *r;
57
58         region = vconf_get_str(VCONFKEY_REGIONFORMAT);
59         if (region) {
60                 setenv("LC_CTYPE", region, 1);
61                 setenv("LC_NUMERIC", region, 1);
62                 setenv("LC_TIME", region, 1);
63                 setenv("LC_COLLATE", region, 1);
64                 setenv("LC_MONETARY", region, 1);
65                 setenv("LC_PAPER", region, 1);
66                 setenv("LC_NAME", region, 1);
67                 setenv("LC_ADDRESS", region, 1);
68                 setenv("LC_TELEPHONE", region, 1);
69                 setenv("LC_MEASUREMENT", region, 1);
70                 setenv("LC_IDENTIFICATION", region, 1);
71                 r = setlocale(LC_ALL, "");
72                 if (r != NULL)
73                         _DBG("*****appcore setlocale=%s\n", r);
74
75                 free(region);
76         }
77 }
78
79 static int __set_i18n(const char *domain, const char *dir)
80 {
81         char *r;
82
83         if (domain == NULL) {
84                 errno = EINVAL;
85                 return -1;
86         }
87
88         r = setlocale(LC_ALL, "");
89         /* if locale is not set properly, try again to set as language base */
90         if (r == NULL) {
91                 r = setlocale(LC_ALL, vconf_get_str(VCONFKEY_LANGSET));
92                 _DBG("*****appcore setlocale=%s\n", r);
93         }
94         if (r == NULL)
95                 _ERR("appcore: setlocale() error");
96
97         r = bindtextdomain(domain, dir);
98         if (r == NULL)
99                 _ERR("appcore: bindtextdomain() error");
100
101         r = textdomain(domain);
102         if (r == NULL)
103                 _ERR("appcore: textdomain() error");
104
105         return 0;
106 }
107
108 EXPORT_API int appcore_set_i18n(const char *domainname, const char *dirname)
109 {
110         int r;
111
112         update_lang();
113         update_region();
114
115         r = __set_i18n(domainname, dirname);
116         if (r == 0)
117                 _set = 1;
118
119         return r;
120 }
121
122 int set_i18n(const char *domainname, const char *dirname)
123 {
124         _retv_if(_set, 0);
125
126         update_lang();
127         update_region();
128
129         return __set_i18n(domainname, dirname);
130 }
131
132 EXPORT_API int appcore_get_timeformat(enum appcore_time_format *timeformat)
133 {
134         int r;
135
136         if (timeformat == NULL) {
137                 errno = EINVAL;
138                 return -1;
139         }
140
141         r = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, (int *)timeformat);
142
143         if (r < 0) {
144                 *timeformat = APPCORE_TIME_FORMAT_UNKNOWN;
145                 return -1;
146         } else
147                 return 0;
148 }