Skip to content

Commit

Permalink
Merge pull request #188 from RodriSanchez1/CrowdinGithubActions
Browse files Browse the repository at this point in the history
Add Github Actions to update and dowloand Crowdin translations
  • Loading branch information
RodriSanchez1 authored Aug 12, 2024
2 parents 25baf01 + 43303fe commit d356652
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/DownloadCrowdinTranslations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Download Crowdin translations

on:
workflow_dispatch:
# pull_request:

permissions:
contents: write
pull-requests: write

jobs:
pre_translate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Compile intl TypeScript files
run: npx -p typescript tsc --project src/intl/intl.tsconfig.json

- name: Get Supported Locales
id: get_locales
run: |
supportedLocales=$(node src/intl/dist/scripts/getSupportedLocales.js)
echo "supportedLocales=$supportedLocales" >> $GITHUB_ENV
- name: Pre-translate
uses: crowdin/github-action@v2
with:
command: 'pre-translate'
command_args: '--method mt ${{ env.supportedLocales }} --file cbuilder/src/intl/cbuilder.json --engine-id ${{ vars.CROWDIN_MT_ID }} --verbose'
env:
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}

create_pr:
runs-on: ubuntu-latest
needs: pre_translate
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Synchronize with Crowdin
uses: crowdin/github-action@v2
with:
upload_sources: false
upload_translations: false
download_translations: true
localization_branch_name: l10n_crowdin_translations

create_pull_request: true
pull_request_title: 'New Crowdin translations'
pull_request_body: 'New Crowdin pull request with translations'
pull_request_base_branch_name: 'main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/UploadSourceFileToCrowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Upload source file to Crowdin

on:
push:
paths: ['src/intl/cbuilder.json']
branches: [main]
pull_request:
workflow_dispatch:

jobs:
crowdin-upload-sources:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Crowdin push
uses: crowdin/github-action@v2
with:
upload_sources: true
upload_translations: false
download_translations: false
env:
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# production
/build
/src/intl/dist

# misc
.DS_Store
Expand Down
16 changes: 16 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'project_id_env': 'CROWDIN_PROJECT_ID'
'api_token_env': 'CROWDIN_PERSONAL_TOKEN'
'base_path': './src/intl'
'base_url': 'https://api.crowdin.com'

'preserve_hierarchy': true

files:
[
{
'source': '/cbuilder.json',
'translation': '/dictionaries/%locale%.json',
'dest': '/cbuilder/src/intl/cbuilder.json',
'type': 'json',
},
]
10 changes: 10 additions & 0 deletions src/intl/intl.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ export const supportedLocales = ['en-US', 'pt-BR', 'es-ES'];
export const defaultLocale = 'en-US';

export const localePrefix = 'always';

//See https://developer.crowdin.com/language-codes/
export const mapSupportedLocalesToCrowdinLanguageCodes: Record<string, string> =
{
'en-US': 'en',
'pt-BR': 'pt-BR',
'es-ES': 'es-ES',
'fr-FR': 'fr',
'it-IT': 'it',
};
14 changes: 14 additions & 0 deletions src/intl/intl.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ESNext",
"outDir": "./dist",
"rootDir": ".",
"moduleResolution": "Node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"strict": true
},
"files": ["./intl.constants.ts", "./scripts/getSupportedLocales.ts"]
}
28 changes: 28 additions & 0 deletions src/intl/scripts/getSupportedLocales.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//To compile the script run the following command in the terminal:
//npx -p typescript tsc --project src/intl/intl.ts-config.json
//To run the script, use the following command:
//node src/intl/dist/getSupportedLocales.js

import {
supportedLocales,
mapSupportedLocalesToCrowdinLanguageCodes,
defaultLocale,
} from '../intl.constants';

const result = supportedLocales
.map((locale) => {
if (!(locale in mapSupportedLocalesToCrowdinLanguageCodes)) {
throw new Error(
`The locale "${locale}" is not supported by Crowdin. Please add it to the "mapSupportedLocalesToCrowdinLanguageCodes" object in "src/intl/intl.constants.ts".`,
);
}
if (locale === defaultLocale) {
return '';
}

const crowdinLanguageCode =
mapSupportedLocalesToCrowdinLanguageCodes[locale];
return `-l ${crowdinLanguageCode}`;
})
.join(' ');
console.log(result);

0 comments on commit d356652

Please sign in to comment.