chore(i18n): clean code

This commit is contained in:
lawvs
2022-09-09 15:27:03 +08:00
parent ff1cb4da84
commit d6e408a4be
5 changed files with 13 additions and 9 deletions

View File

@@ -11,6 +11,7 @@ on:
paths: paths:
- 'libs/datasource/i18n/**' - 'libs/datasource/i18n/**'
- '.github/workflows/languages-sync.yml' - '.github/workflows/languages-sync.yml'
workflow_dispatch:
# Cancels all previous workflow runs for pull requests that have not completed. # Cancels all previous workflow runs for pull requests that have not completed.
# See https://docs.github.com/en/actions/using-jobs/using-concurrency # See https://docs.github.com/en/actions/using-jobs/using-concurrency
@@ -49,8 +50,14 @@ jobs:
- name: Check Language Key - name: Check Language Key
if: github.ref != 'refs/heads/develop' && github.ref != 'refs/heads/master' if: github.ref != 'refs/heads/develop' && github.ref != 'refs/heads/master'
run: pnpm run --recursive sync-languages:check working-directory: ./libs/datasource/i18n
run: pnpm run sync-languages:check
env:
TOLGEE_API_KEY: ${{ secrets.TOLGEE_API_KEY }}
- name: Sync Languages - name: Sync Languages
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master' if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master'
run: pnpm run --recursive sync-languages working-directory: ./libs/datasource/i18n
run: pnpm run sync-languages
env:
TOLGEE_API_KEY: ${{ secrets.TOLGEE_API_KEY }}

View File

@@ -7,7 +7,6 @@
}, },
"dependencies": { "dependencies": {
"i18next": "^21.9.1", "i18next": "^21.9.1",
"jotai": "^1.8.1",
"react-i18next": "^11.18.4" "react-i18next": "^11.18.4"
} }
} }

View File

@@ -9,6 +9,7 @@ if (!TOLGEE_API_KEY) {
const withTolgee = ( const withTolgee = (
fetch: typeof globalThis.fetch fetch: typeof globalThis.fetch
): typeof globalThis.fetch => { ): typeof globalThis.fetch => {
const baseUrl = `${TOLGEE_API_URL}/v2/projects`;
const headers = new Headers({ const headers = new Headers({
'X-API-Key': TOLGEE_API_KEY, 'X-API-Key': TOLGEE_API_KEY,
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@@ -29,14 +30,14 @@ const withTolgee = (
if (!argArray[0].headers) { if (!argArray[0].headers) {
argArray[0] = { argArray[0] = {
...argArray[0], ...argArray[0],
url: `${TOLGEE_API_URL}/v2/projects${argArray[0].url}`, url: `${baseUrl}${argArray[0].url}`,
headers, headers,
}; };
} }
} else { } else {
// URL or URLLike + ?RequestInit // URL or URLLike + ?RequestInit
if (typeof argArray[0] === 'string') { if (typeof argArray[0] === 'string') {
argArray[0] = `${TOLGEE_API_URL}/v2/projects${argArray[0]}`; argArray[0] = `${baseUrl}${argArray[0]}`;
} }
if (!argArray[1]) { if (!argArray[1]) {
argArray[1] = {}; argArray[1] = {};

View File

@@ -79,8 +79,7 @@ const differenceObject = (
}; };
function warnDiff(diff: { add: string[]; remove: string[]; modify: string[] }) { function warnDiff(diff: { add: string[]; remove: string[]; modify: string[] }) {
if (!diff.add.length) { if (diff.add.length) {
} else {
console.log('New keys found:', diff.add.join(', ')); console.log('New keys found:', diff.add.join(', '));
//See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-notice-message //See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-notice-message
process.env['CI'] && process.env['CI'] &&

2
pnpm-lock.yaml generated
View File

@@ -580,11 +580,9 @@ importers:
libs/datasource/i18n: libs/datasource/i18n:
specifiers: specifiers:
i18next: ^21.9.1 i18next: ^21.9.1
jotai: ^1.8.1
react-i18next: ^11.18.4 react-i18next: ^11.18.4
dependencies: dependencies:
i18next: 21.9.1 i18next: 21.9.1
jotai: 1.8.1
react-i18next: 11.18.4_i18next@21.9.1 react-i18next: 11.18.4_i18next@21.9.1
libs/datasource/jwt: libs/datasource/jwt: