Skip to content

Commit 7b4a99c

Browse files
rapha-techducalex
andauthored
Adding Localization support (#159)
* Innitial commit Localization for retro-go using a simple 0(n) lookup function called rg_gettext() * adding language settings in options menu * adding more gettext() * new lookup function * adding "For these changes to take effect you must restart your device." gui alert + fixing gettext() function * modifying the gui dialog * updating struct syntax * update struct syntax (again) * creating the python tool for localization * updating tool + adding missing translations * moving stuff to libs + starting writing readme * adding missing "libs/localization" folder import in cmakelist + added the "fixme for rg_system" * synthax adjust + moving back stuff from libs to retro-go * removing trailing spaces * adding the enum for language ids * updating documentation according to the latest changes * small tweaks * Moved LOCALIZATION.md to the root folder Whilst it is mostly relevant to libretro-go, it really is project-wide documentation. * rg_localization: Got rid of the switch, made GUI dynamic This makes adding a language more straightforward. I kept the *msg *fr *en for now to avoid updating translations.h, but it could be replaced by the GCC extension as such: [RG_LANG_EN] = "...", [RG_LANG_FR] = "...", So that adding a language is really just updating the enum... * rg_localization: translations is const, we can use RG_COUNT * rg_gui: Fixed language selection * rg_localization: No need to validate rg_language in rg_gettext It should always be valid, there's no need to validate it. * rg_gui: Show language name in the log * rg_localization: Got rid of the Translation struct I am not 100% positive this is a good move... Benefits: - One less thing to change when adding a language - Less code is always better Cons: - It doesn't make it clear what the "key" is (the english text) - If in the future we need to add things like flags it will have to be returned to a struct * updated python tool + updating translations * added missing translations * audio filter wrong translation * fix : "a propose de retro-go" --------- Co-authored-by: Alex Duchesne <[email protected]>
1 parent a1d5d9e commit 7b4a99c

25 files changed

+1283
-199
lines changed

LOCALIZATION.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
This document describes the localization protocol used in Retro-go
2+
3+
4+
# C files
5+
translation.h contains the original messages (in english) and the corresponding translations ex:
6+
````c
7+
{
8+
[RG_LANG_EN] = "Yes",
9+
[RG_LANG_FR] = "Oui",
10+
[RG_LANG_ES] = "Si",
11+
},
12+
````
13+
14+
If you want to add your own language :
15+
16+
You should update the enum accordingly (in rg_localization.h):
17+
````c
18+
typedef enum
19+
{
20+
RG_LANG_EN,
21+
RG_LANG_FR,
22+
23+
RG_LANG_ES, // <-- to add spanish translation
24+
25+
RG_LANG_MAX
26+
} rg_language_t;
27+
````
28+
29+
30+
# Python tool
31+
`rg_locate_str.py` is a simple python tool that locate every string preceded by `_("` pattern in each file of Retro-go project
32+
Then the tool compare theses strings to the ones in `translations.h` and put the missing ones in a .txt file called missing_translation.txt

components/retro-go/libs/netplay/rg_netplay.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,19 @@ void rg_netplay_init(netplay_callback_t callback)
360360

361361
bool rg_netplay_quick_start(void)
362362
{
363-
const char *status_msg = "Initializing...";
363+
const char *status_msg = _("Initializing...");
364364
const char *screen_msg = NULL;
365365
// int timeout = 100;
366366

367367
rg_display_clear(0);
368368

369369
const rg_gui_option_t options[] = {
370-
{1, "Host Game (P1)", NULL, RG_DIALOG_FLAG_NORMAL, NULL},
371-
{2, "Find Game (P2)", NULL, RG_DIALOG_FLAG_NORMAL, NULL},
370+
{1, _("Host Game (P1)"), NULL, RG_DIALOG_FLAG_NORMAL, NULL},
371+
{2, _("Find Game (P2)"), NULL, RG_DIALOG_FLAG_NORMAL, NULL},
372372
RG_DIALOG_END
373373
};
374374

375-
int ret = rg_gui_dialog("Netplay", options, 0);
375+
int ret = rg_gui_dialog(_("Netplay"), options, 0);
376376

377377
if (ret == 1)
378378
rg_netplay_start(NETPLAY_MODE_HOST);
@@ -387,31 +387,31 @@ bool rg_netplay_quick_start(void)
387387
{
388388
case NETPLAY_STATUS_CONNECTED:
389389
return remote_player->game_id == local_player->game_id
390-
|| rg_gui_confirm("Netplay", "ROMs not identical. Continue?", 1);
390+
|| rg_gui_confirm(_("Netplay"), _("ROMs not identical. Continue?"), 1);
391391
break;
392392

393393
case NETPLAY_STATUS_HANDSHAKE:
394-
status_msg = "Exchanging info...";
394+
status_msg = _("Exchanging info...");
395395
break;
396396

397397
case NETPLAY_STATUS_CONNECTING:
398-
status_msg = "Connecting...";
398+
status_msg = _("Connecting...");
399399
break;
400400

401401
case NETPLAY_STATUS_DISCONNECTED:
402-
status_msg = "Unable to find host!";
402+
status_msg = _("Unable to find host!");
403403
break;
404404

405405
case NETPLAY_STATUS_STOPPED:
406-
status_msg = "Connection failed!";
406+
status_msg = _("Connection failed!");
407407
break;
408408

409409
case NETPLAY_STATUS_LISTENING:
410-
status_msg = "Waiting for peer...";
410+
status_msg = _("Waiting for peer...");
411411
break;
412412

413413
default:
414-
status_msg = "Unknown status...";
414+
status_msg = _("Unknown status...");
415415
}
416416

417417
if (screen_msg != status_msg)

0 commit comments

Comments
 (0)