24
|
1 #include <stdio.h> |
|
2 #include <stdlib.h> |
|
3 #include <unistd.h> |
|
4 #include <string.h> |
|
5 #include <ctype.h> |
|
6 |
|
7 #include "utils.h" |
|
8 |
|
9 char Lang[100]; |
|
10 |
|
11 void lng_InitLanguage(void) |
|
12 { |
|
13 FILE *fp; |
|
14 memset(Lang, 0, 100); |
|
15 sprintf(Lang, "./lang/%s.txt", getenv("LANG")); |
|
16 /* strcpy(Lang, "./lang/"); |
|
17 strcat(Lang, getenv("LANG")); |
|
18 strcat(Lang, ".txt"); |
|
19 */ |
|
20 if ((fp = fopen(Lang, "r")) == NULL) { |
|
21 /* reverting to default */ |
|
22 ut_WriteLog("Reverting language to default: POSIX\n"); |
|
23 strcpy(Lang, "./lang/POSIX.txt"); |
|
24 } else { |
|
25 fclose(fp); |
|
26 ut_WriteLog("Setting language to %s\n", getenv("LANG")); |
|
27 } |
|
28 } |
|
29 |
|
30 char *i18n(char *text) |
|
31 { |
|
32 /* hack */ |
|
33 char *buf = (char *) malloc(1024); |
|
34 static char result[1024]; |
|
35 FILE *fp; |
|
36 char *line; |
|
37 char *value; |
|
38 int found = 0; |
|
39 |
|
40 memset(result, 0, 1024); |
|
41 |
|
42 if ((fp = fopen(Lang, "r")) != NULL) { |
|
43 while ((fgets(buf, 1024, fp) != NULL) && (!found)) { |
|
44 line = buf; |
|
45 |
|
46 while (isspace((int) *line)) |
|
47 line++; |
|
48 |
|
49 while ((strlen(line) > 0) |
|
50 && isspace((int) line[strlen(line) - 1])) |
|
51 line[strlen(line) - 1] = '\0'; |
|
52 |
|
53 if ((*line == '\n') || (*line == '\0') || (*line == '#')) |
|
54 continue; |
|
55 |
|
56 if ((strchr(line, '=') != NULL)) { |
|
57 value = strchr(line, '='); |
|
58 *value = '\0'; |
|
59 value++; |
|
60 |
|
61 while (isspace((int) *value)) |
|
62 value++; |
|
63 |
|
64 while ((strlen(line) > 0) |
|
65 && isspace((int) line[strlen(line) - 1])) |
|
66 line[strlen(line) - 1] = '\0'; |
|
67 |
|
68 if (!strcasecmp(line, text)) { |
|
69 strcpy(result, value); |
|
70 found = 1; |
|
71 } |
|
72 continue; |
|
73 } |
|
74 /* fprintf(stderr, "CFG: orphaned line \"%s\"\n", line); */ |
|
75 } |
|
76 fclose(fp); |
|
77 } |
|
78 |
|
79 if (!found) { |
|
80 strcpy(result, text); |
|
81 } |
|
82 |
|
83 free(buf); |
|
84 return result; |
|
85 } |