findlocale.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #ifdef WIN32
  5. #include <windows.h>
  6. #include <winnt.h>
  7. #endif
  8. #include "findlocale.h"
  9. static int
  10. is_lcchar(const int c) {
  11. return isalnum(c);
  12. }
  13. static void
  14. lang_country_variant_from_envstring(const char *str,
  15. char **lang,
  16. char **country,
  17. char **variant) {
  18. int end = 0;
  19. int start;
  20. /* get lang, if any */
  21. start = end;
  22. while (is_lcchar(str[end])) {
  23. ++end;
  24. }
  25. if (start != end) {
  26. int i;
  27. int len = end - start;
  28. char *s = malloc(len + 1);
  29. for (i=0; i<len; ++i) {
  30. s[i] = tolower(str[start + i]);
  31. }
  32. s[i] = '\0';
  33. *lang = s;
  34. } else {
  35. *lang = NULL;
  36. }
  37. if (str[end] && str[end]!=':') { /* not at end of str */
  38. ++end;
  39. }
  40. /* get country, if any */
  41. start = end;
  42. while (is_lcchar(str[end])) {
  43. ++end;
  44. }
  45. if (start != end) {
  46. int i;
  47. int len = end - start;
  48. char *s = malloc(len + 1);
  49. for (i=0; i<len; ++i) {
  50. s[i] = toupper(str[start + i]);
  51. }
  52. s[i] = '\0';
  53. *country = s;
  54. } else {
  55. *country = NULL;
  56. }
  57. if (str[end] && str[end]!=':') { /* not at end of str */
  58. ++end;
  59. }
  60. /* get variant, if any */
  61. start = end;
  62. while (str[end] && str[end]!=':') {
  63. ++end;
  64. }
  65. if (start != end) {
  66. int i;
  67. int len = end - start;
  68. char *s = malloc(len + 1);
  69. for (i=0; i<len; ++i) {
  70. s[i] = str[start + i];
  71. }
  72. s[i] = '\0';
  73. *variant = s;
  74. } else {
  75. *variant = NULL;
  76. }
  77. }
  78. static int
  79. accumulate_locstring(const char *str, FL_Locale *l) {
  80. char *lang = NULL;
  81. char *country = NULL;
  82. char *variant = NULL;
  83. if (str) {
  84. lang_country_variant_from_envstring(str, &lang, &country, &variant);
  85. if (lang) {
  86. l->lang = lang;
  87. l->country = country;
  88. l->variant = variant;
  89. return 1;
  90. }
  91. }
  92. free(lang); free(country); free(variant);
  93. return 0;
  94. }
  95. #ifndef WIN32
  96. static int
  97. accumulate_env(const char *name, FL_Locale *l) {
  98. char *env;
  99. char *lang = NULL;
  100. char *country = NULL;
  101. char *variant = NULL;
  102. env = getenv(name);
  103. if (env) {
  104. return accumulate_locstring(env, l);
  105. }
  106. free(lang); free(country); free(variant);
  107. return 0;
  108. }
  109. #endif
  110. static void
  111. canonise_fl(FL_Locale *l) {
  112. /* this function fixes some common locale-specifying mistakes */
  113. /* en_UK -> en_GB */
  114. if (l->lang && 0 == strcmp(l->lang, "en")) {
  115. if (l->country && 0 == strcmp(l->country, "UK")) {
  116. free((void*)l->country);
  117. l->country = (FL_Country)malloc(strlen("GB") + 1);
  118. strcpy((char*)l->country, "GB");
  119. }
  120. }
  121. /* ja_JA -> ja_JP */
  122. if (l->lang && 0 == strcmp(l->lang, "ja")) {
  123. if (l->country && 0 == strcmp(l->country, "JA")) {
  124. free((void*)l->country);
  125. l->country = (FL_Country)malloc(strlen("JP") + 1);
  126. strcpy((char*)l->country, "JP");
  127. }
  128. }
  129. }
  130. #ifdef WIN32
  131. #include <stdio.h>
  132. #define ML(pn,sn) MAKELANGID(LANG_##pn, SUBLANG_##pn##_##sn)
  133. #define MLN(pn) MAKELANGID(LANG_##pn, SUBLANG_DEFAULT)
  134. #define RML(pn,sn) MAKELANGID(LANG_##pn, SUBLANG_##sn)
  135. typedef struct {
  136. LANGID id;
  137. char* code;
  138. } IDToCode;
  139. static const IDToCode both_to_code[] = {
  140. {ML(ENGLISH,US), "en_US.ISO_8859-1"},
  141. {ML(ENGLISH,CAN), "en_CA"}, /* english / canadian */
  142. {ML(ENGLISH,UK), "en_GB"},
  143. {ML(ENGLISH,EIRE), "en_IE"},
  144. {ML(ENGLISH,AUS), "en_AU"},
  145. {MLN(GERMAN), "de_DE"},
  146. {MLN(SPANISH), "es_ES"},
  147. {ML(SPANISH,MEXICAN), "es_MX"},
  148. {MLN(FRENCH), "fr_FR"},
  149. {ML(FRENCH,CANADIAN), "fr_CA"},
  150. {ML(FRENCH,BELGIAN), "fr_BE"}, /* ? */
  151. {ML(DUTCH,BELGIAN), "nl_BE"}, /* ? */
  152. {ML(PORTUGUESE,BRAZILIAN), "pt_BR"},
  153. {MLN(PORTUGUESE), "pt_PT"},
  154. {MLN(SWEDISH), "sv_SE"},
  155. {ML(CHINESE,HONGKONG), "zh_HK"},
  156. /* these are machine-generated and not yet verified */
  157. {RML(AFRIKAANS,DEFAULT), "af_ZA"},
  158. {RML(ALBANIAN,DEFAULT), "sq_AL"},
  159. {RML(ARABIC,ARABIC_ALGERIA), "ar_DZ"},
  160. {RML(ARABIC,ARABIC_BAHRAIN), "ar_BH"},
  161. {RML(ARABIC,ARABIC_EGYPT), "ar_EG"},
  162. {RML(ARABIC,ARABIC_IRAQ), "ar_IQ"},
  163. {RML(ARABIC,ARABIC_JORDAN), "ar_JO"},
  164. {RML(ARABIC,ARABIC_KUWAIT), "ar_KW"},
  165. {RML(ARABIC,ARABIC_LEBANON), "ar_LB"},
  166. {RML(ARABIC,ARABIC_LIBYA), "ar_LY"},
  167. {RML(ARABIC,ARABIC_MOROCCO), "ar_MA"},
  168. {RML(ARABIC,ARABIC_OMAN), "ar_OM"},
  169. {RML(ARABIC,ARABIC_QATAR), "ar_QA"},
  170. {RML(ARABIC,ARABIC_SAUDI_ARABIA), "ar_SA"},
  171. {RML(ARABIC,ARABIC_SYRIA), "ar_SY"},
  172. {RML(ARABIC,ARABIC_TUNISIA), "ar_TN"},
  173. {RML(ARABIC,ARABIC_UAE), "ar_AE"},
  174. {RML(ARABIC,ARABIC_YEMEN), "ar_YE"},
  175. {RML(ARMENIAN,DEFAULT), "hy_AM"},
  176. {RML(AZERI,AZERI_CYRILLIC), "az_AZ"},
  177. {RML(AZERI,AZERI_LATIN), "az_AZ"},
  178. {RML(BASQUE,DEFAULT), "eu_ES"},
  179. {RML(BELARUSIAN,DEFAULT), "be_BY"},
  180. /*{RML(BRETON,DEFAULT), "br_FR"},*/
  181. {RML(BULGARIAN,DEFAULT), "bg_BG"},
  182. {RML(CATALAN,DEFAULT), "ca_ES"},
  183. {RML(CHINESE,CHINESE_HONGKONG), "zh_HK"},
  184. {RML(CHINESE,CHINESE_MACAU), "zh_MO"},
  185. {RML(CHINESE,CHINESE_SIMPLIFIED), "zh_CN"},
  186. {RML(CHINESE,CHINESE_SINGAPORE), "zh_SG"},
  187. {RML(CHINESE,CHINESE_TRADITIONAL), "zh_TW"},
  188. /*{RML(CORNISH,DEFAULT), "kw_GB"},*/
  189. {RML(CZECH,DEFAULT), "cs_CZ"},
  190. {RML(DANISH,DEFAULT), "da_DK"},
  191. {RML(DUTCH,DUTCH), "nl_NL"},
  192. {RML(DUTCH,DUTCH_BELGIAN), "nl_BE"},
  193. /*{RML(DUTCH,DUTCH_SURINAM), "nl_SR"},*/
  194. {RML(ENGLISH,ENGLISH_AUS), "en_AU"},
  195. {RML(ENGLISH,ENGLISH_BELIZE), "en_BZ"},
  196. {RML(ENGLISH,ENGLISH_CAN), "en_CA"},
  197. {RML(ENGLISH,ENGLISH_CARIBBEAN), "en_CB"},
  198. {RML(ENGLISH,ENGLISH_EIRE), "en_IE"},
  199. {RML(ENGLISH,ENGLISH_JAMAICA), "en_JM"},
  200. {RML(ENGLISH,ENGLISH_NZ), "en_NZ"},
  201. {RML(ENGLISH,ENGLISH_PHILIPPINES), "en_PH"},
  202. {RML(ENGLISH,ENGLISH_SOUTH_AFRICA), "en_ZA"},
  203. {RML(ENGLISH,ENGLISH_TRINIDAD), "en_TT"},
  204. {RML(ENGLISH,ENGLISH_UK), "en_GB"},
  205. {RML(ENGLISH,ENGLISH_US), "en_US"},
  206. {RML(ENGLISH,ENGLISH_ZIMBABWE), "en_ZW"},
  207. /*{RML(ESPERANTO,DEFAULT), "eo_"},*/
  208. {RML(ESTONIAN,DEFAULT), "et_EE"},
  209. {RML(FAEROESE,DEFAULT), "fo_FO"},
  210. {RML(FARSI,DEFAULT), "fa_IR"},
  211. {RML(FINNISH,DEFAULT), "fi_FI"},
  212. {RML(FRENCH,FRENCH), "fr_FR"},
  213. {RML(FRENCH,FRENCH_BELGIAN), "fr_BE"},
  214. {RML(FRENCH,FRENCH_CANADIAN), "fr_CA"},
  215. {RML(FRENCH,FRENCH_LUXEMBOURG), "fr_LU"},
  216. {RML(FRENCH,FRENCH_MONACO), "fr_MC"},
  217. {RML(FRENCH,FRENCH_SWISS), "fr_CH"},
  218. /*{RML(GAELIC,GAELIC), "ga_IE"},*/
  219. /*{RML(GAELIC,GAELIC_MANX), "gv_GB"},*/
  220. /*{RML(GAELIC,GAELIC_SCOTTISH), "gd_GB"},*/
  221. /*{RML(GALICIAN,DEFAULT), "gl_ES"},*/
  222. {RML(GEORGIAN,DEFAULT), "ka_GE"},
  223. {RML(GERMAN,GERMAN), "de_DE"},
  224. {RML(GERMAN,GERMAN_AUSTRIAN), "de_AT"},
  225. {RML(GERMAN,GERMAN_LIECHTENSTEIN), "de_LI"},
  226. {RML(GERMAN,GERMAN_LUXEMBOURG), "de_LU"},
  227. {RML(GERMAN,GERMAN_SWISS), "de_CH"},
  228. {RML(GREEK,DEFAULT), "el_GR"},
  229. {RML(GUJARATI,DEFAULT), "gu_IN"},
  230. {RML(HEBREW,DEFAULT), "he_IL"},
  231. {RML(HINDI,DEFAULT), "hi_IN"},
  232. {RML(HUNGARIAN,DEFAULT), "hu_HU"},
  233. {RML(ICELANDIC,DEFAULT), "is_IS"},
  234. {RML(INDONESIAN,DEFAULT), "id_ID"},
  235. {RML(ITALIAN,ITALIAN), "it_IT"},
  236. {RML(ITALIAN,ITALIAN_SWISS), "it_CH"},
  237. {RML(JAPANESE,DEFAULT), "ja_JP"},
  238. {RML(KANNADA,DEFAULT), "kn_IN"},
  239. {RML(KAZAK,DEFAULT), "kk_KZ"},
  240. {RML(KONKANI,DEFAULT), "kok_IN"},
  241. {RML(KOREAN,KOREAN), "ko_KR"},
  242. /*{RML(KYRGYZ,DEFAULT), "ky_KG"},*/
  243. {RML(LATVIAN,DEFAULT), "lv_LV"},
  244. {RML(LITHUANIAN,LITHUANIAN), "lt_LT"},
  245. {RML(MACEDONIAN,DEFAULT), "mk_MK"},
  246. {RML(MALAY,MALAY_BRUNEI_DARUSSALAM), "ms_BN"},
  247. {RML(MALAY,MALAY_MALAYSIA), "ms_MY"},
  248. {RML(MARATHI,DEFAULT), "mr_IN"},
  249. /*{RML(MONGOLIAN,DEFAULT), "mn_MN"},*/
  250. {RML(NORWEGIAN,NORWEGIAN_BOKMAL), "nb_NO"},
  251. {RML(NORWEGIAN,NORWEGIAN_NYNORSK), "nn_NO"},
  252. {RML(POLISH,DEFAULT), "pl_PL"},
  253. {RML(PORTUGUESE,PORTUGUESE), "pt_PT"},
  254. {RML(PORTUGUESE,PORTUGUESE_BRAZILIAN), "pt_BR"},
  255. {RML(PUNJABI,DEFAULT), "pa_IN"},
  256. {RML(ROMANIAN,DEFAULT), "ro_RO"},
  257. {RML(RUSSIAN,DEFAULT), "ru_RU"},
  258. {RML(SANSKRIT,DEFAULT), "sa_IN"},
  259. {RML(SERBIAN,DEFAULT), "hr_HR"},
  260. {RML(SERBIAN,SERBIAN_CYRILLIC), "sr_SP"},
  261. {RML(SERBIAN,SERBIAN_LATIN), "sr_SP"},
  262. {RML(SLOVAK,DEFAULT), "sk_SK"},
  263. {RML(SLOVENIAN,DEFAULT), "sl_SI"},
  264. {RML(SPANISH,SPANISH), "es_ES"},
  265. {RML(SPANISH,SPANISH_ARGENTINA), "es_AR"},
  266. {RML(SPANISH,SPANISH_BOLIVIA), "es_BO"},
  267. {RML(SPANISH,SPANISH_CHILE), "es_CL"},
  268. {RML(SPANISH,SPANISH_COLOMBIA), "es_CO"},
  269. {RML(SPANISH,SPANISH_COSTA_RICA), "es_CR"},
  270. {RML(SPANISH,SPANISH_DOMINICAN_REPUBLIC), "es_DO"},
  271. {RML(SPANISH,SPANISH_ECUADOR), "es_EC"},
  272. {RML(SPANISH,SPANISH_EL_SALVADOR), "es_SV"},
  273. {RML(SPANISH,SPANISH_GUATEMALA), "es_GT"},
  274. {RML(SPANISH,SPANISH_HONDURAS), "es_HN"},
  275. {RML(SPANISH,SPANISH_MEXICAN), "es_MX"},
  276. {RML(SPANISH,SPANISH_MODERN), "es_ES"},
  277. {RML(SPANISH,SPANISH_NICARAGUA), "es_NI"},
  278. {RML(SPANISH,SPANISH_PANAMA), "es_PA"},
  279. {RML(SPANISH,SPANISH_PARAGUAY), "es_PY"},
  280. {RML(SPANISH,SPANISH_PERU), "es_PE"},
  281. {RML(SPANISH,SPANISH_PUERTO_RICO), "es_PR"},
  282. {RML(SPANISH,SPANISH_URUGUAY), "es_UY"},
  283. {RML(SPANISH,SPANISH_VENEZUELA), "es_VE"},
  284. {RML(SWAHILI,DEFAULT), "sw_KE"},
  285. {RML(SWEDISH,SWEDISH), "sv_SE"},
  286. {RML(SWEDISH,SWEDISH_FINLAND), "sv_FI"},
  287. /*{RML(SYRIAC,DEFAULT), "syr_SY"},*/
  288. {RML(TAMIL,DEFAULT), "ta_IN"},
  289. {RML(TATAR,DEFAULT), "tt_TA"},
  290. {RML(TELUGU,DEFAULT), "te_IN"},
  291. {RML(THAI,DEFAULT), "th_TH"},
  292. {RML(TURKISH,DEFAULT), "tr_TR"},
  293. {RML(UKRAINIAN,DEFAULT), "uk_UA"},
  294. {RML(URDU,URDU_PAKISTAN), "ur_PK"},
  295. {RML(UZBEK,UZBEK_CYRILLIC), "uz_UZ"},
  296. {RML(UZBEK,UZBEK_LATIN), "uz_UZ"},
  297. {RML(VIETNAMESE,DEFAULT), "vi_VN"},
  298. /*{RML(WALON,DEFAULT), "wa_BE"},*/
  299. /*{RML(WELSH,DEFAULT), "cy_GB"},*/
  300. };
  301. static const IDToCode primary_to_code[] = {
  302. {LANG_AFRIKAANS, "af"},
  303. {LANG_ARABIC, "ar"},
  304. {LANG_AZERI, "az"},
  305. {LANG_BULGARIAN, "bg"},
  306. /*{LANG_BRETON, "br"},*/
  307. {LANG_BELARUSIAN, "by"},
  308. {LANG_CATALAN, "ca"},
  309. {LANG_CZECH, "cs"},
  310. /*{LANG_WELSH, "cy"},*/
  311. {LANG_DANISH, "da"},
  312. {LANG_GERMAN, "de"},
  313. {LANG_GREEK, "el"},
  314. {LANG_ENGLISH, "en"},
  315. /*{LANG_ESPERANTO, "eo"},*/
  316. {LANG_SPANISH, "es"},
  317. {LANG_ESTONIAN, "et"},
  318. {LANG_BASQUE, "eu"},
  319. {LANG_FARSI, "fa"},
  320. {LANG_FINNISH, "fi"},
  321. {LANG_FAEROESE, "fo"},
  322. {LANG_FRENCH, "fr"},
  323. /*{LANG_GAELIC, "ga"},*/
  324. /*{LANG_GALICIAN, "gl"},*/
  325. {LANG_GUJARATI, "gu"},
  326. {LANG_HEBREW, "he"},
  327. {LANG_HINDI, "hi"},
  328. {LANG_SERBIAN, "hr"},
  329. {LANG_HUNGARIAN, "hu"},
  330. {LANG_ARMENIAN, "hy"},
  331. {LANG_INDONESIAN, "id"},
  332. {LANG_ITALIAN, "it"},
  333. {LANG_JAPANESE, "ja"},
  334. {LANG_GEORGIAN, "ka"},
  335. {LANG_KAZAK, "kk"},
  336. {LANG_KANNADA, "kn"},
  337. {LANG_KOREAN, "ko"},
  338. /*{LANG_KYRGYZ, "ky"},*/
  339. {LANG_LITHUANIAN, "lt"},
  340. {LANG_LATVIAN, "lv"},
  341. {LANG_MACEDONIAN, "mk"},
  342. /*{LANG_MONGOLIAN, "mn"},*/
  343. {LANG_MARATHI, "mr"},
  344. {LANG_MALAY, "ms"},
  345. {LANG_NORWEGIAN, "nb"},
  346. {LANG_DUTCH, "nl"},
  347. {LANG_NORWEGIAN, "nn"},
  348. {LANG_NORWEGIAN, "no"},/* unofficial? */
  349. {LANG_PUNJABI, "pa"},
  350. {LANG_POLISH, "pl"},
  351. {LANG_PORTUGUESE, "pt"},
  352. {LANG_ROMANIAN, "ro"},
  353. {LANG_RUSSIAN, "ru"},
  354. {LANG_SLOVAK, "sk"},
  355. {LANG_SLOVENIAN, "sl"},
  356. {LANG_ALBANIAN, "sq"},
  357. {LANG_SERBIAN, "sr"},
  358. {LANG_SWEDISH, "sv"},
  359. {LANG_SWAHILI, "sw"},
  360. {LANG_TAMIL, "ta"},
  361. {LANG_THAI, "th"},
  362. {LANG_TURKISH, "tr"},
  363. {LANG_TATAR, "tt"},
  364. {LANG_UKRAINIAN, "uk"},
  365. {LANG_URDU, "ur"},
  366. {LANG_UZBEK, "uz"},
  367. {LANG_VIETNAMESE, "vi"},
  368. /*{LANG_WALON, "wa"},*/
  369. {LANG_CHINESE, "zh"},
  370. };
  371. static int num_primary_to_code =
  372. sizeof(primary_to_code) / sizeof(*primary_to_code);
  373. static int num_both_to_code =
  374. sizeof(both_to_code) / sizeof(*both_to_code);
  375. static int
  376. lcid_to_fl(LCID lcid,
  377. FL_Locale *rtn) {
  378. LANGID langid = LANGIDFROMLCID(lcid);
  379. LANGID primary_lang = PRIMARYLANGID(langid);
  380. // LANGID sub_lang = SUBLANGID(langid);
  381. int i;
  382. /* try to find an exact primary/sublanguage combo that we know about */
  383. for (i=0; i<num_both_to_code; ++i) {
  384. if (both_to_code[i].id == langid) {
  385. accumulate_locstring(both_to_code[i].code, rtn);
  386. return 1;
  387. }
  388. }
  389. /* fallback to just checking the primary language id */
  390. for (i=0; i<num_primary_to_code; ++i) {
  391. if (primary_to_code[i].id == primary_lang) {
  392. accumulate_locstring(primary_to_code[i].code, rtn);
  393. return 1;
  394. }
  395. }
  396. return 0;
  397. }
  398. #endif
  399. FL_Success
  400. FL_FindLocale(FL_Locale **locale) {
  401. FL_Success success = FL_FAILED;
  402. FL_Locale *rtn = malloc(sizeof(FL_Locale));
  403. rtn->lang = NULL;
  404. rtn->country = NULL;
  405. rtn->variant = NULL;
  406. #ifdef WIN32
  407. /* win32 >= mswindows95 */
  408. {
  409. LCID lcid = GetThreadLocale();
  410. if (lcid_to_fl(lcid, rtn)) {
  411. success = FL_CONFIDENT;
  412. }
  413. if (success == FL_FAILED) {
  414. /* assume US English on mswindows systems unless we know otherwise */
  415. if (accumulate_locstring("en_US.ISO_8859-1", rtn)) {
  416. success = FL_DEFAULT_GUESS;
  417. }
  418. }
  419. }
  420. #else
  421. /* assume unixoid */
  422. {
  423. /* examples: */
  424. /* sv_SE.ISO_8859-1 */
  425. /* fr_FR.ISO8859-1 */
  426. /* no_NO_NB */
  427. /* no_NO_NY */
  428. /* no_NO */
  429. /* de_DE */
  430. /* try the various vars in decreasing order of authority */
  431. if (accumulate_env("LC_ALL", rtn) ||
  432. accumulate_env("LC_MESSAGES", rtn) ||
  433. accumulate_env("LANG", rtn) ||
  434. accumulate_env("LANGUAGE", rtn)) {
  435. success = FL_CONFIDENT;
  436. }
  437. if (success == FL_FAILED) {
  438. /* assume US English on unixoid systems unless we know otherwise */
  439. if (accumulate_locstring("en_US.ISO_8859-1", rtn)) {
  440. success = FL_DEFAULT_GUESS;
  441. }
  442. }
  443. }
  444. #endif
  445. if (success != FL_FAILED) {
  446. canonise_fl(rtn);
  447. }
  448. *locale = rtn;
  449. return success;
  450. }
  451. void
  452. FL_FreeLocale(FL_Locale **locale) {
  453. if (locale) {
  454. FL_Locale *l = *locale;
  455. if (l) {
  456. if (l->lang) {
  457. free((void*)l->lang);
  458. }
  459. if (l->country) {
  460. free((void*)l->country);
  461. }
  462. if (l->variant) {
  463. free((void*)l->variant);
  464. }
  465. free(l);
  466. *locale = NULL;
  467. }
  468. }
  469. }