Skip to content

Commit

Permalink
Merge pull request #7061 from ever-co/feat/download-translation
Browse files Browse the repository at this point in the history
Feat/download translation
  • Loading branch information
evereq authored Oct 31, 2023
2 parents 87eff57 + 68b7197 commit 62c5e66
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 21 deletions.
5 changes: 3 additions & 2 deletions .env.compose
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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=
5 changes: 3 additions & 2 deletions .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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=
5 changes: 3 additions & 2 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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=
5 changes: 3 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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=
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
8 changes: 2 additions & 6 deletions .scripts/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,25 @@ 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;
DESKTOP_APP_REPO_NAME: string;
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;
DESKTOP_SERVER_APP_REPO_NAME: string;
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(
Expand Down Expand Up @@ -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',
}),
Expand All @@ -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',
}),
Expand All @@ -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}),
Expand Down
6 changes: 6 additions & 0 deletions .scripts/translation/supported-language.ts
Original file line number Diff line number Diff line change
@@ -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'];
}
}
71 changes: 71 additions & 0 deletions .scripts/translation/translation-util.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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<void> {
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();
})();
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,18 @@
"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",
"generate:icons:server": "yarn run generate:icons --desktop=server",
"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": {
Expand Down

0 comments on commit 62c5e66

Please sign in to comment.