Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n #825

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from
Draft

i18n #825

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e261de0
implement tinygettext for localization
Nats-ji May 21, 2023
895f253
add language option
Nats-ji May 23, 2023
101add9
add language setting gui, rework i18n class
Nats-ji May 29, 2023
0722b61
add language setting implementation
Nats-ji May 30, 2023
877afe8
expose locale settings to mods
Nats-ji May 30, 2023
d033225
mark translatable strings
Nats-ji May 30, 2023
194ec50
add gettext tools and xmake script
Nats-ji May 30, 2023
a53bb1b
generated pot file and en.po, translated to zh_CN
Nats-ji May 30, 2023
7c67d89
fix typo, reorgnized gettext script
Nats-ji May 31, 2023
d4e8e78
Update Crowdin configuration file
Nats-ji May 30, 2023
db797e6
Update Crowdin configuration file
Nats-ji May 30, 2023
9170ce9
Update Crowdin configuration file
Nats-ji May 30, 2023
3cf047b
update crowdin config
Nats-ji May 31, 2023
2b00785
[ci skip] update crowdin config
Nats-ji May 31, 2023
411a32e
Update Crowdin configuration file
Nats-ji May 31, 2023
fd415d5
New translations template.pot (Japanese)
Nats-ji May 30, 2023
107fbd2
New translations template.pot (Chinese Simplified)
Nats-ji May 30, 2023
0e25f4f
New translations template.pot (Chinese Traditional)
Nats-ji May 30, 2023
eb89cac
New translations template.pot (Chinese Simplified)
Nats-ji May 30, 2023
87ebbb1
New translations en.po (Japanese)
Nats-ji May 30, 2023
b9aa007
New translations en.po (Chinese Simplified)
Nats-ji May 30, 2023
7e49ad3
New translations en.po (Chinese Traditional)
Nats-ji May 30, 2023
3f57012
New translations template.pot (Japanese)
Nats-ji May 30, 2023
4f1af25
New translations template.pot (Chinese Simplified)
Nats-ji May 30, 2023
4846e4c
New translations template.pot (Chinese Traditional)
Nats-ji May 30, 2023
95decf8
New translations template.pot (Chinese Traditional)
Nats-ji May 30, 2023
e332057
New translations template.pot (Japanese)
Nats-ji May 31, 2023
49224c7
New translations template.pot (Japanese)
Nats-ji May 31, 2023
94f33bd
New translations template.pot (Japanese)
Nats-ji May 31, 2023
ca614b1
New translations template.pot (Chinese Simplified)
Nats-ji May 31, 2023
fa5c53c
New translations template.pot (Chinese Traditional)
Nats-ji May 31, 2023
b129b71
New translations template.pot (Japanese)
Nats-ji May 31, 2023
b237f36
New translations template.pot (Chinese Simplified)
Nats-ji May 31, 2023
6230baa
New translations template.pot (Chinese Traditional)
Nats-ji May 31, 2023
c203d0f
[ci skip] update crowdin config
Nats-ji May 31, 2023
34c4d87
Fix language code in crowdin config
Nats-ji Jun 20, 2023
98ed1dc
add a button to reload language files
Nats-ji Jul 1, 2023
b928d3a
retain window size and pos after language change
Nats-ji Jul 1, 2023
d33d609
add translation instructions
Nats-ji Jul 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "vendor/luasocket"]
path = vendor/luasocket
url = https://github.com/diegonehab/luasocket.git
[submodule "vendor/tinygettext"]
path = vendor/tinygettext
url = https://github.com/tinygettext/tinygettext.git
39 changes: 38 additions & 1 deletion ThirdParty_LICENSES
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,41 @@ and desktop fonts contain some icons that are redistributed under the Apache
licenses or are distributed under the Apache 2.0 license.

# Code: MIT (https://opensource.org/licenses/MIT)
The MIT license applies to all non-font and non-icon files.
The MIT license applies to all non-font and non-icon files.

================== tinygettext ================

tinygettext - A gettext replacement that works directly on .po files

Copyright (c) 2004-2016

* Bastiaan Zapf <[email protected]>
* Christoph Sommer <[email protected]>
* Georg Kilzer (leper) <[email protected]>
* Ingo Ruhnke <[email protected]>
* Mathnerd314 <[email protected]>
* Matt McCutchen <[email protected]>
* Matthias Braun <[email protected]>
* Nathan Phillip Brink <[email protected]>
* Poren Chiang <[email protected]>
* Ravu al Hemio <[email protected]>
* Ryan Flegel <[email protected]>
* Tim Goya <[email protected]>
* Tobias Markus <[email protected]>
* Wolfgang Becker <[email protected]>

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgement in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
92 changes: 92 additions & 0 deletions Translation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Translation

Instructions on how to create and update the language files for CET.

## For translators

The language files have the extension name of ".po". The file names are generally using [two-letter language codes](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. en, fr, de). For languages that have different writing systems or to differentiate by country, the file name needs to be a locale with an underscore (e.g. zh_CN, zh_TW).

### Use Crowdin

Todo


### Use commandline scripts:

### Create a new language file
To create a new language, use the following command:
```sh
xmake i18n-po create filename
```
This will generate a new po file under the `languages/` directory. Make sure the filename follows the rules above. Otherwise, the language name won't be parsed by CET correctly.

### Update the language files
To update those files, use the following command:
```sh
xmake i18n-po update
```
This will add new translatable strings from `template.pot` file to all `.po` files.

### Edit the language files
To edit the language files, you can either edit them on Crowdin or open them in a text editor or a PO editor.

### Test the translations
You can reload the translations from `Settings->CET Development Settings->Reload translation`.

If you are editing the language files from the project directory. Use the following command to copy the language files to your game directory:
```sh
xmake i18n-install
```

## Format

The language files are using the GNU gettext PO format. Detailed documentation can be found [here](https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html).
```po
white-space
# translator-comments
#. extracted-comments
#: reference…
#, flag…
#| msgid previous-untranslated-string
msgid untranslated-string
msgstr translated-string
```
## For developers

There are two macros you can use the mark the translatable strings.

To translate normal strings, use:
```cpp
_t("This string will be translated.");
```

To translate strings with plural forms:
```cpp
_t("There is %d apple.", "There are %d apples.", number);
```

If you have strings inside a container that you want to translate. You can use the `_noop("string")` to mark it for translation. For example:
```cpp
std::vector<std::string> fruits = {
_noop("apple"),
_noop("banana"),
_noop("orange")
};

for (const auto& fruit : list)
{
Log::Info(_t(fruit));
}
```

Always remember to update the `template.pot` file before you commit the changes you made to the translatable strings. So translators can start to work on updating the translations.

### Update the template file

The template file `template.pot` is auto-generated from the source files. It includes all the translatable strings in the source files.

To update this file, use the following command:
```sh
xmake i18n-pot
```
This will also auto-update the `en.po` file. `en.po` is always auto-generated from the template file, so there's no need to edit it.
10 changes: 10 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pull_request_title: Update Translation
commit_message: '[ci skip]'
files:
- source: /languages/template.pot
translation: /languages/%two_letters_code%.po
update_option: update_as_unapproved
languages_mapping:
two_letters_code:
zh-CN: zh_CN
zh-TW: zh_TW
Loading