| 1 | # [fheroes2](README.md) Translation Guide |
| 2 | |
| 3 | This project uses portable object (PO) files to handle localization in various languages. The PO files are located in the `files/lang` |
| 4 | subdirectory of the project source tree. The current instruction is designed for Linux, MacOS and Windows users. |
| 5 | |
| 6 | ## Current Status |
| 7 | |
| 8 |  |
| 9 |  |
| 10 |  |
| 11 |  |
| 12 |  |
| 13 |  |
| 14 |  |
| 15 |  |
| 16 |  |
| 17 |  |
| 18 |  |
| 19 |  |
| 20 |  |
| 21 |  |
| 22 |  |
| 23 |  |
| 24 |  |
| 25 |  |
| 26 |  |
| 27 |  |
| 28 |  |
| 29 |  |
| 30 |  |
| 31 | |
| 32 | ## Adding New Translations/Localizations |
| 33 | |
| 34 | If you want to add a new localization, you will first need to add it to the `SupportedLanguage` list/enumeration in the source code. |
| 35 | Afterwards, a new PO file for it will need to be added. It will have to be named according to the ISO standard's two-character |
| 36 | language abbreviations. Then to have font support, you will have to specify what font encoding/charset is compatible by adding |
| 37 | the language to the font generation code found in `src/fheroes2/gui/ui_font.cpp`. If a compatible font encoding has not currently |
| 38 | been implemented, then code for that will need to be written. |
| 39 | |
| 40 | ## Editing Translations - Before You Start |
| 41 | |
| 42 | Before starting, you will have to set up the necessary environment: fork the fheroes2 repository and install an application used |
| 43 | for translating. When you have your own fork of fheroes2 you should create a branch. At this point you can start translating. |
| 44 | After you finish your work, and you are ready to share it, you will have to prepare a pull request. |
| 45 | |
| 46 | ### Forking the fheroes2 Repository |
| 47 | |
| 48 | A fork is your copy of the fheroes2 repository. It gives you a safe environment to prepare and test your changes. |
| 49 | You can read here how to [**create a fork**](https://docs.github.com/en/get-started/quickstart/fork-a-repo). |
| 50 | |
| 51 | ### Translation Editing Software |
| 52 | |
| 53 | We encourage you to use [**poedit**](https://poedit.net/) or [**gtranslator**](https://wiki.gnome.org/Apps/Gtranslator) to |
| 54 | edit translations. Currently all implemented languages adhere to a standardized font encoding/charset. |
| 55 | |
| 56 | ## Editing Translations - For the First Time or Again |
| 57 | |
| 58 | ### Syncing Your Fork |
| 59 | |
| 60 | Before you start working on the first or next translation, make sure that your fork has all the recent changes from the fheroes2 repo. |
| 61 | To do this, [**sync your fork**](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork). |
| 62 | |
| 63 | ### Creating a Branch |
| 64 | |
| 65 | Next you will set up an environment for working on your translation, in addition to testing and sharing your changes. |
| 66 | Read more [**about branches**](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches). |
| 67 | |
| 68 | To create a branch, please follow GitHub's instructions on |
| 69 | [**creating a branch within your repo**](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-and-deleting-branches-within-your-repository). |
| 70 | |
| 71 | ### Submitting Translations |
| 72 | |
| 73 | Finally you will use your translation software of choice to make changes to the translation. All original translatable strings are |
| 74 | located in the source code of the project. If you need to clarify where this string is being used you can search for it. |
| 75 | The string below, for example, can be translated in PO files: |
| 76 | |
| 77 | ```cpp |
| 78 | _( "Are you sure you want to quit?" ) |
| 79 | ``` |
| 80 | |
| 81 | ### Testing Your Changes |
| 82 | |
| 83 | Once the translation files have been modified, for Linux/MacOS run the `make` command below in the `files/lang` subdirectory to create |
| 84 | machine object (MO) binary files which can be used by the fheroes2 engine. |
| 85 | |
| 86 | For example, for the German PO file, `de.po`, the following would be the command: |
| 87 | |
| 88 | ```bash |
| 89 | make de.mo |
| 90 | ``` |
| 91 | |
| 92 | To make the engine use this MO, the file should be placed in the `files/lang` folder used by the fheroes2 executable. |
| 93 | The exact location of this folder depends on the operating system. |
| 94 | |
| 95 | On Windows, it is usually located in the app installation directory. |
| 96 | |
| 97 | On Linux, it is usually located in the `/usr/share/fheroes2` or `/usr/local/share/fheroes2`. |
| 98 | |
| 99 | Currently for MacOS users this location is dependent on what third-party package manager is used to install fheroes2. |
| 100 | |
| 101 | The Flatpak version of the fheroes2 installation from Flathub is located in the `usr/.var/app/io.github.ihhub.Fheroes2` directory. |
| 102 | |
| 103 | For Windows users who use POEdit or a similar application, it is possible to compile the MO file using said program. However, note that |
| 104 | the program will need to be set to compile the MO file in the font encoding/charset that the language that you are translating to has been |
| 105 | set to. |
| 106 | |
| 107 | For example, for German you will have to set font encoding to CP1252, while for Russian this would be CP1251. Later when submitting |
| 108 | a pull request with your changes, you will have to save the PO file in UTF-8 encoding because this is what Github supports. |
| 109 | |
| 110 | ### Sharing Your Translation Work |
| 111 | |
| 112 | When you are satisfied with your work, you can proceed with sharing it. The first step is to commit your work into the branch you made of |
| 113 | your own fheroes2 fork. Then, create a pull request that proposes to introduce your changes into the fheroes2 repository. |
| 114 | |
| 115 | How to [**commit**](https://github.com/git-guides/git-commit). |
| 116 | |
| 117 | How to [**create a pull request from your fork**](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork). |
| 118 | |
| 119 | The pull request title has to be something human-understandable. This allows the team to quickly identify the purpose of |
| 120 | your work, I.E. "Update the Slovak translation". |
| 121 | |
| 122 | ### Pull request restrictions - Please read |
| 123 | |
| 124 | The fheroes2 team has set a maximum of 400 total modified lines for any pull request for translations. For contributors wanting to |
| 125 | add translated lines to a new language this has a maximum of 30 total modified lines for that first pull request. |
| 126 | |
| 127 | These limitations have been set because every pull request needs to be reviewed by our team, and so changing too many lines at once will only slow this |
| 128 | process down. In addition, GitHub becomes increasingly difficult to navigate once too many changes, comments and so on are present within the |
| 129 | same pull request page, further slowing down the process of reviewing it. |
| 130 | |
| 131 | Furthermore, we have decided on a minimum amount of 15 changed strings for a translation pull request. For languages that have translations that are more |
| 132 | or less complete, less than this amount can be accepted. |
| 133 | |
| 134 | Preferably a pull request should contain a small amount of changes, about 100 lines, all focused on translating a specific part of the game - for |
| 135 | example creature names or castle buildings. |
| 136 | |
| 137 | ## Updating PO Templates and Translatable Strings in PO Files |
| 138 | |
| 139 | Currently all PO files are automatically updated with new strings after each commit that brings changes to the ingame text. If for whatever reason |
| 140 | you still need to update strings locally, this can be achieved by running the command below in `src/dist/fheroes2` to generate a new portable object |
| 141 | template (POT) file. Windows users will need to set up an environment that lets them run `make`, like Windows Subsystem for Linux (WSL) or |
| 142 | [**Cygwin**](https://www.cygwin.com/)/[**MSYS2**](https://www.msys2.org/). |
| 143 | |
| 144 | ```bash |
| 145 | make pot |
| 146 | ``` |
| 147 | |
| 148 | Once the POT file has been created, go to the `files/lang` folder and run the command below to update translatable strings in the PO files. |
| 149 | |
| 150 | ```bash |
| 151 | make merge |
| 152 | ``` |
| 153 | |
| 154 | If you are using programs mentioned above like POEdit, then they have options to merge new strings from a POT file. |