summaryrefslogtreecommitdiff
path: root/src/lang.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-22 17:28:05 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-22 17:28:05 +0200
commit36ad6cd20a07aecf69e92e9fa724beef14be536a (patch)
treee2b130724be663b48ae7949327ffca158c35bae1 /src/lang.c
parent157f0be146bf8122a70dcf5940f1033a6462c34c (diff)
Basic language string mechanism
Added a set of English strings. Lang can load a language. LabelWidget can replace IDs in the label. IssueID #192
Diffstat (limited to 'src/lang.c')
-rw-r--r--src/lang.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/lang.c b/src/lang.c
index 3e99c09c..d0120798 100644
--- a/src/lang.c
+++ b/src/lang.c
@@ -31,15 +31,16 @@ static void clear_Lang_(iLang *d) {
31 31
32static void load_Lang_(iLang *d, const char *id) { 32static void load_Lang_(iLang *d, const char *id) {
33 /* Load compiled language strings from an embedded blob. */ 33 /* Load compiled language strings from an embedded blob. */
34 const iBlock *data = NULL; // &blobLangEn_Embedded; 34 iUnused(id);
35 const iBlock *data = &blobEn_Embedded;
35 iMsgStr msg; 36 iMsgStr msg;
36 for (const char *ptr = constBegin_Block(data); ptr != constEnd_Block(data); ptr++) { 37 for (const char *ptr = constBegin_Block(data); ptr != constEnd_Block(data); ptr++) {
37 msg.id = ptr; 38 msg.id = ptr;
38 while (*++ptr) {} 39 while (*++ptr) {}
39 msg.str = ++ptr; 40 msg.str = ++ptr;
40 while (*++ptr) {} 41 while (*++ptr) {}
41 /* Allocate the string. */ 42 /* Allocate the string. The data has already been sorted. */
42 insert_SortedArray(d->messages, &msg); 43 pushBack_Array(&d->messages->values, &msg);
43 } 44 }
44} 45}
45 46
@@ -68,8 +69,8 @@ const char *cstr_Lang(const char *msgId) {
68 if (locate_SortedArray(d->messages, &key, &pos)) { 69 if (locate_SortedArray(d->messages, &key, &pos)) {
69 return ((const iMsgStr *) at_SortedArray(d->messages, pos))->str; 70 return ((const iMsgStr *) at_SortedArray(d->messages, pos))->str;
70 } 71 }
71 //iAssert(iFalse); 72 fprintf(stderr, "[Lang] missing: %s\n", msgId); fflush(stderr);
72 fprintf(stderr, "[Lang] missing: %s\n", msgId); 73 iAssert(iFalse);
73 return msgId; 74 return msgId;
74} 75}
75 76