From 358d9f2fb21281ee2a91d7a7258363c932389308 Mon Sep 17 00:00:00 2001 From: Anxo Rodriguez Date: Tue, 31 Oct 2023 12:54:45 +0000 Subject: [PATCH] build: fix i18n script usage with nx (#3303) --- CONTRIBUTING.md | 2 +- apps/cowswap-frontend/lingui.config.ts | 56 --------------------- apps/cowswap-frontend/package.json | 5 -- apps/cowswap-frontend/project.json | 23 +++++++++ apps/cowswap-frontend/src/locales/README.md | 7 --- libs/common-utils/src/environments.test.ts | 2 +- lingui.config.ts | 4 +- package.json | 5 +- 8 files changed, 30 insertions(+), 74 deletions(-) delete mode 100644 apps/cowswap-frontend/lingui.config.ts delete mode 100644 apps/cowswap-frontend/src/locales/README.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 08364611ae..7220ad1d4a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,7 +9,7 @@ yarn install ## Generate locale files ``` -yarn i18n:extract +yarn i18n ``` ## Run the interface diff --git a/apps/cowswap-frontend/lingui.config.ts b/apps/cowswap-frontend/lingui.config.ts deleted file mode 100644 index 5dd55d3933..0000000000 --- a/apps/cowswap-frontend/lingui.config.ts +++ /dev/null @@ -1,56 +0,0 @@ -const linguiConfig = { - catalogs: [ - { - path: '/src/locales/{locale}', - include: ['/src'], - }, - ], - fallbackLocales: { - default: 'en-US', - }, - format: 'po', - formatOptions: { - lineNumbers: false, - }, - locales: [ - /* 'af-ZA', - 'ar-SA', - 'ca-ES', - 'cs-CZ', - 'da-DK', - 'de-DE', - 'el-GR', */ - 'en-US', - /* 'es-ES', - 'fi-FI', - 'fr-FR', - 'he-IL', - 'hu-HU', - 'id-ID', - 'it-IT', - 'ja-JP', - 'ko-KR', - 'nl-NL', - 'no-NO', - 'pl-PL', - 'pt-BR', - 'pt-PT', - 'ro-RO', - 'ru-RU', - 'sr-SP', - 'sv-SE', - 'sw-TZ', - 'tr-TR', - 'uk-UA', - 'vi-VN', - 'zh-CN', - 'zh-TW', */ - 'pseudo', - ], - orderBy: 'messageId', - runtimeConfigModule: ['@lingui/core', 'i18n'], - sourceLocale: 'en-US', - pseudoLocale: 'pseudo', -} - -export default linguiConfig diff --git a/apps/cowswap-frontend/package.json b/apps/cowswap-frontend/package.json index 70081eda33..ee83e78599 100644 --- a/apps/cowswap-frontend/package.json +++ b/apps/cowswap-frontend/package.json @@ -8,11 +8,6 @@ "ipfs:build": "cross-env PUBLIC_URL=\".\" yarn build", "ipfs:publish": "npx ipfs-deploy build -p pinata -O", "patch-package": "npx patch-package", - "i18n": "yarn run i18n:compile", - "i18n:compile": "yarn run i18n:extract && npx lingui compile", - "i18n:extract": "cross-env NODE_ENV=development npx lingui extract --locale en-US", - "i18n:pseudo": "npx lingui extract --locale pseudo && lingui compile", - "postinstall": "yarn run i18n", "cosmos:clear": "rm -rf ./public/cosmos", "cosmos:run": "yarn run _cosmos:run", "build:cosmos": "cross-env NODE_ENV=development npx cosmos-export", diff --git a/apps/cowswap-frontend/project.json b/apps/cowswap-frontend/project.json index 6c020d732c..8e001fb9f0 100644 --- a/apps/cowswap-frontend/project.json +++ b/apps/cowswap-frontend/project.json @@ -8,6 +8,7 @@ "executor": "@nx/vite:build", "outputs": ["{options.outputPath}"], "defaultConfiguration": "production", + "dependsOn": ["i18n:compile"], "options": { "outputPath": "build/cowswap" }, @@ -71,6 +72,28 @@ "options": { "buildTarget": "cowswap-frontend:build" } + }, + + "i18n": { + "executor": "nx:noop", + "dependsOn": ["i18n:compile"] + }, + "i18n:compile": { + "executor": "nx:run-commands", + "dependsOn": ["i18n:extract"], + "options": { + "command": "npx lingui compile" + }, + "inputs": ["{projectRoot}/src/locales/*.po"], + "outputs": ["{projectRoot}/src/locales/*.js"] + }, + "i18n:extract": { + "executor": "nx:run-commands", + "options": { + "command": "cross-env NODE_ENV=development npx lingui extract --locale en-US" + }, + "inputs": ["{workspaceRoot}/apps/**/*.{ts,tsx,jsx}", "{workspaceRoot}/libs/**/*.{ts,tsx,jsx}"], + "outputs": ["{projectRoot}/src/locales/*.po"] } }, "tags": [] diff --git a/apps/cowswap-frontend/src/locales/README.md b/apps/cowswap-frontend/src/locales/README.md deleted file mode 100644 index b3f39c6aa6..0000000000 --- a/apps/cowswap-frontend/src/locales/README.md +++ /dev/null @@ -1,7 +0,0 @@ -**Do not edit translation files manually** - -## Contributing - -Translation files in this folder are automatically generated from our [Crowdin project](https://crowdin.com/project/uniswap-interface). - -See [CONTRIBUTING](https://github.com/Uniswap/uniswap-interface/blob/main/CONTRIBUTING.md#translations) on how to get started. diff --git a/libs/common-utils/src/environments.test.ts b/libs/common-utils/src/environments.test.ts index c61f7810b2..2cf8d96aa5 100644 --- a/libs/common-utils/src/environments.test.ts +++ b/libs/common-utils/src/environments.test.ts @@ -20,7 +20,7 @@ describe('Detect environments using host and path', () => { }) }) - describe('Is production', () => { + describe.only('Is production', () => { const isProduction = { ...DEFAULT_ENVIRONMENTS_CHECKS, isProd: true } it('swap.cow.fi', () => { diff --git a/lingui.config.ts b/lingui.config.ts index 5dd55d3933..f1c4d794bc 100644 --- a/lingui.config.ts +++ b/lingui.config.ts @@ -1,8 +1,8 @@ const linguiConfig = { catalogs: [ { - path: '/src/locales/{locale}', - include: ['/src'], + path: '/apps/cowswap-frontend/src/locales/{locale}', + include: ['/apps', '/libs'], }, ], fallbackLocales: { diff --git a/package.json b/package.json index 56d61afe9b..12f5e90673 100644 --- a/package.json +++ b/package.json @@ -21,14 +21,15 @@ "ci:build": "yarn run build:cowswap && yarn run build-widget", "ipfs:build": "PUBLIC_URL=\".\" yarn build", "ipfs:publish": "npx ipfs-deploy build -p pinata -O", + "i18n": "nx run-many -t i18n", "preview": "cross-env NODE_OPTIONS=--max-old-space-size=32768 nx run cowswap-frontend:preview", "test": "yarn test:all", "test:all": "nx run-many -t test", "e2e": "nx run-many -t e2e", "lint": "nx run-many -t lint", - "prebuild-app": "nx run cowswap-frontend:i18n", + "prebuild-app": "yarn i18n", "prepare": "husky install", - "postinstall": "yarn run patch-package", + "postinstall": "yarn run patch-package && yarn i18n", "analyze-build": "cross-env ANALYZE_BUNDLE=true ANALYZE_BUNDLE_TEMPLATE=sunburst yarn build" }, "browser": {