Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules_mobile / localization / include / LanguageTagsProvider.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @file    LanguageTagsProvider.h
18  * @author  Marcin Kaminski (marcin.ka@samsung.com)
19  * @version 1.0
20  */
21
22 #ifndef LANGUAGETAGSPROVIDER_H
23 #define LANGUAGETAGSPROVIDER_H
24
25 #include <dpl/optional.h>
26 #include <dpl/string.h>
27 #include <dpl/singleton.h>
28 #include <list>
29
30 typedef std::list<DPL::String> LanguageTags;
31
32 class LanguageTagsProvider
33 {
34   public:
35     /*
36      * Get list of currently set language tags
37      */
38     const LanguageTags getLanguageTags() const;
39
40     /*
41      * Set new language tags (other than based on system locales)
42      */
43     void setLanguageTags(const LanguageTags& taglist);
44
45     /*
46      * Set language tags from given locales.
47      * Supported format is: xx[-yy[-zz]][.encoding]
48      */
49     void setLanguageTagsFromLocales(const char* locales);
50
51     /*
52      * Set language tags based on system language settings
53      */
54     void resetLanguageTags();
55
56     /*
57      * Adds default widget locales to language tags if
58      * it doesn't exist within actual tags.
59      * Default locales i added:
60      * - at the beginning if less then 2 tags exists on list
61      * - just before empty ("") locales - pre-last position
62      * - at the end if last position is not empty locale
63      */
64     void addWidgetDefaultLocales(const DPL::String&);
65
66     /*
67      * Function converts language tag string (i.e. en-US)
68      * into locales string (en_US).
69      */
70     static DPL::String BCP47LanguageTagToLocale(const DPL::String&);
71
72     /*
73      * Function converts locales string (i.e. en_US.UTF-8) into language tag
74      * (i.e. en-US)
75      */
76     static DPL::String LocaleToBCP47LanguageTag(const DPL::String&);
77
78   private:
79     friend class DPL::Singleton<LanguageTagsProvider>;
80
81     LanguageTags m_languageTagsList;
82
83     LanguageTagsProvider();
84     virtual ~LanguageTagsProvider();
85
86     void loadSystemTags();
87     void createTagsFromLocales(const char* language);
88 };
89
90 typedef DPL::Singleton<LanguageTagsProvider> LanguageTagsProviderSingleton;
91
92 #endif /* LANGUAGETAGSPROVIDER_H */