-made it so settings menu strings are loaded from .po files instead of .locs
-fixed issue where BlitScaled was just drawing white rectangles instead of stretching the txtSurf, so I just let this use BlitSurface instead with text getting cut off if it's too long.
This commit is contained in:
parent
34e7e822ec
commit
6b7e357e92
93
src/i18n.cpp
93
src/i18n.cpp
|
|
@ -52,36 +52,91 @@ void _read(void * ptr, size_t size, size_t count, FILE * stream) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadLocale(const char* locale) {
|
void loadLocale(const char* locale) {
|
||||||
|
char line[1024];
|
||||||
char pathbuf[100];
|
char pathbuf[100];
|
||||||
FILE* locfile;
|
FILE* locfile;
|
||||||
char header[8];
|
|
||||||
unsigned int i;
|
|
||||||
int strSize = 0;
|
|
||||||
|
|
||||||
unloadLocale();
|
unloadLocale();
|
||||||
|
|
||||||
_setLocaleFamily(locale);
|
_setLocaleFamily(locale);
|
||||||
|
|
||||||
sprintf(pathbuf, "Languages/internal/%s.loc", locale);
|
int dictSize = 52;
|
||||||
locfile = fopen(pathbuf, "rb");
|
// currently there are 52
|
||||||
|
strdict = (char**)malloc(sizeof(char*) * dictSize);
|
||||||
|
|
||||||
|
sprintf(pathbuf, "Languages/internal/%s.po", locale);
|
||||||
|
locfile = fopen(pathbuf, "r");
|
||||||
if (locfile) {
|
if (locfile) {
|
||||||
_read(header, 1, 8, locfile);
|
while (fgets(line, 1024, locfile)) {
|
||||||
if (!strcmp(header, LOC_HEADER)) {
|
if (strncmp("msgstr \"", line, 8) == 0) {
|
||||||
// Read number of strs in this file
|
char* lineWithoutMsgid = line + 8;
|
||||||
_read(&nStr, 4, 1, locfile);
|
|
||||||
strdict = (char**)malloc(sizeof(char*) * nStr);
|
char* endQuoteAddress = strrchr(lineWithoutMsgid, '"');
|
||||||
for (i = 0; i < nStr; i++) {
|
|
||||||
// Read the size of the next string
|
// end string at last quotation mark
|
||||||
_read(&strSize, 4, 1, locfile);
|
if (endQuoteAddress != 0) {
|
||||||
strdict[i] = (char*)malloc(strSize+1);
|
endQuoteAddress[0] = 0;
|
||||||
if (strSize > 0) {
|
|
||||||
// Read the contents of the next string
|
|
||||||
_read(strdict[i], 1, strSize, locfile);
|
|
||||||
strdict[i][strSize] = 0;
|
|
||||||
}
|
}
|
||||||
strdict[i][strSize] = 0;
|
|
||||||
|
decodeEscapeChars(lineWithoutMsgid);
|
||||||
|
|
||||||
|
int lineLen = strlen(lineWithoutMsgid);
|
||||||
|
|
||||||
|
strdict[nStr] = (char*)malloc(lineLen + 1);
|
||||||
|
strcpy(strdict[nStr], lineWithoutMsgid);
|
||||||
|
|
||||||
|
nStr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(locfile);
|
fclose(locfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// replaces escape characters with their actual values in-place in a string
|
||||||
|
// can do it in-place because the replacement values are always smaller than the original value
|
||||||
|
// it only handles \\ and \", but this can be expanded to include more if needed
|
||||||
|
void decodeEscapeChars(char* s) {
|
||||||
|
char* dest = s;
|
||||||
|
char* src = s;
|
||||||
|
while (src[0] != 0) {
|
||||||
|
switch (src[0]) {
|
||||||
|
// might be an escape character?
|
||||||
|
case '\\':
|
||||||
|
switch (src[1]) {
|
||||||
|
case '\\' :
|
||||||
|
dest[0] = '\\';
|
||||||
|
dest++;
|
||||||
|
src += 2;
|
||||||
|
break;
|
||||||
|
case '\"':
|
||||||
|
dest[0] = '\"';
|
||||||
|
dest++;
|
||||||
|
src += 2;
|
||||||
|
break;
|
||||||
|
// end of the string?
|
||||||
|
// so only advance forward 1 character
|
||||||
|
case 0:
|
||||||
|
dest[0] = '\\';
|
||||||
|
dest++;
|
||||||
|
src++;
|
||||||
|
break;
|
||||||
|
// not escape, handle normally
|
||||||
|
default:
|
||||||
|
dest[0] = '\\';
|
||||||
|
dest[1] = src[1];
|
||||||
|
dest+=2;
|
||||||
|
src+=2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dest[0] = src[0];
|
||||||
|
dest++;
|
||||||
|
src++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// cap the end of the string
|
||||||
|
dest[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
void unloadLocale();
|
void unloadLocale();
|
||||||
void loadLocale(const char* locale);
|
void loadLocale(const char* locale);
|
||||||
|
void decodeEscapeChars(char* s);
|
||||||
const char* findtext(unsigned int msgid, const char* fallback);
|
const char* findtext(unsigned int msgid, const char* fallback);
|
||||||
int getLocaleFamily();
|
int getLocaleFamily();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -530,7 +530,13 @@ struct SettingsMenuPrivate
|
||||||
{
|
{
|
||||||
dstRect.w = alignW;
|
dstRect.w = alignW;
|
||||||
dstRect.x = drawOff.x + x;
|
dstRect.x = drawOff.x + x;
|
||||||
SDL_BlitScaled(txtSurf, 0, surf, &dstRect);
|
|
||||||
|
SDL_Rect srcRect;
|
||||||
|
srcRect.x = 0;
|
||||||
|
srcRect.y = 0;
|
||||||
|
srcRect.w = dstRect.w;
|
||||||
|
srcRect.h = txtSurf->h;
|
||||||
|
SDL_BlitSurface(txtSurf, &srcRect, surf, &dstRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -973,7 +979,7 @@ void BindingWidget::clickHandler(int x, int y, uint8_t button)
|
||||||
if (cell == -1)
|
if (cell == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p->onBWidgetCellClicked(src[cell], vb.str, button);
|
p->onBWidgetCellClicked(src[cell], findtext(vb.trstrId, vb.str), button);
|
||||||
}
|
}
|
||||||
|
|
||||||
int BindingWidget::cellIndex(int x, int y) const
|
int BindingWidget::cellIndex(int x, int y) const
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue