@finesoft/create-app 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finesoft/create-app",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Scaffold a new Finesoft Front project",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -8,7 +8,7 @@
8
8
  "preview": "vp preview"
9
9
  },
10
10
  "dependencies": {
11
- "@finesoft/front": "^0.1.57",
11
+ "@finesoft/front": "^0.1.58",
12
12
  "react": "^19.0.0",
13
13
  "react-dom": "^19.0.0"
14
14
  },
@@ -8,7 +8,7 @@
8
8
  "preview": "vp preview"
9
9
  },
10
10
  "dependencies": {
11
- "@finesoft/front": "^0.1.57",
11
+ "@finesoft/front": "^0.1.58",
12
12
  "react": "^19.0.0",
13
13
  "react-dom": "^19.0.0"
14
14
  },
@@ -8,7 +8,7 @@
8
8
  "preview": "vp preview"
9
9
  },
10
10
  "dependencies": {
11
- "@finesoft/front": "^0.1.57",
11
+ "@finesoft/front": "^0.1.58",
12
12
  "svelte": "^5.0.0"
13
13
  },
14
14
  "devDependencies": {
@@ -8,7 +8,7 @@
8
8
  "preview": "vp preview"
9
9
  },
10
10
  "dependencies": {
11
- "@finesoft/front": "^0.1.57",
11
+ "@finesoft/front": "^0.1.58",
12
12
  "svelte": "^5.0.0"
13
13
  },
14
14
  "devDependencies": {
@@ -1,6 +1,16 @@
1
- import { type Framework, defineRoutes } from "@finesoft/front";
1
+ import { defineBootstrap, defineRoutes } from "@finesoft/front";
2
2
  import { HomeController } from "./lib/controllers/home";
3
3
 
4
- export function bootstrap(framework: Framework): void {
5
- defineRoutes(framework, [{ path: "/", intentId: "home", controller: new HomeController() }]);
6
- }
4
+ export const bootstrap = defineBootstrap(
5
+ {
6
+ frameworkConfig: {
7
+ // Change this to "zh-Hans" to load src/locales/zh-Hans.json instead.
8
+ locale: "zh-Hans",
9
+ },
10
+ },
11
+ (framework) => {
12
+ defineRoutes(framework, [
13
+ { path: "/", intentId: "home", controller: new HomeController() },
14
+ ]);
15
+ },
16
+ );
@@ -1,15 +1,27 @@
1
- import { BaseController, type BasePage } from "@finesoft/front";
1
+ import {
2
+ BaseController,
3
+ DEP_KEYS,
4
+ type BasePage,
5
+ type Container,
6
+ type Translator,
7
+ } from "@finesoft/front";
2
8
 
3
9
  export class HomeController extends BaseController<Record<string, string>, BasePage> {
4
10
  readonly intentId = "home";
5
11
 
6
- execute(): BasePage {
12
+ execute(_params: Record<string, string>, container: Container): BasePage {
13
+ const translator = container.has(DEP_KEYS.TRANSLATOR)
14
+ ? container.resolve<Translator>(DEP_KEYS.TRANSLATOR)
15
+ : undefined;
16
+
7
17
  return {
8
18
  id: "home",
9
19
  pageType: "home",
10
20
  url: "/",
11
- title: "Home",
12
- description: "Welcome to Finesoft Front",
21
+ title: translator?.t("home.title") ?? "Hello from Finesoft Front",
22
+ description:
23
+ translator?.t("home.description") ??
24
+ "This page uses locale JSON files loaded by finesoftFrontViteConfig.",
13
25
  };
14
26
  }
15
27
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "home.title": "Hello from Finesoft Front",
3
+ "home.description": "This page uses locale JSON files loaded by finesoftFrontViteConfig.",
4
+ "home.localeLabel": "Current locale",
5
+ "home.runtimeBadge": "Hydration kept the translator alive on the client.",
6
+ "home.switchHint": "Change frameworkConfig.locale in src/bootstrap.ts to load another JSON file."
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "home.title": "你好,来自 Finesoft Front",
3
+ "home.description": "这个页面的文案来自 finesoftFrontViteConfig 自动加载的 JSON 翻译文件。",
4
+ "home.localeLabel": "当前语言",
5
+ "home.runtimeBadge": "浏览器接管后,翻译器仍然可用。",
6
+ "home.switchHint": "把 src/bootstrap.ts 里的 frameworkConfig.locale 改成 zh-Hans,就会加载这份翻译文件。"
7
+ }
@@ -1,10 +1,25 @@
1
1
  <script lang="ts">
2
2
  import type { BasePage } from "@finesoft/front";
3
+ import { getFramework } from "../lib/framework-svelte";
3
4
 
4
5
  let { page }: { page: BasePage } = $props();
6
+
7
+ const framework = getFramework();
8
+ const locale = framework?.getLocale()?.lang ?? "unknown";
9
+ const translator = framework?.getTranslator();
10
+ const localeLabel = translator?.t("home.localeLabel") ?? "Current locale";
11
+ const runtimeBadge =
12
+ translator?.t("home.runtimeBadge") ??
13
+ "Hydration kept the translator alive on the client.";
14
+ const switchHint =
15
+ translator?.t("home.switchHint") ??
16
+ 'Change frameworkConfig.locale in src/bootstrap.ts to load another JSON file.';
5
17
  </script>
6
18
 
7
19
  <div>
8
20
  <h1>{page.title}</h1>
9
21
  <p>{page.description}</p>
22
+ <p><strong>{localeLabel}:</strong> {locale}</p>
23
+ <p>{runtimeBadge}</p>
24
+ <p>{switchHint}</p>
10
25
  </div>
@@ -7,6 +7,9 @@ export default defineConfig({
7
7
  svelte(),
8
8
  finesoftFrontViteConfig({
9
9
  ssr: { entry: "src/ssr.ts" },
10
+ i18n: {
11
+ messagesDir: "src/locales",
12
+ },
10
13
  }),
11
14
  ],
12
15
  });
@@ -8,7 +8,7 @@
8
8
  "preview": "vp preview"
9
9
  },
10
10
  "dependencies": {
11
- "@finesoft/front": "^0.1.57",
11
+ "@finesoft/front": "^0.1.58",
12
12
  "vue": "^3.5.0"
13
13
  },
14
14
  "devDependencies": {
@@ -8,7 +8,7 @@
8
8
  "preview": "vp preview"
9
9
  },
10
10
  "dependencies": {
11
- "@finesoft/front": "^0.1.57",
11
+ "@finesoft/front": "^0.1.58",
12
12
  "vue": "^3.5.0"
13
13
  },
14
14
  "devDependencies": {