|
| 1 | +# Adding Translations |
| 2 | + |
| 3 | +## Setting up translation with Crowdin |
| 4 | + |
| 5 | +The scripts and workflows referenced here, as well as some sample `core_options` files, can be found in the [RetroArch translation example](https://github.com/libretro/RetroArch/tree/master/libretro-common/samples/core_options/example_translation). |
| 6 | + |
| 7 | +### Requirements |
| 8 | + |
| 9 | +Make sure the core is libretro conformant: |
| 10 | +both `libretro_core_options.h`, containing the English texts, and |
| 11 | +`libretro_core_options_intl.h`, containing all already existing |
| 12 | +translations, if any, must be present in the same directory. |
| 13 | + |
| 14 | +> Please note: `libretro_core_options_intl.h` does not need to contain |
| 15 | +anything, if no translations exist or none of them should be preserved. |
| 16 | + |
| 17 | +The scripts are not compatible with text filled in by macros or during run time. |
| 18 | +The procedure should not fail - but those texts will not be made translatable. |
| 19 | + |
| 20 | +Also, please verify the existence and correct use of |
| 21 | + |
| 22 | + `#ifdef HAVE_LANGEXTRA` |
| 23 | + |
| 24 | +and/or |
| 25 | + |
| 26 | + `#ifndef HAVE_NO_LANGEXTRA` |
| 27 | + |
| 28 | +pre-compiler instructions in `libretro_core_options.h` to remove any |
| 29 | +references to additional languages on platforms which cannot handle them, |
| 30 | +e.g. due to limited RAM. |
| 31 | +For an example, refer to an up-to-date core, like [gambatte-libretro](https://github.com/libretro/gambatte-libretro/blob/master/libgambatte/libretro/libretro_core_options.h). |
| 32 | + |
| 33 | +> Make sure `options_intl` in `libretro_core_options.h` correctly references the `_intl` options, or the translations will not be applied! |
| 34 | +
|
| 35 | +### Adding automatic Crowdin sync |
| 36 | + |
| 37 | +Place the `intl` and `.github` folders from the [sample folder](https://github.com/libretro/RetroArch/tree/master/libretro-common/samples/core_options/example_translation), including content, into the root |
| 38 | +of the repository. |
| 39 | + |
| 40 | +In `.github/workflows` are two files: `crowdin_prep.yml` & `crowdin_translate.yml`. |
| 41 | + |
| 42 | +In each of those are placeholders, which need to be replaced. |
| 43 | + |
| 44 | +For convenience, one can run `intl/activate.py`, which will try to find |
| 45 | +the `libretro_core_options.h` file as well as identify the core name to |
| 46 | +fill those placeholders with. |
| 47 | + |
| 48 | +Even then, one should still check if it produced the correct result: |
| 49 | + |
| 50 | +For `crowdin_prep.yml`: |
| 51 | +> **NOTE:** Please verify, that this workflow watches the correct branch (e.g. main, instead of master)! |
| 52 | +Uploads happen, whenever `libretro_core_options.h` of that branch is changed. |
| 53 | + |
| 54 | +- <PATH/TO/libretro_core_options.h FILE> (x2) |
| 55 | + - replace with the full path from the root of the repo to the |
| 56 | + `libretro_core_options.h` file |
| 57 | + |
| 58 | +- <CORE_NAME> |
| 59 | + - the name of the core (or repo) |
| 60 | + |
| 61 | +And for crowdin_translate.yml: |
| 62 | +- <0-59> <0-23> |
| 63 | + - Minute and hour at which the sync will happen. |
| 64 | + The script will generate a random time for this, to avoid |
| 65 | + stressing GitHub & Crowdin with many simultaneous runs. |
| 66 | + |
| 67 | +- <CORE_NAME> |
| 68 | + - same as above |
| 69 | + |
| 70 | +- <PATH/TO/libretro_core_options_intl.h FILE> (x2) |
| 71 | + - replace with the full path from the root of the repo to the |
| 72 | + 'libretro_core_options_intl.h' file |
| 73 | + |
| 74 | +Create a Pull Request and ask a Crowdin project manager, either on [Crowdin](https://crowdin.com/project/retroarch) or, preferably, on [Discord](https://ra-link.web.app/discord) in the `retroarch-translations` channel, to provide you with an access token. Create an Actions repository secret on GitHub named CROWDIN_API_KEY for this access token. |
| 75 | + |
| 76 | +<!-- TODO: set correct permissions https://github.com/marketplace/actions/github-push --> |
| 77 | +When everything is ready, run the "Crowdin Translations Initial Setup" workflow manually to upload the source texts and any translations to Crowdin. |
| 78 | + |
| 79 | +> You may either disable the initial workflow or even remove it from your repository. Running it more than once is very much discouraged! That may mess with the newest translations, which are usually not yet incorporated into the repository. |
| 80 | +
|
| 81 | +Finally, it is recommended to run the "Crowdin Translation Sync" workflow manually once. If a "Permission to \<repository> denied" error occurs, you might need to configure the GITHUB_TOKEN with the appropriate access rights, [see here](https://github.com/marketplace/actions/github-push#requirements-and-prerequisites). |
| 82 | + |
| 83 | +### (For Crowdin project managers) Creating an access token |
| 84 | + |
| 85 | +To create an access token, navigate to the account settings via your profile picture in the top right. Change to the API tab. Here you should find a `New Token` button. |
| 86 | + |
| 87 | +Name the token after the core/repository, which will receive it. The following permissions should be set: |
| 88 | + |
| 89 | +- Projects |
| 90 | + - read |
| 91 | +- Source files & strings |
| 92 | + - read & write |
| 93 | +- Translations |
| 94 | + - read & write |
| 95 | +- (optional) Translation status |
| 96 | + - read |
| 97 | + |
| 98 | +> Please provide these access tokens to the core developers in a private message and delete those after successful setup. Do not share tokens publicly or store them in plain text long term! |
| 99 | +
|
| 100 | +## Enabling new languages in cores |
| 101 | + |
| 102 | +Adding a language to RetroArch does not automatically enable it for the core options. To do that for cores which have been added to Crowdin, follow these steps: |
| 103 | + |
| 104 | +1. Locate the `libretro.h` file and add a `RETRO_LANGUAGE_XXXXX` item to the `retro_language` enum exactly the same as was done for RetroArch. |
| 105 | + - Alternatively, overwrite this file with the `libretro-common/include/libretro.h` file from RetroArch's code. |
| 106 | +2. Locate the `libretro_core_options.h` file and open it. |
| 107 | + - Add `&options_xx,` at the end of the `options_intl` struct. Remember to keep the same order as in the `retro_language` enum. |
| 108 | + |
| 109 | + |
| 110 | +### Example |
| 111 | + |
| 112 | +- mgba: |
| 113 | + - [Enable Indonesian, Swedish and Ukrainian localisations](https://github.com/libretro/mgba/commit/b0cdccc9ad2e5a8cd40ad4b9a3db1587d6f1560b) |
0 commit comments