Skip to content

Commit

Permalink
Make strings translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
Epicpkmn11 authored and d0k3 committed Apr 15, 2023
1 parent cae3d27 commit 93ee590
Show file tree
Hide file tree
Showing 31 changed files with 1,852 additions and 946 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export ASFLAGS := -g -x assembler-with-cpp $(INCLUDE)
export CFLAGS := -DDBUILTS="\"$(DBUILTS)\"" -DDBUILTL="\"$(DBUILTL)\"" -DVERSION="\"$(VERSION)\"" -DFLAVOR="\"$(FLAVOR)\"" \
-g -Os -Wall -Wextra -Wcast-align -Wformat=2 -Wno-main \
-fomit-frame-pointer -ffast-math -std=gnu11 -MMD -MP \
-Wno-unused-function -Wno-format-truncation $(INCLUDE) -ffunction-sections -fdata-sections
-Wno-unused-function -Wno-format-truncation -Wno-format-nonliteral $(INCLUDE) -ffunction-sections -fdata-sections
export LDFLAGS := -Tlink.ld -nostartfiles -Wl,--gc-sections,-z,max-page-size=4096
ELF := arm9/arm9.elf arm11/arm11.elf

Expand Down
3 changes: 2 additions & 1 deletion arm9/source/common/swkbd.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdarg.h>

