diff --git a/.github/workflows/DownloadCrowdinTranslations.yml b/.github/workflows/DownloadCrowdinTranslations.yml new file mode 100644 index 00000000..cdf12084 --- /dev/null +++ b/.github/workflows/DownloadCrowdinTranslations.yml @@ -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 }} diff --git a/.github/workflows/UploadSourceFileToCrowdin.yml b/.github/workflows/UploadSourceFileToCrowdin.yml new file mode 100644 index 00000000..dbf37e43 --- /dev/null +++ b/.github/workflows/UploadSourceFileToCrowdin.yml @@ -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 }} diff --git a/.gitignore b/.gitignore index fd3dbb57..16c9c87d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ # production /build +/src/intl/dist # misc .DS_Store diff --git a/crowdin.yml b/crowdin.yml new file mode 100644 index 00000000..df710792 --- /dev/null +++ b/crowdin.yml @@ -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', + }, + ] diff --git a/src/intl/intl.constants.ts b/src/intl/intl.constants.ts index ef573f9d..042c5cb9 100644 --- a/src/intl/intl.constants.ts +++ b/src/intl/intl.constants.ts @@ -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 = + { + 'en-US': 'en', + 'pt-BR': 'pt-BR', + 'es-ES': 'es-ES', + 'fr-FR': 'fr', + 'it-IT': 'it', + }; diff --git a/src/intl/intl.tsconfig.json b/src/intl/intl.tsconfig.json new file mode 100644 index 00000000..a006433f --- /dev/null +++ b/src/intl/intl.tsconfig.json @@ -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"] +} diff --git a/src/intl/scripts/getSupportedLocales.ts b/src/intl/scripts/getSupportedLocales.ts new file mode 100644 index 00000000..1dddf550 --- /dev/null +++ b/src/intl/scripts/getSupportedLocales.ts @@ -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);