Skip to content

Commit

Permalink
translate info page strings at init not draw
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito committed Feb 19, 2021
1 parent 0377289 commit cb8c2a3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 55 deletions.
3 changes: 3 additions & 0 deletions src/lang.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "include/util.h"
#include "include/fntsys.h"
#include "include/ioman.h"
#include "include/themes.h"

// Language support
static char *internalEnglish[LANG_STR_COUNT] = {
Expand Down Expand Up @@ -480,13 +481,15 @@ int lngSetGuiValue(int langID)
language_t *currLang = &languages[langID - 1];
if (lngLoadFromFile(currLang->filePath, currLang->name)) {
guiLangID = langID;
thmSetGuiValue(thmGetGuiValue(), 1);
return 1;
}
}
lang_strs = internalEnglish;
guiLangID = 0;
// lang switched back to internalEnglish, reload default font
fntLoadDefault(NULL);
thmSetGuiValue(thmGetGuiValue(), 1);
}
}
return 0;
Expand Down
106 changes: 51 additions & 55 deletions src/themes.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,29 @@ static mutable_text_t *initMutableText(const char *themePath, config_set_t *them
else
alias = value;
}
length = strlen(alias) + 1 + 2;
mutableText->alias = (char *)malloc(length * sizeof(char));

char *temp;
if (!strncmp(alias, "Title", 5))
temp = _l(_STR_INFO_TITLE);
else if (!strncmp(alias, "Genre", 5))
temp = _l(_STR_INFO_GENRE);
else if (!strncmp(alias, "Release", 7))
temp = _l(_STR_INFO_RELEASE);
else if (!strncmp(alias, "Developer", 9))
temp = _l(_STR_INFO_DEVELOPER);
else if (!strncmp(alias, "Size", 4))
temp = _l(_STR_SIZE);
else if (!strncmp(alias, "Description", 11))
temp = _l(_STR_INFO_DESCRIPTION);
else
temp = (char *)alias;