#include "language.h"
#include "swkbd.h"
#include "timer.h"
#include "hid.h"
Expand Down Expand Up @@ -253,7 +254,7 @@ bool ShowKeyboard(char* inputstr, const u32 max_size, const char *format, ...) {
TouchBox* textbox = swkbd_alphabet; // always use this textbox

static bool show_instr = true;
static const char* instr = "Keyboard Controls:\n \n←/→ - Move cursor\nR - Caps / Capslock\nX - Delete char\nY - Insert char\nA - Submit\nB - Cancel\n \nSELECT switches to\nclassic prompt";
const char* instr = STR_KEYBOARD_CONTROLS_DETAILS;
if (show_instr) {
ShowPrompt(false, "%s", instr);
show_instr = false;
Expand Down
5 changes: 3 additions & 2 deletions arm9/source/common/touchcal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ui.h"
#include "hid.h"
#include "crc16.h"
#include "language.h"
#include "spiflash.h"
#include "support.h"

Expand Down Expand Up @@ -46,8 +47,8 @@ bool ShowTouchCalibrationDialog(void)

// clear screen, draw instructions
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
DrawStringCenter(BOT_SCREEN, COLOR_STD_FONT, COLOR_STD_BG,
"Touch the red crosshairs to\ncalibrate your touchscreen.\n \nUse the stylus for best\nresults!");
DrawStringCenter(BOT_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, "%s",
STR_TOUCH_CROSSHAIRS_TO_CALIBRATE_TOUCHSCREEN_USE_STYLUS);

// set calibration defaults
SetCalibrationDefaults();
Expand Down
52 changes: 21 additions & 31 deletions arm9/source/common/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "power.h"
#include "hid.h"
#include "fixp.h"
#include "language.h"

#define STRBUF_SIZE 512 // maximum size of the string buffer
#define FONT_MAX_WIDTH 8
Expand Down Expand Up @@ -576,18 +577,13 @@ void ResizeString(char* dest, const char* orig, int nlength, int tpos, bool alig

if (nlength < olength) {
TruncateString(dest, orig, nlength, tpos);
} else if (!align_right) {
int nsize = 0;
for (int i = 0; i < nlength || (orig[nsize] & 0xC0) == 0x80; nsize++) {
if ((orig[nsize] & 0xC0) != 0x80) i++;
}
snprintf(dest, UTF_BUFFER_BYTESIZE(nlength), "%-*.*s", nsize, nsize, orig);
} else {
int nsize = 0;
for (int i = 0; i < nlength || (orig[nsize] & 0xC0) == 0x80; nsize++) {
if ((orig[nsize] & 0xC0) != 0x80) i++;
int osize = strnlen(orig, 256);
for (int i = 0; i < nlength || (nsize <= osize && (orig[nsize] & 0xC0) == 0x80); nsize++) {
if (nsize > osize || (orig[nsize] & 0xC0) != 0x80) i++;
}
snprintf(dest, UTF_BUFFER_BYTESIZE(nlength), "%*.*s", nsize, nsize, orig);
snprintf(dest, UTF_BUFFER_BYTESIZE(nlength), align_right ? "%*.*s" : "%-*.*s", nsize, nsize, orig);
}
}

Expand Down Expand Up @@ -625,20 +621,20 @@ void FormatNumber(char* str, u64 number) { // str should be 32 byte in size
for (; number / (mag1000 * 1000) > 0; mag1000 *= 1000);
for (; mag1000 > 0; mag1000 /= 1000) {
u32 pos = strnlen(str, 31);
snprintf(str + pos, 31 - pos, "%0*llu%c", (pos) ? 3 : 1, (number / mag1000) % 1000, (mag1000 > 1) ? ',' : '\0');
snprintf(str + pos, 31 - pos, "%0*llu%s", (pos) ? 3 : 1, (number / mag1000) % 1000, (mag1000 > 1) ? STR_THOUSAND_SEPARATOR : "");
}
}

void FormatBytes(char* str, u64 bytes) { // str should be 32 byte in size, just to be safe
const char* units[] = {" Byte", " kB", " MB", " GB"};
const char* units[] = {STR_BYTE, STR_KB, STR_MB, STR_GB};

if (bytes == (u64) -1) snprintf(str, 32, "INVALID");
if (bytes == (u64) -1) snprintf(str, 32, "%s", STR_INVALID);
else if (bytes < 1024) snprintf(str, 32, "%llu%s", bytes, units[0]);
else {
u32 scale = 1;
u64 bytes100 = (bytes * 100) >> 10;
for(; (bytes100 >= 1024*100) && (scale < 3); scale++, bytes100 >>= 10);
snprintf(str, 32, "%llu.%llu%s", bytes100 / 100, (bytes100 % 100) / 10, units[scale]);
snprintf(str, 32, "%llu%s%llu%s", bytes100 / 100, STR_DECIMAL_SEPARATOR, (bytes100 % 100) / 10, units[scale]);
}
}

Expand Down Expand Up @@ -720,7 +716,7 @@ bool ShowPrompt(bool ask, const char *format, ...)

ClearScreenF(true, false, COLOR_STD_BG);
DrawStringCenter(MAIN_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, "%s\n \n%s", str,
(ask) ? "(<A> yes, <B> no)" : "(<A> to continue)");
(ask) ? STR_A_YES_B_NO : STR_A_TO_CONTINUE);

while (true) {
u32 pad_state = InputWait(0);
Expand Down Expand Up @@ -775,7 +771,7 @@ bool ShowUnlockSequence(u32 seqlvl, const char *format, ...) {
ClearScreenF(true, false, color_bg);
DrawStringF(MAIN_SCREEN, x, y, color_font, color_bg, "%s", str);
#ifndef TIMER_UNLOCK
DrawStringF(MAIN_SCREEN, x, y + str_height - 28, color_font, color_bg, "To proceed, enter this:");
DrawStringF(MAIN_SCREEN, x, y + str_height - 28, color_font, color_bg, "%s", STR_TO_PROCEED_ENTER_THIS);

// generate sequence
const char *dpad_symbols[] = { "→", "←", "↑", "↓" }; // R L U D
Expand Down Expand Up @@ -812,7 +808,7 @@ bool ShowUnlockSequence(u32 seqlvl, const char *format, ...) {
lvl = 0;
}
#else
DrawStringF(MAIN_SCREEN, x, y + str_height - 28, color_font, color_bg, "To proceed, hold <X>:");
DrawStringF(MAIN_SCREEN, x, y + str_height - 28, color_font, color_bg, STR_TO_PROCEED_HOLD_X);

while (!CheckButton(BUTTON_B)) {
for (u32 n = 0; n < seqlen; n++) {
Expand Down Expand Up @@ -865,7 +861,7 @@ u32 ShowSelectPrompt(int n, const char** options, const char *format, ...) {

ClearScreenF(true, false, COLOR_STD_BG);
DrawStringF(MAIN_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
DrawStringF(MAIN_SCREEN, x, yopt + (n_show*(line_height+2)) + line_height, COLOR_STD_FONT, COLOR_STD_BG, "(<A> select, <B> cancel)");
DrawStringF(MAIN_SCREEN, x, yopt + (n_show*(line_height+2)) + line_height, COLOR_STD_FONT, COLOR_STD_BG, "%s", STR_A_SELECT_B_CANCEL);
while (true) {
for (int i = scroll; i < scroll+n_show; i++) {
DrawStringF(MAIN_SCREEN, x, yopt + ((line_height+2)*(i-scroll)), (sel == i) ? COLOR_STD_FONT : COLOR_LIGHTGREY, COLOR_STD_BG, "%2.2s %s",
Expand Down Expand Up @@ -944,7 +940,7 @@ u32 ShowFileScrollPrompt(int n, const DirEntry** options, bool hide_ext, const c

ClearScreenF(true, false, COLOR_STD_BG);
DrawStringF(MAIN_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
DrawStringF(MAIN_SCREEN, x, yopt + (n_show*(line_height+2)) + line_height, COLOR_STD_FONT, COLOR_STD_BG, "(<A> select, <B> cancel)");
DrawStringF(MAIN_SCREEN, x, yopt + (n_show*(line_height+2)) + line_height, COLOR_STD_FONT, COLOR_STD_BG, "%s", STR_A_SELECT_B_CANCEL);
while (true) {
for (int i = scroll; i < scroll+n_show; i++) {
char bytestr[16];
Expand All @@ -965,12 +961,12 @@ u32 ShowFileScrollPrompt(int n, const DirEntry** options, bool hide_ext, const c

DrawStringF(MAIN_SCREEN, x + item_width - font_width * 11, yopt + ((line_height+2)*(i-scroll)),
(sel == i) ? COLOR_STD_FONT : COLOR_ENTRY(options[i]), COLOR_STD_BG, "%10.10s",
(options[i]->type == T_DIR) ? "(dir)" : (options[i]->type == T_DOTDOT) ? "(..)" : bytestr);
(options[i]->type == T_DIR) ? STR_DIR : (options[i]->type == T_DOTDOT) ? "(..)" : bytestr);
}
// show [n more]
if (n - n_show - scroll > 0) {
char more_str[UTF_BUFFER_BYTESIZE(item_width / font_width)], temp_str[64];
snprintf(temp_str, 64, " [%d more]", (n - (n_show-1) - scroll));
snprintf(temp_str, 64, STR_N_MORE, (n - (n_show-1) - scroll));
ResizeString(more_str, temp_str, item_width / font_width, 8, false);
DrawString(MAIN_SCREEN, more_str, x, yopt + (line_height+2)*(n_show-1), COLOR_LIGHTGREY, COLOR_STD_BG);
}
Expand Down Expand Up @@ -1025,7 +1021,7 @@ u32 ShowHotkeyPrompt(u32 n, const char** options, const u32* keys, const char *f
ButtonToString(keys[i], buttonstr);
ptr += snprintf(ptr, STRBUF_SIZE - (ptr-str), "\n<%s> %s", buttonstr, options[i]);
}
ptr += snprintf(ptr, STRBUF_SIZE - (ptr-str), "\n \n<%s> %s", "B", "cancel");
ptr += snprintf(ptr, STRBUF_SIZE - (ptr-str), "\n \n<%s> %s", "B", STR_CANCEL);

ClearScreenF(true, false, COLOR_STD_BG);
DrawStringCenter(MAIN_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
Expand Down Expand Up @@ -1074,7 +1070,7 @@ bool ShowInputPrompt(char* inputstr, u32 max_size, u32 resize, const char* alpha
ClearScreenF(true, false, COLOR_STD_BG);
DrawStringF(MAIN_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
DrawStringF(MAIN_SCREEN, x + 8, y + str_height - 40, COLOR_STD_FONT, COLOR_STD_BG,
"R - (↑↓) fast scroll\nL - clear data%s", resize ? "\nX - remove char\nY - insert char" : "");
"%s\n%s", STR_R_FAST_SCROLL_L_CLEAR_DATA, resize ? STR_X_REMOVE_CHAR_Y_INSERT_CHAR : "");

// wait for all keys released
while (HID_ReadState() & BUTTON_ANY);
Expand Down Expand Up @@ -1423,12 +1419,12 @@ bool ShowProgress(u64 current, u64 total, const char* opstr)
ResizeString(progstr, tempstr, bar_width / FONT_WIDTH_EXT, 8, false);
DrawString(MAIN_SCREEN, progstr, bar_pos_x, text_pos_y, COLOR_STD_FONT, COLOR_STD_BG);
if (sec_elapsed >= 1) {
snprintf(tempstr, 16, "ETA %02llum%02llus", sec_remain / 60, sec_remain % 60);
snprintf(tempstr, 16, STR_ETA_N_MIN_N_SEC, sec_remain / 60, sec_remain % 60);
ResizeString(progstr, tempstr, 16, 8, true);
DrawString(MAIN_SCREEN, progstr, bar_pos_x + bar_width - 1 - (FONT_WIDTH_EXT * 16),
bar_pos_y - line_height - 1, COLOR_STD_FONT, COLOR_STD_BG);
}
DrawString(MAIN_SCREEN, "(hold B to cancel)", bar_pos_x + 2, text_pos_y + 14, COLOR_STD_FONT, COLOR_STD_BG);
DrawString(MAIN_SCREEN, STR_HOLD_B_TO_CANCEL, bar_pos_x + 2, text_pos_y + 14, COLOR_STD_FONT, COLOR_STD_BG);

last_prog_width = prog_width;

Expand All @@ -1441,13 +1437,7 @@ int ShowBrightnessConfig(int set_brightness)
u32 btn_input, bar_count;
int bar_x_pos, bar_y_pos, bar_width, bar_height;

const char *brightness_str =
"[←] Decrease brightness\n"
"[→] Increase brightness\n"
" \n"
"[X] Use volume slider control\n"
"[A] Set current brightness\n"
"[B] Cancel";
const char *brightness_str = STR_BRIGHTNESS_CONTROLS;
static const u16 brightness_slider_colmasks[] = {
COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_WHITE
};
Expand Down
25 changes: 13 additions & 12 deletions arm9/source/filesys/fsdrive.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "fsdrive.h"
#include "fsgame.h"
#include "fsinit.h"
#include "language.h"
#include "virtual.h"
#include "vcart.h"
#include "sddata.h"
Expand Down Expand Up @@ -84,13 +85,13 @@ bool GetFATVolumeLabel(const char* drv, char* label) {
}

bool GetRootDirContentsWorker(DirStruct* contents) {
static const char* drvname[] = { FS_DRVNAME };
const char* drvname[] = { FS_DRVNAME };
static const char* drvnum[] = { FS_DRVNUM };
u32 n_entries = 0;

char sdlabel[DRV_LABEL_LEN];
if (!GetFATVolumeLabel("0:", sdlabel) || !(*sdlabel))
strcpy(sdlabel, "NOLABEL");
strcpy(sdlabel, STR_LAB_NOLABEL);

char carttype[16];
GetVCartTypeString(carttype);
Expand All @@ -101,15 +102,15 @@ bool GetRootDirContentsWorker(DirStruct* contents) {
if (!DriveType(drvnum[i])) continue; // drive not available
entry->p_name = 4;
entry->name = entry->path + entry->p_name;
memset(entry->path, 0x00, 64);
memset(entry->path, 0x00, 256);
snprintf(entry->path, 4, "%s", drvnum[i]);
if ((*(drvnum[i]) >= '7') && (*(drvnum[i]) <= '9') && !(GetMountState() & IMG_NAND)) // Drive 7...9 handling
snprintf(entry->name, 32, "[%s] %s", drvnum[i],
(*(drvnum[i]) == '7') ? "FAT IMAGE" :
(*(drvnum[i]) == '8') ? "BONUS DRIVE" :
(*(drvnum[i]) == '9') ? "RAMDRIVE" : "UNK");
snprintf(entry->name, 252, "[%s] %s", drvnum[i],
(*(drvnum[i]) == '7') ? STR_LAB_FAT_IMAGE :
(*(drvnum[i]) == '8') ? STR_LAB_BONUS_DRIVE :
(*(drvnum[i]) == '9') ? STR_LAB_RAMDRIVE : "UNK");
else if (*(drvnum[i]) == 'G') // Game drive special handling
snprintf(entry->name, 32, "[%s] %s %s", drvnum[i],
snprintf(entry->name, 252, "[%s] %s %s", drvnum[i],
(GetMountState() & GAME_CIA ) ? "CIA" :
(GetMountState() & GAME_NCSD ) ? "NCSD" :
(GetMountState() & GAME_NCCH ) ? "NCCH" :
Expand All @@ -119,10 +120,10 @@ bool GetRootDirContentsWorker(DirStruct* contents) {
(GetMountState() & SYS_FIRM ) ? "FIRM" :
(GetMountState() & GAME_TAD ) ? "DSIWARE" : "UNK", drvname[i]);
else if (*(drvnum[i]) == 'C') // Game cart handling
snprintf(entry->name, 32, "[%s] %s (%s)", drvnum[i], drvname[i], carttype);
snprintf(entry->name, 252, "[%s] %s (%s)", drvnum[i], drvname[i], carttype);
else if (*(drvnum[i]) == '0') // SD card handling
snprintf(entry->name, 32, "[%s] %s (%s)", drvnum[i], drvname[i], sdlabel);
else snprintf(entry->name, 32, "[%s] %s", drvnum[i], drvname[i]);
snprintf(entry->name, 252, "[%s] %s (%s)", drvnum[i], drvname[i], sdlabel);
else snprintf(entry->name, 252, "[%s] %s", drvnum[i], drvname[i]);
entry->size = GetTotalSpace(entry->path);
entry->type = T_ROOT;
entry->marked = 0;
Expand Down Expand Up @@ -211,7 +212,7 @@ void SearchDirContents(DirStruct* contents, const char* path, const char* patter

void GetDirContents(DirStruct* contents, const char* path) {
if (*search_path && (DriveType(path) & DRV_SEARCH)) {
ShowString("Searching, please wait...");
ShowString("%s", STR_SEARCHING_PLEASE_WAIT);
SearchDirContents(contents, search_path, search_pattern, true);
ClearScreenF(true, false, COLOR_STD_BG);
} else if (title_manager_mode && (DriveType(path) & DRV_TITLEMAN)) {
Expand Down
20 changes: 10 additions & 10 deletions arm9/source/filesys/fsdrive.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
#define DRV_LABEL_LEN (36)

#define FS_DRVNAME \
"SDCARD", \
"SYSNAND CTRNAND", "SYSNAND TWLN", "SYSNAND TWLP", "SYSNAND SD", "SYSNAND VIRTUAL", \
"EMUNAND CTRNAND", "EMUNAND TWLN", "EMUNAND TWLP", "EMUNAND SD", "EMUNAND VIRTUAL", \
"IMGNAND CTRNAND", "IMGNAND TWLN", "IMGNAND TWLP", "IMGNAND VIRTUAL", \
"GAMECART", \
"GAME IMAGE", "AESKEYDB IMAGE", "BDRI IMAGE", "DISA/DIFF IMAGE", \
"MEMORY VIRTUAL", \
"VRAM VIRTUAL", \
"TITLE MANAGER", \
"LAST SEARCH" \
STR_LAB_SDCARD, \
STR_LAB_SYSNAND_CTRNAND, STR_LAB_SYSNAND_TWLN, STR_LAB_SYSNAND_TWLP, STR_LAB_SYSNAND_SD, STR_LAB_SYSNAND_VIRTUAL, \
STR_LAB_EMUNAND_CTRNAND, STR_LAB_EMUNAND_TWLN, STR_LAB_EMUNAND_TWLP, STR_LAB_EMUNAND_SD, STR_LAB_EMUNAND_VIRTUAL, \
STR_LAB_IMGNAND_CTRNAND, STR_LAB_IMGNAND_TWLN, STR_LAB_IMGNAND_TWLP, STR_LAB_IMGNAND_VIRTUAL, \
STR_LAB_GAMECART, \
STR_LAB_GAME_IMAGE, STR_LAB_AESKEYDB_IMAGE, STR_LAB_BDRI_IMAGE, STR_LAB_DISA_DIFF_IMAGE, \
STR_LAB_MEMORY_VIRTUAL, \
STR_LAB_VRAM_VIRTUAL, \
STR_LAB_TITLE_MANAGER, \
STR_LAB_LAST_SEARCH

#define FS_DRVNUM \
"0:", "1:", "2:", "3:", "A:", "S:", "4:", "5:", "6:", "B:", "E:", "7:", "8:", "9:", \
Expand Down
3 changes: 2 additions & 1 deletion arm9/source/filesys/fsgame.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "fsgame.h"
#include "fsperm.h"
#include "gameutil.h"
#include "language.h"
#include "tie.h"
#include "ui.h"
#include "vff.h"
Expand Down Expand Up @@ -39,7 +40,7 @@ bool GoodRenamer(DirEntry* entry, bool ask) {
TruncateString(oldname_tr, entry->name, 32, 8);
strncpy(newname_ww, goodname, 256);
WordWrapString(newname_ww, 32);
if (!ShowPrompt(true, "%s\nRename to good name?\n \n%s", oldname_tr, newname_ww))
if (!ShowPrompt(true, "%s\n%s\n \n%s", oldname_tr, STR_RENAME_TO_GOOD_NAME, newname_ww))
return true; // call it a success because user choice
}

Expand Down
Loading

0 comments on commit 93ee590

Please sign in to comment.