diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lang.c | 36 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 2 | ||||
-rw-r--r-- | src/ui/labelwidget.c | 3 |
3 files changed, 29 insertions, 12 deletions
@@ -66,16 +66,24 @@ void setCurrent_Lang(const char *language) { | |||
66 | load_Lang_(d, language); | 66 | load_Lang_(d, language); |
67 | } | 67 | } |
68 | 68 | ||
69 | iRangecc range_Lang(iRangecc msgId) { | 69 | static iBool find_Lang_(iRangecc msgId, iRangecc *str_out) { |
70 | const iLang *d = &lang_; | 70 | const iLang *d = &lang_; |
71 | size_t pos; | 71 | size_t pos; |
72 | const iMsgStr key = { .id = msgId }; | 72 | const iMsgStr key = { .id = msgId }; |
73 | if (locate_SortedArray(d->messages, &key, &pos)) { | 73 | if (locate_SortedArray(d->messages, &key, &pos)) { |
74 | return ((const iMsgStr *) at_SortedArray(d->messages, pos))->str; | 74 | *str_out = ((const iMsgStr *) at_SortedArray(d->messages, pos))->str; |
75 | return iTrue; | ||
75 | } | 76 | } |
76 | fprintf(stderr, "[Lang] missing: %s\n", cstr_Rangecc(msgId)); fflush(stderr); | 77 | fprintf(stderr, "[Lang] missing: %s\n", cstr_Rangecc(msgId)); fflush(stderr); |
77 | // iAssert(iFalse); | 78 | // iAssert(iFalse); |
78 | return msgId; | 79 | *str_out = msgId; |
80 | return iFalse; | ||
81 | } | ||
82 | |||
83 | iRangecc range_Lang(iRangecc msgId) { | ||
84 | iRangecc str; | ||
85 | find_Lang_(msgId, &str); | ||
86 | return str; | ||
79 | } | 87 | } |
80 | 88 | ||
81 | const char *cstr_Lang(const char *msgId) { | 89 | const char *cstr_Lang(const char *msgId) { |
@@ -96,13 +104,19 @@ void translate_Lang(iString *textWithIds) { | |||
96 | id.start += 2; | 104 | id.start += 2; |
97 | id.end = strchr(id.start, '}'); | 105 | id.end = strchr(id.start, '}'); |
98 | iAssert(id.end != NULL); | 106 | iAssert(id.end != NULL); |
99 | const size_t idLen = size_Range(&id); | 107 | const size_t idLen = size_Range(&id); |
100 | const iRangecc replacement = range_Lang(id); | 108 | iRangecc replacement; |
101 | const size_t startPos = id.start - cstr_String(textWithIds) - 2; | 109 | const size_t startPos = id.start - cstr_String(textWithIds) - 2; |
102 | /* Replace it. */ | 110 | if (find_Lang_(id, &replacement)) { |
103 | remove_Block(&textWithIds->chars, startPos, idLen + 3); | 111 | /* Replace it. */ |
104 | insertData_Block(&textWithIds->chars, startPos, replacement.start, size_Range(&replacement)); | 112 | remove_Block(&textWithIds->chars, startPos, idLen + 3); |
105 | pos = cstr_String(textWithIds) + startPos + size_Range(&replacement); | 113 | insertData_Block(&textWithIds->chars, startPos, replacement.start, size_Range(&replacement)); |
114 | pos = cstr_String(textWithIds) + startPos + size_Range(&replacement); | ||
115 | } | ||
116 | else { | ||
117 | remove_Block(&textWithIds->chars, startPos, 1); /* skip on subsequent attempts */ | ||
118 | pos = cstr_String(textWithIds) + startPos + idLen; | ||
119 | } | ||
106 | } | 120 | } |
107 | } | 121 | } |
108 | 122 | ||
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 139f622c..3d8d4f12 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -2089,7 +2089,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
2089 | size_PtrArray(links)), | 2089 | size_PtrArray(links)), |
2090 | (iMenuItem[]){ | 2090 | (iMenuItem[]){ |
2091 | { "${cancel}", 0, 0, NULL }, | 2091 | { "${cancel}", 0, 0, NULL }, |
2092 | { format_CStr(isPlural ? "dlg.import.add.many" : "dlg.import.add", | 2092 | { format_CStr(cstr_Lang(isPlural ? "dlg.import.add.many" : "dlg.import.add"), |
2093 | uiTextAction_ColorEscape, | 2093 | uiTextAction_ColorEscape, |
2094 | size_PtrArray(links)), | 2094 | size_PtrArray(links)), |
2095 | 0, | 2095 | 0, |
diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c index 6e8208c4..c34ae3cf 100644 --- a/src/ui/labelwidget.c +++ b/src/ui/labelwidget.c | |||
@@ -86,7 +86,10 @@ static iBool processEvent_LabelWidget_(iLabelWidget *d, const SDL_Event *ev) { | |||
86 | updateSize_LabelWidget(d); | 86 | updateSize_LabelWidget(d); |
87 | } | 87 | } |
88 | else if (isCommand_UserEvent(ev, "lang.changed")) { | 88 | else if (isCommand_UserEvent(ev, "lang.changed")) { |
89 | const iChar oldIcon = d->icon; /* icon will be retained */ | ||
89 | setText_LabelWidget(d, &d->srcLabel); | 90 | setText_LabelWidget(d, &d->srcLabel); |
91 | checkIcon_LabelWidget(d); /* strip it */ | ||
92 | d->icon = oldIcon; | ||
90 | return iFalse; | 93 | return iFalse; |
91 | } | 94 | } |
92 | else if (isCommand_UserEvent(ev, "bindings.changed")) { | 95 | else if (isCommand_UserEvent(ev, "bindings.changed")) { |