Skip to content

Commit 19ef874

Browse files
authored
Extract translation sources and upload them to Crowdin at each commit on master (#3114)
* Extract but without upload for other branches Don't show in changelog
1 parent 567efaf commit 19ef874

8 files changed

+108
-14
lines changed
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# GitHub Action to extract translations and (later) upload them to Crowdin.
2+
3+
name: Extract translations
4+
on:
5+
# Execute for all commits (to ensure translations extraction works)
6+
push:
7+
# Allows to run this workflow manually from the Actions tab.
8+
workflow_dispatch:
9+
10+
jobs:
11+
extract-translations:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
# Cache npm dependencies to speed up the workflow
17+
- name: Cache node modules
18+
uses: actions/cache@v2
19+
env:
20+
cache-name: cache-newIDE-app-node_modules
21+
with:
22+
# npm cache files are stored in `~/.npm` on Linux/macOS
23+
path: ~/.npm
24+
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('newIDE/app/package-lock.json') }}
25+
26+
- name: Install gettext
27+
run: sudo apt update && sudo apt install gettext -y
28+
29+
- name: Install newIDE dependencies
30+
run: npm install
31+
working-directory: newIDE/app
32+
33+
- name: Extract translations
34+
run: npm run extract-all-translations
35+
working-directory: newIDE/app
36+
37+
# Only upload on Crowdin for the master branch
38+
- name: Install Crowdin CLI
39+
if: github.ref == 'refs/heads/master'
40+
run: npm i -g @crowdin/cli
41+
42+
- name: Upload translations to Crowdin
43+
run: crowdin upload sources
44+
if: github.ref == 'refs/heads/master'
45+
env:
46+
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
47+
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}

crowdin.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'project_id_env': 'CROWDIN_PROJECT_ID'
2+
'api_token_env': 'CROWDIN_PERSONAL_TOKEN'
3+
'base_path': '.'
4+
'base_url': 'https://api.crowdin.com'
5+
6+
# Flatten files in Crowdin
7+
'preserve_hierarchy': false
8+
9+
# "Source" files, which are .POT files extracted from the source code.
10+
# The built files are .PO files that are the compiled by `compile-translations`
11+
# script in `newIDE/app/scripts`.
12+
files:
13+
[
14+
{
15+
'source': 'newIDE/app/src/locales/en/ide-messages.pot',
16+
'translation': 'newIDE/app/src/locales/%locale_with_underscore%/ide-messages.po',
17+
},
18+
{
19+
'source': 'scripts/gdcore-gdcpp-gdjs-extensions-messages.pot',
20+
'translation': 'newIDE/app/src/locales/%locale_with_underscore%/gdcore-gdcpp-gdjs-extensions-messages.po',
21+
},
22+
]

newIDE/app/package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

newIDE/app/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"@storybook/addon-essentials": "6.3.8",
1111
"@storybook/react": "6.3.8",
1212
"axios-mock-adapter": "^1.19.0",
13+
"babel-core": "^7.0.0-bridge.0",
1314
"babel-loader": "8.0.6",
1415
"flow-bin": "0.131.0",
1516
"flow-coverage-report": "^0.4.0",

newIDE/app/package.json.README.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ GDevelop relies on some dependencies that can have special requirements:
1010
- `babel-loader` is specified to be the exact version required by `react-scripts` (because `react-scripts` wants the exact version and will complain if forced to use the `babel-loader` of Storybook).
1111
- **Try removing these extra `devDependencies`** if you upgrade Storybook or Create React App.
1212

13+
- `"babel-core": "^7.0.0-bridge.0"` is needed for js-lingui `lingui extract` command (who runs Babel on source files).
14+
1315
- **`react-dnd`** is used by `react-mosaic-component` and `react-sortable-tree` (but not `react-sortable-hoc`). Both must be using **the same versions** of `react-dnd` and `react-dnd-html5-backend`. Otherwise, you get blanks/not rendered components.
1416

1517
> You can check if there is only one version of a package by doing `npm ls` or `yarn why`:

