2 * Copyright (c) 2015 - 2016 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 #define PATH_LOCALE "locale"
36 void _update_lang(void)
39 char *lang = vconf_get_str(VCONFKEY_LANGSET);
41 setenv("LANG", lang, 1);
42 setenv("LC_MESSAGES", lang, 1);
44 r = setlocale(LC_ALL, "");
47 r = setlocale(LC_ALL, lang);
49 _D("*****appcore setlocale=%s\n", r);
54 _E("failed to get current language for set lang env"); /* LCOV_EXCL_LINE */
58 void _update_region(void)
63 region = vconf_get_str(VCONFKEY_REGIONFORMAT);
65 setenv("LC_CTYPE", region, 1);
66 setenv("LC_NUMERIC", region, 1);
67 setenv("LC_TIME", region, 1);
68 setenv("LC_COLLATE", region, 1);
69 setenv("LC_MONETARY", region, 1);
70 setenv("LC_PAPER", region, 1);
71 setenv("LC_NAME", region, 1);
72 setenv("LC_ADDRESS", region, 1);
73 setenv("LC_TELEPHONE", region, 1);
74 setenv("LC_MEASUREMENT", region, 1);
75 setenv("LC_IDENTIFICATION", region, 1);
77 r = setlocale(LC_ALL, "");
79 _D("*****appcore setlocale=%s\n", r);
83 _E("failed to get current region format for set region env"); /* LCOV_EXCL_LINE */
87 static int __get_locale_resource_dir(char *locale_dir, int size)
91 res_path = aul_get_app_resource_path();
92 if (res_path == NULL) {
93 _E("Failed to get resource path"); /* LCOV_EXCL_LINE */
94 return -1; /* LCOV_EXCL_LINE */
97 snprintf(locale_dir, size, "%s" PATH_LOCALE, res_path);
98 if (access(locale_dir, R_OK) != 0)
104 static int __set_i18n(const char *domain)
107 char locale_dir[PATH_MAX];
110 if (domain == NULL) {
111 errno = EINVAL; /* LCOV_EXCL_LINE */
112 return -1; /* LCOV_EXCL_LINE */
115 __get_locale_resource_dir(locale_dir, sizeof(locale_dir));
116 _D("locale dir: %s", locale_dir);
118 r = setlocale(LC_ALL, "");
119 /* if locale is not set properly, try again to set as language base */
121 /* LCOV_EXCL_START */
122 lang = vconf_get_str(VCONFKEY_LANGSET);
123 r = setlocale(LC_ALL, lang);
125 _D("*****appcore setlocale=%s\n", r);
132 _E("appcore: setlocale() error"); /* LCOV_EXCL_LINE */
134 r = bindtextdomain(domain, locale_dir);
136 _E("appcore: bindtextdomain() error"); /* LCOV_EXCL_LINE */
138 r = textdomain(domain);
140 _E("appcore: textdomain() error"); /* LCOV_EXCL_LINE */
145 int _set_i18n(const char *domainname)
150 return __set_i18n(domainname);