Unity 8
LocalePlugin.cpp
1 /*
2  * Copyright (C) 2015 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3, as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranties of
10  * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11  * PURPOSE. See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #include <QLocale>
18 #include <QStringList>
19 
20 #include <libintl.h>
21 
22 #include "LocalePlugin.h"
23 
24 class LocalePrivate {
25 public:
26  LocalePrivate() {
27  m_mccCodes = QHash<int, QString>
28  ({{202,"gr"},
29  {204,"nl"},
30  {206,"be"},
31  {208,"fr"},
32  {212,"mc"},
33  {213,"ad"},
34  {214,"es"},
35  {216,"hu"},
36  {218,"ba"},
37  {219,"hr"},
38  {220,"rs"},
39  {222,"it"},
40  {226,"ro"},
41  {228,"ch"},
42  {230,"cz"},
43  {231,"sk"},
44  {232,"at"},
45  {234,"gb"},
46  {235,"gb"},
47  {238,"dk"},
48  {240,"se"},
49  {242,"no"},
50  {244,"fi"},
51  {246,"lt"},
52  {247,"lv"},
53  {248,"ee"},
54  {250,"ru"},
55  {255,"ua"},
56  {257,"by"},
57  {259,"md"},
58  {260,"pl"},
59  {262,"de"},
60  {266,"gi"},
61  {268,"pt"},
62  {270,"lu"},
63  {272,"ie"},
64  {274,"is"},
65  {276,"al"},
66  {278,"mt"},
67  {280,"cy"},
68  {282,"ge"},
69  {283,"am"},
70  {284,"bg"},
71  {286,"tr"},
72  {288,"fo"},
73  {289,"ge"},
74  {290,"gl"},
75  {292,"sm"},
76  {293,"si"},
77  {294,"mk"},
78  {295,"li"},
79  {297,"me"},
80  {302,"ca"},
81  {308,"pm"},
82  {310,"gu"},
83  {310,"us"},
84  {311,"gu"},
85  {311,"us"},
86  {312,"us"},
87  {316,"us"},
88  {330,"pr"},
89  {334,"mx"},
90  {338,"jm"},
91  {340,"fg"},
92  {340,"gp"},
93  {340,"mq"},
94  {342,"bb"},
95  {344,"ag"},
96  {346,"ky"},
97  {348,"vg"},
98  {350,"bm"},
99  {352,"gd"},
100  {354,"ms"},
101  {356,"kn"},
102  {358,"lc"},
103  {360,"vc"},
104  {362,"an"},
105  {362,"cw"},
106  {363,"aw"},
107  {364,"bs"},
108  {365,"ai"},
109  {366,"dm"},
110  {368,"cu"},
111  {370,"do"},
112  {372,"ht"},
113  {374,"tt"},
114  {376,"tc"},
115  {376,"vi"},
116  {400,"az"},
117  {401,"kz"},
118  {402,"bt"},
119  {404,"in"},
120  {405,"in"},
121  {410,"pk"},
122  {412,"af"},
123  {413,"lk"},
124  {414,"mm"},
125  {415,"lb"},
126  {416,"jo"},
127  {417,"sy"},
128  {418,"iq"},
129  {419,"kw"},
130  {420,"sa"},
131  {421,"ye"},
132  {422,"om"},
133  {424,"ae"},
134  {425,"il"},
135  {425,"ps"},
136  {426,"bh"},
137  {427,"qa"},
138  {428,"mn"},
139  {429,"np"},
140  {430,"ae"},
141  {431,"ae"},
142  {432,"ir"},
143  {434,"uz"},
144  {436,"tk"},
145  {437,"kg"},
146  {438,"tm"},
147  {440,"jp"},
148  {441,"jp"},
149  {450,"kr"},
150  {452,"vn"},
151  {454,"hk"},
152  {455,"mo"},
153  {456,"kh"},
154  {457,"la"},
155  {460,"cn"},
156  {466,"tw"},
157  {467,"kp"},
158  {470,"bd"},
159  {472,"mv"},
160  {502,"my"},
161  {505,"au"},
162  {510,"id"},
163  {514,"tp"},
164  {515,"ph"},
165  {520,"th"},
166  {525,"sg"},
167  {528,"bn"},
168  {530,"nz"},
169  {537,"pg"},
170  {539,"to"},
171  {540,"sb"},
172  {541,"vu"},
173  {542,"fj"},
174  {544,"as"},
175  {545,"ki"},
176  {546,"nc"},
177  {547,"pf"},
178  {548,"ck"},
179  {549,"ws"},
180  {550,"fm"},
181  {552,"pw"},
182  {553,"tv"},
183  {555,"nu"},
184  {602,"eg"},
185  {603,"dz"},
186  {604,"ma"},
187  {605,"tn"},
188  {606,"ly"},
189  {607,"gm"},
190  {608,"sn"},
191  {609,"mr"},
192  {610,"ml"},
193  {611,"gn"},
194  {612,"ci"},
195  {613,"bf"},
196  {614,"ne"},
197  {615,"tg"},
198  {616,"bj"},
199  {617,"mu"},
200  {618,"lr"},
201  {619,"sl"},
202  {620,"gh"},
203  {621,"ng"},
204  {622,"td"},
205  {623,"cf"},
206  {624,"cm"},
207  {625,"cv"},
208  {626,"st"},
209  {627,"gq"},
210  {628,"ga"},
211  {629,"cg"},
212  {630,"cd"},
213  {631,"ao"},
214  {632,"gw"},
215  {633,"sc"},
216  {634,"sd"},
217  {635,"rw"},
218  {636,"et"},
219  {637,"so"},
220  {638,"dj"},
221  {639,"ke"},
222  {640,"tz"},
223  {641,"ug"},
224  {642,"bi"},
225  {643,"mz"},
226  {645,"zm"},
227  {646,"mg"},
228  {647,"re"},
229  {648,"zw"},
230  {649,"na"},
231  {650,"mw"},
232  {651,"ls"},
233  {652,"bw"},
234  {653,"sz"},
235  {654,"km"},
236  {655,"za"},
237  {657,"er"},
238  {659,"ss"},
239  {702,"bz"},
240  {704,"gt"},
241  {706,"sv"},
242  {708,"hn"},
243  {710,"ni"},
244  {712,"cr"},
245  {714,"pa"},
246  {716,"pe"},
247  {722,"ar"},
248  {724,"br"},
249  {730,"cl"},
250  {732,"co"},
251  {734,"ve"},
252  {736,"bo"},
253  {738,"gy"},
254  {740,"ec"},
255  {744,"py"},
256  {746,"sr"},
257  {748,"uy"},
258  {750,"fk"}}
259  );
260  }
261 
262  QString mccToCountryCode(int mcc) const {
263  return m_mccCodes.value(mcc, "us").toUpper();
264  }
265 
266 private:
267  // MCC = Mobile Country Code, see https://en.wikipedia.org/wiki/Mobile_country_code
268  QHash<int,QString> m_mccCodes;
269 };
270 
271 Q_GLOBAL_STATIC(LocalePrivate, d)
272 
273 LocaleAttached::LocaleAttached(QObject* parent)
274  : QObject(parent)
275 {
276 }
277 
278 QString LocaleAttached::mccToCountryCode(int mcc) const
279 {
280  return d->mccToCountryCode(mcc);
281 }
282 
283 LocalePlugin::LocalePlugin(QObject* parent)
284  : QObject(parent)
285 {
286 }
287 
288 LocaleAttached* LocalePlugin::qmlAttachedProperties(QObject* parent)
289 {
290  return new LocaleAttached(parent);
291 }