support webm format
[platform/core/multimedia/libmm-fileinfo.git] / utils / mm_file_util_locale.c
1 /*
2  * libmm-fileinfo
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Haejeong Kim <backto.kim@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 #include <stdlib.h>
23 #include <string.h>
24 #include <vconf.h>
25
26 #ifdef GCONF_SUPPORT
27 #include <gconf/gconf-client.h>
28 #endif
29
30 #include "mm_file_debug.h"
31 #include "mm_file_utils.h"
32
33 /* This macro is the same with global-gconf.h */
34 #define MMFILE_LANGUAGETYPE_REPOSITORY      "/Apps/Settings/language_type"
35 typedef enum {
36         MMFILE_LANGUAGE_ENGLISH = 0x00, /**<Language - English*/
37         MMFILE_LANGUAGE_GERMAN,                 /**<Language - German*/
38         MMFILE_LANGUAGE_FRENCH,                 /**<Language - French*/
39         MMFILE_LANGUAGE_ITALIAN,                        /**<Language - Italian*/
40         MMFILE_LANGUAGE_DUTCH,                  /**<Language - Dutch*/
41         MMFILE_LANGUAGE_SPANISH,                        /**<Language - Spanish*/
42         MMFILE_LANGUAGE_GREEK,                  /**<Language - Greek*/
43         MMFILE_LANGUAGE_PORTUGUESE,             /**<Language - Portuguese*/
44         MMFILE_LANGUAGE_TURKISH,                        /**<Language - Turkish*/
45         MMFILE_LANGUAGE_JAPAN_CP932,            /**<Language - Japanease for CP932*/
46         MMFILE_LANGUAGE_SIM_CHINA,              /**<Language - Simplified Chinese*/
47         MMFILE_LANGUAGE_TRA_CHINA,              /**<Language - Traditional Chinese*/
48         MMFILE_LANGUAGE_JAPAN,                  /**<Language - Japanease*/
49 #if 0
50         MMFILE_LANGUAGE_BULGARIAN,              /**<Language - Bulgarian*/
51         MMFILE_LANGUAGE_ARABIC,                 /**<Language - Arabic*/
52 #endif
53         MMFILE_LANGUAGE_MAX
54 } eMMFileSettingPhoneLanguage;
55
56 const char *MMFILE_LOCALE_TABLE[MMFILE_LANGUAGE_MAX] = {
57         "EUC-KR",               /* Temporally - Language - English */
58         "ISO8859-1",            /* Language - German */
59         "ISO8859-1",            /* Language - French */
60         "ISO8859-1",            /* Language - Italian */
61         "ISO8859-1",            /* Temporally -  Language - Dutch */
62         "ISO8859-1",            /* Language - Spanish */
63         "ISO8859-7",            /* Language - Greek */
64         "ISO8859-1",            /* Language - Portuguese */
65         "ISO8859-3",            /* Language - Turkish */
66         "CP932",                        /* Language - Japan*/
67         "GBK",                  /* Language - Simplified Chinese */
68         "BIG5",                 /* Language - Traditional Chinese */
69         "SHIFT_JIS"             /* Language - Japanease */
70 #if 0
71         /* Language - Bulgarian */
72         /* Language - Arabic */
73 #endif
74 };
75
76
77 static int _MMFileUtilGetLocaleindex()
78 {
79         int index = MMFILE_LANGUAGE_ENGLISH;
80         char *lang = NULL;
81
82         const char *china_prefix = "zh";
83         const char *eng_prefix = "en";
84
85         const char *china_lang = "zh_CN";
86         /*const char *hongkong_lang = "zh_HK";*/
87         /*const char *taiwan_lang = "zh_TW";*/
88         const char *jpn_lang = "ja_JP";
89
90         lang = vconf_get_str(VCONFKEY_LANGSET);
91
92         if (lang != NULL) {
93                 if (strncmp(lang, china_prefix, strlen(china_prefix)) == 0) {
94                         /* This case is selected language is china */
95                         if (strncmp(lang, china_lang, strlen(china_lang)) == 0) {
96                                 debug_msg(DEBUG, "[%s]character set is simplified chinese", lang);
97                                 index = MMFILE_LANGUAGE_SIM_CHINA;
98                         } else {
99                                 debug_msg(DEBUG, "[%s]character set is traditional chinese", lang);
100                                 index = MMFILE_LANGUAGE_TRA_CHINA;
101                         }
102                 } else if (strncmp(lang, eng_prefix, strlen(eng_prefix)) == 0) {
103                         /* This case is selected language is engilish
104                              In case of engilish, the character set is related with region of target binary */
105                         debug_msg(DEBUG, "[%s]character set is engilish", lang);
106                         index = MMFILE_LANGUAGE_ENGLISH;
107                 } else if (strncmp(lang, jpn_lang, strlen(jpn_lang)) == 0) {
108                         /* This case is selected language is japanease */
109                         debug_msg(DEBUG, "[%s]character set is japanease", lang);
110                         index = MMFILE_LANGUAGE_JAPAN;
111                 } else {
112                         debug_error(DEBUG, "use default character set");
113                         index = MMFILE_LANGUAGE_ENGLISH;
114                 }
115         } else {
116                 debug_error(DEBUG, "language value is NULL, use default character set");
117                 index = MMFILE_LANGUAGE_ENGLISH;
118         }
119
120         if (lang) {
121                 free(lang);
122                 lang = NULL;
123         }
124
125         return index;
126 }
127
128 EXPORT_API
129 char *MMFileUtilGetLocale(int *error)
130 {
131         int index = 0;
132         int err = 0;
133         index = _MMFileUtilGetLocaleindex();
134
135         if (index < 0 || index >= MMFILE_LANGUAGE_MAX) {
136                 debug_error(DEBUG, "invalid index\n");
137                 err = MMFILE_UTIL_FAIL;
138                 return NULL;
139         }
140
141         err = MMFILE_UTIL_SUCCESS;
142         if (error) {
143                 *error = err;
144         }
145
146         return (char *)MMFILE_LOCALE_TABLE[index];
147 }
148