Skip to content

Commit

Permalink
Adding Localization support (#159)
Browse files Browse the repository at this point in the history
* 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 <ducalex007@gmail.com>
  • Loading branch information
raphatex and ducalex authored Nov 16, 2024
1 parent a1d5d9e commit 7b4a99c
Show file tree
Hide file tree
Showing 25 changed files with 1,283 additions and 199 deletions.
32 changes: 32 additions & 0 deletions LOCALIZATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
This document describes the localization protocol used in Retro-go


# C files
translation.h contains the original messages (in english) and the corresponding translations ex:
````c
{
[RG_LANG_EN] = "Yes",
[RG_LANG_FR] = "Oui",
[RG_LANG_ES] = "Si",
},
````

If you want to add your own language :

You should update the enum accordingly (in rg_localization.h):
````c
typedef enum
{
RG_LANG_EN,
RG_LANG_FR,

RG_LANG_ES, // <-- to add spanish translation

RG_LANG_MAX
} rg_language_t;
````


# Python tool
`rg_locate_str.py` is a simple python tool that locate every string preceded by `_("` pattern in each file of Retro-go project
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
22 changes: 11 additions & 11 deletions components/retro-go/libs/netplay/rg_netplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,19 +360,19 @@ void rg_netplay_init(netplay_callback_t callback)

bool rg_netplay_quick_start(void)
{
const char *status_msg = "Initializing...";
const char *status_msg = _("Initializing...");
const char *screen_msg = NULL;
// int timeout = 100;

rg_display_clear(0);

const rg_gui_option_t options[] = {
{1, "Host Game (P1)", NULL, RG_DIALOG_FLAG_NORMAL, NULL},
{2, "Find Game (P2)", NULL, RG_DIALOG_FLAG_NORMAL, NULL},
{1, _("Host Game (P1)"), NULL, RG_DIALOG_FLAG_NORMAL, NULL},
{2, _("Find Game (P2)"), NULL, RG_DIALOG_FLAG_NORMAL, NULL},
RG_DIALOG_END
};

int ret = rg_gui_dialog("Netplay", options, 0);
int ret = rg_gui_dialog(_("Netplay"), options, 0);

if (ret == 1)
rg_netplay_start(NETPLAY_MODE_HOST);
Expand All @@ -387,31 +387,31 @@ bool rg_netplay_quick_start(void)
{
case NETPLAY_STATUS_CONNECTED:
return remote_player->game_id == local_player->game_id
|| rg_gui_confirm("Netplay", "ROMs not identical. Continue?", 1);
|| rg_gui_confirm(_("Netplay"), _("ROMs not identical. Continue?"), 1);
break;

case NETPLAY_STATUS_HANDSHAKE:
status_msg = "Exchanging info...";
status_msg = _("Exchanging info...");
break;

case NETPLAY_STATUS_CONNECTING:
status_msg = "Connecting...";
status_msg = _("Connecting...");
break;

case NETPLAY_STATUS_DISCONNECTED:
status_msg = "Unable to find host!";
status_msg = _("Unable to find host!");
break;

case NETPLAY_STATUS_STOPPED:
status_msg = "Connection failed!";
status_msg = _("Connection failed!");
break;

case NETPLAY_STATUS_LISTENING:
status_msg = "Waiting for peer...";
status_msg = _("Waiting for peer...");
break;

default:
status_msg = "Unknown status...";
status_msg = _("Unknown status...");
}

if (screen_msg != status_msg)
Expand Down
Loading

0 comments on commit 7b4a99c

Please sign in to comment.