Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules / 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/string.h>
26 #include <dpl/singleton.h>
27 #include <list>
28
29 typedef std::list<DPL::String> LanguageTags;
30
31 class LanguageTagsProvider
32 {
33   public:
34     /*
35      * Get list of currently set language tags
36      */
37     const LanguageTags getLanguageTags() const;
38
39     /*
40      * Set new language tags (other than based on system locales)
41      */
42     void setLanguageTags(const LanguageTags& taglist);
43
44     /*
45      * Set language tags from given locales.
46      * Supported format is: xx[-yy[-zz]][.encoding]
47      */
48     void setLanguageTagsFromLocales(const char* locales);
49
50     /*
51      * Set language tags based on system language settings
52      */
53     void resetLanguageTags();
54
55     /*
56      * Adds default widget locales to language tags if
57      * it doesn't exist within actual tags.
58      * Default locales i added:
59      * - at the beginning if less then 2 tags exists on list
60      * - just before empty ("") locales - pre-last position
61      * - at the end if last position is not empty locale
62      */
63     void addWidgetDefaultLocales(const DPL::String&);
64
65     /*
66      * Function converts language tag string (i.e. en-US)
67      * into locales string (en_US).
68      */
69     static DPL::String BCP47LanguageTagToLocale(const DPL::String&);
70
71     /*
72      * Function converts locales string (i.e. en_US.UTF-8) into language tag
73      * (i.e. en-US)
74      */
75     static DPL::String LocaleToBCP47LanguageTag(const DPL::String&);
76
77   private:
78     friend class DPL::Singleton<LanguageTagsProvider>;
79
80     LanguageTags m_languageTagsList;
81
82     LanguageTagsProvider();
83     virtual ~LanguageTagsProvider();
84
85     void loadSystemTags();
86     void createTagsFromLocales(const char* language);
87 };
88
89 typedef DPL::Singleton<LanguageTagsProvider> LanguageTagsProviderSingleton;
90
91 #endif /* LANGUAGETAGSPROVIDER_H */