From 71d316d12229fea64688713c88148a4f0c062cda Mon Sep 17 00:00:00 2001 From: garrettmills Date: Mon, 22 Mar 2021 12:07:33 -0500 Subject: [PATCH] Update logo; add i18n support --- ex | 14 ++++++++------ package.json | 1 + pnpm-lock.yaml | 2 ++ src/Units.extollo.ts | 2 ++ src/app/configs/lang/common.config.ts | 5 +++++ src/app/configs/lang/en_US.config.ts | 6 ++++++ src/app/http/controllers/main/Home.controller.ts | 7 ++++++- src/app/resources/views/welcome.pug | 6 +++--- 8 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 src/app/configs/lang/common.config.ts create mode 100644 src/app/configs/lang/en_US.config.ts diff --git a/ex b/ex index 758648d..3ee08e1 100755 --- a/ex +++ b/ex @@ -3,12 +3,14 @@ ENV_NODE="$(which node)" ENV_PNPM="$(which pnpm)" -LOGO=" ______ _ _ _ - | ____| | | | | | - | |__ __ _| |_ ___ | | | ___ - | __| \\ \\/ / __/ _ \\| | |/ _ \\ - | |____ > <| || (_) | | | (_) | - |______/_/\\_\\\\__\\___/|_|_|\\___/" +LOGO=" _ + / /\ ______ _ _ _ + / / \ | ____| | | | | | + / / /\ \ | |__ __ _| |_ ___ | | | ___ + / / /\ \ \ | __| \ \/ / __/ _ \| | |/ _ \\ +/ / / \ \_\ | |____ > <| || (_) | | | (_) | +\/_/ \/_/ |______/_/\_\\\__\___/|_|_|\___/ +" # Author: Tasos Latsas diff --git a/package.json b/package.json index 4a53e41..428db5e 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "@extollo/lib": "file:../lib", "@extollo/orm": "file:../orm", "@extollo/cli": "file:../cli", + "@extollo/i18n": "file:../i18n", "copyfiles": "^2.4.1", "typescript": "^4.1.3" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 548e381..34aac2f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,6 +1,7 @@ dependencies: '@extollo/cli': link:../cli '@extollo/di': link:../di + '@extollo/i18n': link:../i18n '@extollo/lib': link:../lib '@extollo/orm': link:../orm copyfiles: 2.4.1 @@ -297,6 +298,7 @@ packages: specifiers: '@extollo/cli': file:../cli '@extollo/di': file:../di + '@extollo/i18n': file:../i18n '@extollo/lib': file:../lib '@extollo/orm': file:../orm copyfiles: ^2.4.1 diff --git a/src/Units.extollo.ts b/src/Units.extollo.ts index 12faf66..ff9fc1d 100644 --- a/src/Units.extollo.ts +++ b/src/Units.extollo.ts @@ -1,6 +1,7 @@ import {Config, Controllers, HTTPServer, Middlewares, Routing, Unit} from '@extollo/lib' import {Database, Models} from "@extollo/orm"; import {CommandLine} from "@extollo/cli"; +import {Internationalization} from "@extollo/i18n"; export const Units = [ Config, @@ -9,6 +10,7 @@ export const Units = [ Middlewares, Database, Models, + Internationalization, Routing, HTTPServer, diff --git a/src/app/configs/lang/common.config.ts b/src/app/configs/lang/common.config.ts new file mode 100644 index 0000000..972fea9 --- /dev/null +++ b/src/app/configs/lang/common.config.ts @@ -0,0 +1,5 @@ +import { env } from "@extollo/lib" + +export default { + app_name: env('APP_NAME', 'Extollo'), +} diff --git a/src/app/configs/lang/en_US.config.ts b/src/app/configs/lang/en_US.config.ts new file mode 100644 index 0000000..5ab104c --- /dev/null +++ b/src/app/configs/lang/en_US.config.ts @@ -0,0 +1,6 @@ +import {env} from '@extollo/lib' + +export default { + welcome_to_extollo: 'Welcome to Extollo!', + viewed_page_num_times: 'You have viewed this page :num: times.', +} diff --git a/src/app/http/controllers/main/Home.controller.ts b/src/app/http/controllers/main/Home.controller.ts index b16deb4..af5a47f 100644 --- a/src/app/http/controllers/main/Home.controller.ts +++ b/src/app/http/controllers/main/Home.controller.ts @@ -1,16 +1,21 @@ import {Controller, view, Session} from '@extollo/lib'; import {Inject, Injectable} from "@extollo/di"; +import {Locale} from "@extollo/i18n" @Injectable() export class Home extends Controller { @Inject() protected readonly session!: Session; + @Inject() + protected readonly locale!: Locale; + public welcome() { this.session.set('app_visits', this.session.get('app_visits', 0) + 1) return view('welcome', { - app_visits: this.session.get('app_visits') + app_visits: this.session.get('app_visits'), + locale: this.locale.helper(), }) } } diff --git a/src/app/resources/views/welcome.pug b/src/app/resources/views/welcome.pug index 3f428e4..7649fb1 100644 --- a/src/app/resources/views/welcome.pug +++ b/src/app/resources/views/welcome.pug @@ -1,6 +1,6 @@ html head - title Welcome | Extollo + title !{locale('app_name')} body - h1 Welcome to Extollo - h2 You have viewed this page !{app_visits} times. + h1 !{locale('welcome_to_extollo')} + h2 !{locale('viewed_page_num_times', { interp: { num: app_visits } })}