1 | /* |
---|
2 | * Estonian ID card plugin for web browsers |
---|
3 | * |
---|
4 | * Copyright (C) 2010-2011 Codeborne <info@codeborne.com> |
---|
5 | * |
---|
6 | * This is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of the GNU Lesser General Public |
---|
8 | * License as published by the Free Software Foundation; either |
---|
9 | * version 2.1 of the License, or (at your option) any later version. |
---|
10 | * |
---|
11 | * This software is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | * Lesser General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU Lesser General Public |
---|
17 | * License along with this library; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
19 | * |
---|
20 | */ |
---|
21 | |
---|
22 | #include <stdio.h> |
---|
23 | #include <stdlib.h> |
---|
24 | #include <string.h> |
---|
25 | |
---|
26 | #include "esteid_log.h" |
---|
27 | #include "l10n.h" |
---|
28 | #include "esteid_misc.h" |
---|
29 | |
---|
30 | typedef struct { |
---|
31 | const char *en, *et, *ru; |
---|
32 | } label; |
---|
33 | |
---|
34 | #include "labels.h" |
---|
35 | |
---|
36 | #define LABEL_COUNT (sizeof(labels) / sizeof(label)) |
---|
37 | |
---|
38 | #define DEFAULT_LANGUAGE_OFFSET 1 |
---|
39 | |
---|
40 | int languageOffset; |
---|
41 | char* globalEmptyCString = ""; |
---|
42 | |
---|
43 | char *EstEID_getUserLocale(); |
---|
44 | |
---|
45 | int EstEID_getLanguageOffset(const char *language) { |
---|
46 | if (!language) return -1; |
---|
47 | if (!STRCASECMP("et", language)) return 1; |
---|
48 | if (!STRCASECMP("ru", language)) return 2; |
---|
49 | if (!STRCASECMP("en", language)) return 0; |
---|
50 | return -1; |
---|
51 | } |
---|
52 | |
---|
53 | void EstEID_setLocale(const char *language) { |
---|
54 | LOG_LOCATION; |
---|
55 | EstEID_log("setting language to '%s'", language); |
---|
56 | languageOffset = EstEID_getLanguageOffset(language); |
---|
57 | |
---|
58 | if (languageOffset == -1) languageOffset = DEFAULT_LANGUAGE_OFFSET; |
---|
59 | EstEID_log("languageOffset=%i", languageOffset); |
---|
60 | } |
---|
61 | |
---|
62 | const char *l10n(const char *en) { |
---|
63 | unsigned int i; |
---|
64 | if (!en) { |
---|
65 | return globalEmptyCString; |
---|
66 | } |
---|
67 | for (i = 0; i < LABEL_COUNT; i++) { |
---|
68 | if (!strcmp(labels[i].en, en)) return *(&(labels[i].en) + languageOffset); |
---|
69 | } |
---|
70 | return en; |
---|
71 | } |
---|