2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <linux/limits.h>
31 #include "widget-log.h"
32 #include "widget-private.h"
34 void _update_lang(void)
36 char *lang = vconf_get_str(VCONFKEY_LANGSET);
38 setenv("LANG", lang, 1);
39 setenv("LC_MESSAGES", lang, 1);
41 char *r = setlocale(LC_ALL, "");
43 r = setlocale(LC_ALL, lang);
45 _D("*****appcore setlocale=%s\n", r);
50 _E("failed to get current language for set lang env");
54 void _update_region(void)
59 region = vconf_get_str(VCONFKEY_REGIONFORMAT);
61 setenv("LC_CTYPE", region, 1);
62 setenv("LC_NUMERIC", region, 1);
63 setenv("LC_TIME", region, 1);
64 setenv("LC_COLLATE", region, 1);
65 setenv("LC_MONETARY", region, 1);
66 setenv("LC_PAPER", region, 1);
67 setenv("LC_NAME", region, 1);
68 setenv("LC_ADDRESS", region, 1);
69 setenv("LC_TELEPHONE", region, 1);
70 setenv("LC_MEASUREMENT", region, 1);
71 setenv("LC_IDENTIFICATION", region, 1);
72 r = setlocale(LC_ALL, "");
74 _D("*****appcore setlocale=%s\n", r);
78 _E("failed to get current region format for set region env");
82 static int __read_proc(const char *path, char *buf, int size)
87 if (buf == NULL || path == NULL)
90 fd = open(path, O_RDONLY);
94 ret = read(fd, buf, size - 1);
106 static char* __proc_get_cmdline()
108 #define MAX_CMD_BUFSZ 1024
110 char buf[MAX_CMD_BUFSZ];
113 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", getpid());
114 ret = __read_proc(buf, buf, sizeof(buf));
121 static void __get_dir_name(char *dirname, int maxlen)
123 const char *path = NULL;
125 path = aul_get_app_root_path();
126 snprintf(dirname, maxlen, "%s/res/locale", path);
131 static int __set_i18n(const char *domain)
134 char dirname[PATH_MAX] = {0, };
136 if (domain == NULL) {
141 __get_dir_name(dirname, PATH_MAX - 1);
142 _D("locale dir: %s", dirname);
144 r = setlocale(LC_ALL, "");
145 /* if locale is not set properly, try again to set as language base */
147 char *lang = vconf_get_str(VCONFKEY_LANGSET);
148 r = setlocale(LC_ALL, lang);
150 _D("*****appcore setlocale=%s\n", r);
157 _E("appcore: setlocale() error");
160 r = bindtextdomain(domain, dirname);
162 _E("appcore: bindtextdomain() error");
165 r = textdomain(domain);
167 _E("appcore: textdomain() error");
173 int _set_i18n(const char *domainname)
178 return __set_i18n(domainname);