newIDE/app/scripts/extract-all-translations.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,29 @@ let hasErrors = false;
1212
// Clean existing English messages catalog, if any
1313
const enMessagesJsPath = path.join(newIdeAppPath, 'src/locales/en/messages.js');
1414
if (fs.existsSync(enMessagesJsPath)) {
15-
shell.echo(`ℹ️ Removing ${enMessagesJsPath} as "en" should not have any translations ("pot" file)`);
15+
shell.echo(
16+
`ℹ️ Removing ${enMessagesJsPath} as "en" should not have any translations ("pot" file)`
17+
);
1618
shell.rm(enMessagesJsPath);
1719
}
18-
const enIdeMessagesPotPath = path.join(newIdeAppPath, 'src/locales/en/ide-messages.pot');
20+
const enIdeMessagesPotPath = path.join(
21+
newIdeAppPath,
22+
'src/locales/en/ide-messages.pot'
23+
);
1924
if (fs.existsSync(enIdeMessagesPotPath)) {
20-
shell.echo(`ℹ️ Removing ${enIdeMessagesPotPath} as "en" should not have any translations ("pot" file)`);
25+
shell.echo(
26+
`ℹ️ Removing ${enIdeMessagesPotPath} as "en" should not have any translations ("pot" file)`
27+
);
2128
shell.rm(enIdeMessagesPotPath);
2229
}
2330

2431
// Launch "lingui extract" for extracting newIDE translations
2532
shell.echo('ℹ️ Extracting translations for newIDE...');
2633

27-
hasErrors |= shell.exec(
28-
'node node_modules/.bin/lingui extract --clean --overwrite',
29-
{
34+
hasErrors |=
35+
shell.exec('node node_modules/.bin/lingui extract --clean --overwrite', {
3036
cwd: newIdeAppPath,
31-
}
32-
).stderr;
37+
}).code !== 0;
3338

3439
shell.echo('ℹ️ Renaming extracted translations to ide-messages.po...');
3540
getLocales().then(locales =>
@@ -53,17 +58,20 @@ shell.echo(
5358
'ℹ️ Extracting translations for GDCore/GDJS/Extensions to scripts/gdcore-gdcpp-gdjs-extensions-messages.pot...'
5459
);
5560
if (isWin) {
56-
hasErrors |= shell.exec('ExtractTranslations.bat', {
57-
cwd: gdScriptsPath,
58-
}).stderr;
61+
hasErrors |=
62+
shell.exec('ExtractTranslations.bat', {
63+
cwd: gdScriptsPath,
64+
}).code !== 0;
5965
} else {
60-
hasErrors |= shell.exec('./ExtractTranslations.sh ', {
61-
cwd: gdScriptsPath,
62-
}).stderr;
66+
hasErrors |=
67+
shell.exec('./ExtractTranslations.sh ', {
68+
cwd: gdScriptsPath,
69+
}).code !== 0;
6370
}
6471

6572
if (!hasErrors) {
6673
shell.echo('✅ Translations extracted');
6774
} else {
6875
shell.echo(`❌ Error(s) occurred while extracting translations`);
76+
shell.exit(1);
6977
}

newIDE/app/yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -4677,6 +4677,11 @@ babel-code-frame@^6.22.0:
46774677
esutils "^2.0.2"
46784678
js-tokens "^3.0.2"
46794679

4680+
babel-core@^7.0.0-bridge.0:
4681+
version "7.0.0-bridge.0"
4682+
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece"
4683+
integrity sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==
4684+
46804685
babel-eslint@10.0.3:
46814686
version "10.0.3"
46824687
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.0.3.tgz#81a2c669be0f205e19462fed2482d33e4687a88a"

scripts/ExtractTranslations.sh

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#Launch this script to generate the .POT file used
22
#to update the strings to be translated.
3+
set -e
4+
35
echo "ℹ️ Listing all GDCore, GDJS and Extensions sources files to translate..."
46

57
find ../GDJS/GDJS/ -name '*.cpp' | grep -v '/Dialogs/' > /tmp/listfile.txt
@@ -22,4 +24,5 @@ if type $GETTEXT 2>/dev/null; then
2224
echo "ℹ️ Translation file 'gdcore-gdcpp-gdjs-extensions-messages.pot' generated and ready to be sent to Crowdin or used in a translation software like PoEdit."
2325
else
2426
echo "❌ Unable to find xgettext on your system."
27+
exit 1
2528
fi

0 commit comments

Comments
 (0)