length = strlen(temp) + 1 + 2;
mutableText->alias = (char *)calloc(length, sizeof(char));
if (mutableText->sizingMode == SIZING_WRAP)
snprintf(mutableText->alias, length, "%s:\n", alias);
snprintf(mutableText->alias, length, "%s:\n", temp);
else
snprintf(mutableText->alias, length, "%s: ", alias);
snprintf(mutableText->alias, length, "%s: ", temp);
} else {
if (mutableText->sizingMode == SIZING_WRAP)
fntFitString(elem->font, mutableText->value, elem->width);
Expand Down Expand Up @@ -183,9 +200,7 @@ static void initStaticText(const char *themePath, config_set_t *themeConfig, the

static void drawAttributeText(struct menu_list *menu, struct submenu_list *item, config_set_t *config, struct theme_element *elem)
{
char result[300];
mutable_text_t *mutableText = (mutable_text_t *)elem->extended;

if (config) {
if (mutableText->currentConfigId != config->uid) {
// force refresh
Expand All @@ -196,59 +211,40 @@ static void drawAttributeText(struct menu_list *menu, struct submenu_list *item,
fntFitString(elem->font, mutableText->currentValue, elem->width);
}
}
}

if (mutableText->displayMode == DISPLAY_NEVER) {
if (mutableText->currentValue) {
if (!strncmp(mutableText->alias, "Size", 4))
snprintf(result, sizeof(result), "%s MiB", mutableText->currentValue);
else
snprintf(result, sizeof(result), mutableText->currentValue);

if (mutableText->sizingMode == SIZING_NONE)
fntRenderString(elem->font, elem->posX, elem->posY, elem->aligned, 0, 0, result, elem->color);
else
fntRenderString(elem->font, elem->posX, elem->posY, elem->aligned, elem->width, elem->height, result, elem->color);
char result[300];
if (mutableText->displayMode == DISPLAY_NEVER) {
if (!strncmp(mutableText->alias, _l(_STR_SIZE), strlen(_l(_STR_SIZE)))) {
snprintf(result, sizeof(result), "%s MiB", mutableText->currentValue);
if (mutableText->sizingMode == SIZING_NONE)
fntRenderString(elem->font, elem->posX, elem->posY, elem->aligned, 0, 0, result, elem->color);
else
fntRenderString(elem->font, elem->posX, elem->posY, elem->aligned, elem->width, elem->height, result, elem->color);
} else {
if (mutableText->sizingMode == SIZING_NONE)
fntRenderString(elem->font, elem->posX, elem->posY, elem->aligned, 0, 0, mutableText->currentValue, elem->color);
else
fntRenderString(elem->font, elem->posX, elem->posY, elem->aligned, elem->width, elem->height, mutableText->currentValue, elem->color);
}
} else {
if (!strncmp(mutableText->alias, _l(_STR_SIZE), strlen(_l(_STR_SIZE))))
snprintf(result, sizeof(result), "%s%s MiB", mutableText->alias, mutableText->currentValue);
else
snprintf(result, sizeof(result), "%s%s", mutableText->alias, mutableText->currentValue);
if (mutableText->sizingMode == SIZING_NONE)
fntRenderString(elem->font, elem->posX, elem->posY, elem->aligned, 0, 0, result, elem->color);
else
fntRenderString(elem->font, elem->posX, elem->posY, elem->aligned, elem->width, elem->height, result, elem->color);
}
return;
}
return;
}

if (mutableText->displayMode == DISPLAY_DEFINED && mutableText->currentValue == NULL)
return;

char colon[4];
if (mutableText->sizingMode == SIZING_WRAP)
snprintf(colon, sizeof(colon), ":\n");
else
snprintf(colon, sizeof(colon), ": ");

int addSuffix = 0;
if (!strncmp(mutableText->alias, "Title", 5))
snprintf(result, sizeof(result), "%s%s", _l(_STR_INFO_TITLE), colon);
else if (!strncmp(mutableText->alias, "Genre", 5))
snprintf(result, sizeof(result), "%s%s", _l(_STR_INFO_GENRE), colon);
else if (!strncmp(mutableText->alias, "Release", 7))
snprintf(result, sizeof(result), "%s%s", _l(_STR_INFO_RELEASE), colon);
else if (!strncmp(mutableText->alias, "Developer", 9))
snprintf(result, sizeof(result), "%s%s", _l(_STR_INFO_DEVELOPER), colon);
else if (!strncmp(mutableText->alias, "Size", 4)) {
snprintf(result, sizeof(result), "%s%s", _l(_STR_SIZE), colon);
addSuffix = 1;
} else if (!strncmp(mutableText->alias, "Description", 11))
snprintf(result, sizeof(result), "%s%s", _l(_STR_INFO_DESCRIPTION), colon);
else
snprintf(result, sizeof(result), "%s", mutableText->alias);

if (mutableText->currentValue) {
strcat(result, mutableText->currentValue);
if (addSuffix)
strcat(result, " MiB");
if (mutableText->displayMode == DISPLAY_ALWAYS) {
if (mutableText->sizingMode == SIZING_NONE)
fntRenderString(elem->font, elem->posX, elem->posY, elem->aligned, 0, 0, mutableText->alias, elem->color);
else
fntRenderString(elem->font, elem->posX, elem->posY, elem->aligned, elem->width, elem->height, mutableText->alias, elem->color);
}

if (mutableText->sizingMode == SIZING_NONE)
fntRenderString(elem->font, elem->posX, elem->posY, elem->aligned, 0, 0, result, elem->color);
else
fntRenderString(elem->font, elem->posX, elem->posY, elem->aligned, elem->width, elem->height, result, elem->color);
}

static void initAttributeText(const char *themePath, config_set_t *themeConfig, theme_t *theme, theme_element_t *elem, const char *name)
Expand Down

0 comments on commit cb8c2a3

Please sign in to comment.