From 7c1cea9fb4c94d0aeb36b31f8b61a56c239edc3d Mon Sep 17 00:00:00 2001 From: Adolphe Kifungo <45813955+adkif@users.noreply.github.com> Date: Tue, 31 Oct 2023 22:30:43 +0200 Subject: [PATCH 1/3] fix: use common i18n url variable from all desktop app --- .env.compose | 5 +++-- .env.docker | 5 +++-- .env.local | 5 +++-- .env.sample | 5 +++-- .../common-environment-content.ts | 1 + .../desktop-environment-content.ts | 1 - .../desktop-server-environment-content.ts | 1 - .../desktop-timer-environment-content.ts | 1 - .scripts/env.ts | 8 ++------ 9 files changed, 15 insertions(+), 17 deletions(-) diff --git a/.env.compose b/.env.compose index cf742eb7f39..f087e9dcca9 100644 --- a/.env.compose +++ b/.env.compose @@ -371,7 +371,6 @@ DESKTOP_APP_REPO_NAME='ever-gauzy-desktop' DESKTOP_APP_REPO_OWNER='ever-co' DESKTOP_APP_WELCOME_TITLE= DESKTOP_APP_WELCOME_CONTENT= -DESKTOP_APP_I18N_FILES_URL= # Desktop Server Application Configuration DESKTOP_SERVER_APP_NAME='gauzy-server' @@ -381,4 +380,6 @@ DESKTOP_SERVER_APP_REPO_NAME='ever-gauzy-server' DESKTOP_SERVER_APP_REPO_OWNER='ever-co' DESKTOP_SERVER_APP_WELCOME_TITLE= DESKTOP_SERVER_APP_WELCOME_CONTENT= -DESKTOP_SERVER_APP_I18N_FILES_URL= + +# I18N Translation Files URL +I18N_FILES_URL= diff --git a/.env.docker b/.env.docker index 42f095af48f..199b53d0270 100644 --- a/.env.docker +++ b/.env.docker @@ -345,7 +345,6 @@ DESKTOP_APP_REPO_NAME='ever-gauzy-desktop' DESKTOP_APP_REPO_OWNER='ever-co' DESKTOP_APP_WELCOME_TITLE= DESKTOP_APP_WELCOME_CONTENT= -DESKTOP_APP_I18N_FILES_URL= # Desktop Server Application Configuration DESKTOP_SERVER_APP_NAME='gauzy-server' @@ -355,4 +354,6 @@ DESKTOP_SERVER_APP_REPO_NAME='ever-gauzy-server' DESKTOP_SERVER_APP_REPO_OWNER='ever-co' DESKTOP_SERVER_APP_WELCOME_TITLE= DESKTOP_SERVER_APP_WELCOME_CONTENT= -DESKTOP_SERVER_APP_I18N_FILES_URL= + +# I18N Translation Files URL +I18N_FILES_URL= diff --git a/.env.local b/.env.local index 09d9c460d02..2f54b10ece7 100644 --- a/.env.local +++ b/.env.local @@ -332,7 +332,6 @@ DESKTOP_APP_REPO_NAME='ever-gauzy-desktop' DESKTOP_APP_REPO_OWNER='ever-co' DESKTOP_APP_WELCOME_TITLE= DESKTOP_APP_WELCOME_CONTENT= -DESKTOP_APP_I18N_FILES_URL= # Desktop Server Application Configuration DESKTOP_SERVER_APP_NAME='gauzy-server' @@ -342,4 +341,6 @@ DESKTOP_SERVER_APP_REPO_NAME='ever-gauzy-server' DESKTOP_SERVER_APP_REPO_OWNER='ever-co' DESKTOP_SERVER_APP_WELCOME_TITLE= DESKTOP_SERVER_APP_WELCOME_CONTENT= -DESKTOP_SERVER_APP_I18N_FILES_URL= + +# I18N Translation Files URL +I18N_FILES_URL= diff --git a/.env.sample b/.env.sample index 8e77cfc4baa..bc3c2b12bd7 100644 --- a/.env.sample +++ b/.env.sample @@ -364,7 +364,6 @@ DESKTOP_APP_REPO_NAME='ever-gauzy-desktop' DESKTOP_APP_REPO_OWNER='ever-co' DESKTOP_APP_WELCOME_TITLE= DESKTOP_APP_WELCOME_CONTENT= -DESKTOP_APP_I18N_FILES_URL= # Desktop Server Application Configuration DESKTOP_SERVER_APP_NAME='gauzy-server' @@ -374,4 +373,6 @@ DESKTOP_SERVER_APP_REPO_NAME='ever-gauzy-server' DESKTOP_SERVER_APP_REPO_OWNER='ever-co' DESKTOP_SERVER_APP_WELCOME_TITLE= DESKTOP_SERVER_APP_WELCOME_CONTENT= -DESKTOP_SERVER_APP_I18N_FILES_URL= + +# I18N Translation Files URL +I18N_FILES_URL= diff --git a/.scripts/electron-desktop-environment/concrete-environment-content/common-environment-content.ts b/.scripts/electron-desktop-environment/concrete-environment-content/common-environment-content.ts index 427a9144019..35d827af6c6 100644 --- a/.scripts/electron-desktop-environment/concrete-environment-content/common-environment-content.ts +++ b/.scripts/electron-desktop-environment/concrete-environment-content/common-environment-content.ts @@ -15,6 +15,7 @@ export class CommonEnvironmentContent implements IContentGenerator { COMPANY_SITE_LINK: '${variable.COMPANY_SITE_LINK}', GAUZY_DESKTOP_LOGO_512X512: '${variable.GAUZY_DESKTOP_LOGO_512X512}', NO_INTERNET_LOGO: '${variable.NO_INTERNET_LOGO}', + I18N_FILES_URL: '${variable.I18N_FILES_URL}', `; } } diff --git a/.scripts/electron-desktop-environment/concrete-environment-content/desktop-environment-content.ts b/.scripts/electron-desktop-environment/concrete-environment-content/desktop-environment-content.ts index 74c32166318..472cbd7b707 100644 --- a/.scripts/electron-desktop-environment/concrete-environment-content/desktop-environment-content.ts +++ b/.scripts/electron-desktop-environment/concrete-environment-content/desktop-environment-content.ts @@ -11,7 +11,6 @@ export class DesktopEnvironmentContent implements IContentGenerator { REPO_OWNER: '${variable.DESKTOP_APP_REPO_OWNER || variable.REPO_OWNER}', WELCOME_TITLE: '${variable.DESKTOP_APP_WELCOME_TITLE || variable.WELCOME_TITLE || ''}', WELCOME_CONTENT: '${variable.DESKTOP_APP_WELCOME_CONTENT || variable.WELCOME_CONTENT || ''}', - I18N_FILES_URL: '${variable.DESKTOP_APP_I18N_FILES_URL || variable.I18N_FILES_URL || ''}', IS_DESKTOP_TIMER: ${false}, IS_DESKTOP: ${true}, IS_SERVER: ${false}, diff --git a/.scripts/electron-desktop-environment/concrete-environment-content/desktop-server-environment-content.ts b/.scripts/electron-desktop-environment/concrete-environment-content/desktop-server-environment-content.ts index 543011ebd64..b94b8b3572a 100644 --- a/.scripts/electron-desktop-environment/concrete-environment-content/desktop-server-environment-content.ts +++ b/.scripts/electron-desktop-environment/concrete-environment-content/desktop-server-environment-content.ts @@ -11,7 +11,6 @@ export class DesktopServerEnvironmentContent implements IContentGenerator { REPO_OWNER: '${variable.DESKTOP_SERVER_APP_REPO_OWNER || variable.REPO_OWNER}', WELCOME_TITLE: '${variable.DESKTOP_SERVER_APP_WELCOME_TITLE || variable.WELCOME_TITLE || ''}', WELCOME_CONTENT: '${variable.DESKTOP_SERVER_APP_WELCOME_CONTENT || variable.WELCOME_CONTENT || ''}', - I18N_FILES_URL: '${variable.DESKTOP_SERVER_APP_I18N_FILES_URL || variable.I18N_FILES_URL || ''}', IS_DESKTOP_TIMER: ${false}, IS_DESKTOP: ${false}, IS_SERVER: ${true}, diff --git a/.scripts/electron-desktop-environment/concrete-environment-content/desktop-timer-environment-content.ts b/.scripts/electron-desktop-environment/concrete-environment-content/desktop-timer-environment-content.ts index 25fb9ee3fdf..3a5ae23c6f3 100644 --- a/.scripts/electron-desktop-environment/concrete-environment-content/desktop-timer-environment-content.ts +++ b/.scripts/electron-desktop-environment/concrete-environment-content/desktop-timer-environment-content.ts @@ -11,7 +11,6 @@ export class DesktopTimerEnvironmentContent implements IContentGenerator { REPO_OWNER: '${variable.DESKTOP_TIMER_APP_REPO_OWNER || variable.REPO_OWNER}', WELCOME_TITLE: '${variable.DESKTOP_TIMER_APP_WELCOME_TITLE || variable.WELCOME_TITLE || ''}', WELCOME_CONTENT: '${variable.DESKTOP_TIMER_APP_WELCOME_CONTENT || variable.WELCOME_CONTENT || ''}', - I18N_FILES_URL: '${variable.DESKTOP_TIMER_APP_I18N_FILES_URL || variable.I18N_FILES_URL || ''}', IS_DESKTOP_TIMER: ${true}, IS_DESKTOP: ${false}, IS_SERVER: ${false}, diff --git a/.scripts/env.ts b/.scripts/env.ts index b62fa1862e1..270d840e8d0 100644 --- a/.scripts/env.ts +++ b/.scripts/env.ts @@ -100,7 +100,6 @@ export type Env = Readonly<{ DESKTOP_TIMER_APP_REPO_OWNER: string; DESKTOP_TIMER_APP_WELCOME_TITLE: string; DESKTOP_TIMER_APP_WELCOME_CONTENT: string; - DESKTOP_TIMER_APP_I18N_FILES_URL: string; DESKTOP_APP_NAME: string; DESKTOP_APP_DESCRIPTION: string; DESKTOP_APP_ID: string; @@ -108,7 +107,6 @@ export type Env = Readonly<{ DESKTOP_APP_REPO_OWNER: string; DESKTOP_APP_WELCOME_TITLE: string; DESKTOP_APP_WELCOME_CONTENT: string; - DESKTOP_APP_I18N_FILES_URL: string; DESKTOP_SERVER_APP_NAME: string; DESKTOP_SERVER_APP_DESCRIPTION: string; DESKTOP_SERVER_APP_ID: string; @@ -116,11 +114,11 @@ export type Env = Readonly<{ DESKTOP_SERVER_APP_REPO_OWNER: string; DESKTOP_SERVER_APP_WELCOME_TITLE: string; DESKTOP_SERVER_APP_WELCOME_CONTENT: string; - DESKTOP_SERVER_APP_I18N_FILES_URL: string; AWHost: string; API_DEFAULT_PORT: number; GAUZY_UI_DEFAULT_PORT: number; SCREENSHOTS_ENGINE_METHOD: string; + I18N_FILES_URL: string; }>; export const env: Env = cleanEnv( @@ -263,7 +261,6 @@ export const env: Env = cleanEnv( DESKTOP_TIMER_APP_REPO_OWNER: str({ default: 'ever-co' }), DESKTOP_TIMER_APP_WELCOME_TITLE: str({ default: '' }), DESKTOP_TIMER_APP_WELCOME_CONTENT: str({ default: '' }), - DESKTOP_TIMER_APP_I18N_FILES_URL: str({ default: '' }), DESKTOP_APP_NAME: str({ default: 'gauzy-desktop', }), @@ -279,7 +276,6 @@ export const env: Env = cleanEnv( DESKTOP_APP_REPO_OWNER: str({ default: 'ever-co' }), DESKTOP_APP_WELCOME_TITLE: str({ default: '' }), DESKTOP_APP_WELCOME_CONTENT: str({ default: '' }), - DESKTOP_APP_I18N_FILES_URL: str({ default: '' }), DESKTOP_SERVER_APP_NAME: str({ default: 'gauzy-server', }), @@ -295,7 +291,7 @@ export const env: Env = cleanEnv( DESKTOP_SERVER_APP_REPO_OWNER: str({ default: 'ever-co' }), DESKTOP_SERVER_APP_WELCOME_TITLE: str({ default: '' }), DESKTOP_SERVER_APP_WELCOME_CONTENT: str({ default: '' }), - DESKTOP_SERVER_APP_I18N_FILES_URL: str({ default: '' }), + I18N_FILES_URL: str({ default: '' }), AWHost: str({default: 'http://localhost:5600'}), API_DEFAULT_PORT: num({default: 3000}), GAUZY_UI_DEFAULT_PORT: num({default: 5621}), From c536dcebad21c824c65e6e2bf114ead97068dddf Mon Sep 17 00:00:00 2001 From: Adolphe Kifungo <45813955+adkif@users.noreply.github.com> Date: Tue, 31 Oct 2023 22:33:15 +0200 Subject: [PATCH 2/3] feat: download translation from the web --- .scripts/translation/supported-language.ts | 6 ++ .scripts/translation/translation-util.ts | 71 ++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 .scripts/translation/supported-language.ts create mode 100644 .scripts/translation/translation-util.ts diff --git a/.scripts/translation/supported-language.ts b/.scripts/translation/supported-language.ts new file mode 100644 index 00000000000..0bb84b4c4c6 --- /dev/null +++ b/.scripts/translation/supported-language.ts @@ -0,0 +1,6 @@ +export class SupportedLanguage { + // Supported languages + public static get list(): string[] { + return ['ar', 'bg', 'de', 'en', 'es', 'fr', 'he', 'it', 'nl', 'pl', 'pt', 'ru', 'zh']; + } +} diff --git a/.scripts/translation/translation-util.ts b/.scripts/translation/translation-util.ts new file mode 100644 index 00000000000..a3815195bf1 --- /dev/null +++ b/.scripts/translation/translation-util.ts @@ -0,0 +1,71 @@ +import { argv } from 'yargs'; +import fetch from 'node-fetch'; +import * as path from 'path'; +import * as fs from 'fs'; +import { env } from '../env'; +import { SupportedLanguage } from './supported-language'; + +export class TranslationUtil { + public readonly desktop: string; + public readonly destination: string; + public readonly i18nUrl: string; + public readonly translations = []; + + constructor() { + this.desktop = String(argv.desktop || ''); + this.destination = path.join('apps', this.desktop, 'src', 'assets', 'i18n'); + this.i18nUrl = env.I18N_FILES_URL; + } + + private validateUrl() { + if (!this.i18nUrl) { + console.warn('WARNING: No translation files url provided'); + return false; + } + try { + const url = new URL(this.i18nUrl); + return !!url; + } catch (error) { + console.error(`ERROR: Url '${this.i18nUrl}' provided is not valid: ` + error); + return false; + } + } + + private async download(language: string): Promise { + const url = `${this.i18nUrl}/${language}.json`; + const response = await fetch(url); + const data = await response.json(); + const fileName = path.basename(url); + fs.writeFileSync(path.join(this.destination, fileName), JSON.stringify(data, null, 4)); + console.log(`✔ File ${fileName} downloaded.`); + } + + private copyAll(): void { + const source = path.join('apps', 'gauzy', 'src', 'assets', 'i18n'); + fs.cpSync(source, this.destination, { recursive: true }); + console.log(`✔ All translations copied from ${source}.`); + } + + public async downloadAll(): Promise { + if (!fs.existsSync(this.destination)) { + console.log(`✔ I18n directory created.`); + fs.mkdirSync(this.destination); + } + if (!this.validateUrl()) { + this.copyAll(); + return; + } + for (const language of SupportedLanguage.list) { + try { + await this.download(language); + } catch (error) { + console.error(`ERROR: Language '${language}' not available: ` + error); + } + } + } +} + +(async () => { + const translationUtil = new TranslationUtil(); + await translationUtil.downloadAll(); +})(); From 68b7197fe4c59c3d73ffd0a6bdefa7d00038d0b6 Mon Sep 17 00:00:00 2001 From: Adolphe Kifungo <45813955+adkif@users.noreply.github.com> Date: Tue, 31 Oct 2023 22:34:23 +0200 Subject: [PATCH 3/3] feat: update commands and download translations --- package.json | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 461c4f7cd8e..8d5f9b342b3 100644 --- a/package.json +++ b/package.json @@ -169,9 +169,9 @@ "build:gauzy-server:linux:release:gh": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=30000 yarn run config:prod && yarn run build:gauzy-server && npm config set cache .cache && yarn electron-builder -c.electronVersion=20.2.0 build --linux --publish=always --project dist/apps/gauzy-server", "build:gauzy-server:mac:release": "yarn run build:gauzy-server && npm config set cache .cache && yarn electron-builder -c.electronVersion=20.2.0 build --mac --publish=always --project dist/apps/gauzy-server", "quick:build:gauzy-server": "yarn electron-builder -c.electronVersion=20.2.0 -c.extraMetadata.author.name=Ever build --mac --project dist/apps/gauzy-server", - "copy-files-i18n-desktop-timer": "copyfiles -f apps/gauzy/src/assets/i18n/*.json apps/desktop-timer/src/assets/i18n/", - "copy-files-i18n-desktop": "copyfiles -f apps/gauzy/src/assets/i18n/*.json apps/desktop/src/assets/i18n/", - "copy-files-i18n-server": "copyfiles -f apps/gauzy/src/assets/i18n/*.json apps/server/src/assets/i18n/", + "copy-files-i18n-desktop-timer": "yarn run download:translations --desktop=desktop-timer", + "copy-files-i18n-desktop": "yarn run download:translations --desktop=desktop", + "copy-files-i18n-server": "yarn run download:translations --desktop=server", "generate:icons": "yarn ts-node .scripts/icon-utils/icon-factory.ts", "generate:icons:desktop-timer": "yarn run generate:icons --desktop=desktop-timer", "generate:icons:desktop": "yarn run generate:icons --desktop=desktop", @@ -179,7 +179,8 @@ "pack": "yarn ts-node .scripts/electron-package-utils/package-util.ts", "pack:desktop-timer": "yarn run pack --desktop=desktop-timer", "pack:desktop": "yarn run pack --desktop=desktop", - "pack:server": "yarn run pack --desktop=server" + "pack:server": "yarn run pack --desktop=server", + "download:translations": "yarn ts-node .scripts/translation/translation-util.ts" }, "config": { "commitizen": {