dsh-locale-pack-loader 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-pirate-ui contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
1
+ # 语言包加载器
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 启用 `dsh-locale-pack-loader` 后,主题整合包可以通过补丁给 `locale-pack-loader` 提供一份语言包,并给 DSH 的 `locale` 行设置语言偏好。
4
+
5
+ ```yaml
6
+ - id: locale-pack-loader
7
+ config:
8
+ pack:
9
+ id: zh-fantasy
10
+ label: 简体中文 · 奇幻
11
+ fallback: zh
12
+ dictionaries:
13
+ sidebar:
14
+ session.new: 新冒险
15
+ session.new.label: 新冒险
16
+ conversation:
17
+ hero.headline: 踏上旅途
18
+ - id: locale
19
+ config:
20
+ preference: zh-fantasy
21
+ ```
22
+
23
+ 加载器从宿主读取配置,按命名空间注册词典。清除 `pack` 或停用加载器后,词典与语言定义一并注销。加载器只读取配置。语言选择由 DSH 处理,优先级更高的个人偏好仍然有效。请在整合包列表中把加载器排在提供词典的主题前面。多个主题同时配置时,靠后的整合包胜出。
package/client.js ADDED
@@ -0,0 +1,59 @@
1
+ window.__ModuleLoader__.load({
2
+ id: 'dsh-locale-pack-loader',
3
+ factory() {
4
+ function registerPack(locale, pack) {
5
+ const disposers = [];
6
+ const release = () => {
7
+ let failure;
8
+ for (const dispose of disposers.splice(0).reverse()) {
9
+ try { dispose(); } catch (error) { failure ??= error; }
10
+ }
11
+ if (failure !== undefined) throw failure;
12
+ };
13
+
14
+ try {
15
+ for (const [namespace, dictionary] of Object.entries(pack.dictionaries)) {
16
+ disposers.push(locale.register(namespace, pack.id, dictionary));
17
+ }
18
+ disposers.push(locale.addLanguage({ id: pack.id, label: pack.label, fallback: pack.fallback }));
19
+ } catch (error) {
20
+ try { release(); } catch {}
21
+ throw error;
22
+ }
23
+ return release;
24
+ }
25
+
26
+ return {
27
+ inject: ['locale', 'configForms'],
28
+ apply(ctx) {
29
+ return ctx.effect(() => {
30
+ const form = ctx.configForms.get('locale-pack-loader');
31
+ let current;
32
+ let disposePack;
33
+ const sync = () => {
34
+ const { status, value } = form.getSnapshot();
35
+ if (status === 'loading') return;
36
+ const pack = status === 'ready' ? value?.pack : undefined;
37
+ const revision = JSON.stringify(pack);
38
+ if (current === revision) return;
39
+ const previous = disposePack;
40
+ disposePack = undefined;
41
+ current = undefined;
42
+ try {
43
+ previous?.();
44
+ disposePack = pack ? registerPack(ctx.locale, pack) : undefined;
45
+ current = revision;
46
+ } catch (error) {
47
+ console.error('[locale-pack-loader] Language pack registration failed:', error);
48
+ }
49
+ };
50
+ const unsubscribe = form.subscribe(sync);
51
+ sync();
52
+ return () => {
53
+ try { unsubscribe(); } finally { disposePack?.(); }
54
+ };
55
+ }, 'locale-pack-loader: language pack');
56
+ },
57
+ };
58
+ },
59
+ });
package/icon.svg ADDED
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40" fill="none">
2
+ <rect x="3" y="3" width="34" height="34" rx="9" fill="#172840"/>
3
+ <path d="M9 13h12m-6-3v3m3 0c0 6-4 10-9 12m3-10c1 3 3 6 7 8m2 6 5-13 5 13m-8-4h6" stroke="#D5EAFE" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
4
+ </svg>
package/index.js ADDED
@@ -0,0 +1,25 @@
1
+ import { createRequire } from 'node:module';
2
+ import { join } from 'node:path';
3
+
4
+ const localRequire = createRequire(import.meta.url);
5
+ const hostRoot = process.env.DSH_INSTALL_DIR
6
+ ?? (process.resourcesPath && join(process.resourcesPath, 'app.asar', 'dsh', 'node_modules', '@deepseek-ai', 'dsh'));
7
+ const schemastery = hostRoot
8
+ ? createRequire(join(hostRoot, 'package.json'))('@deepseek-ai/schemastery')
9
+ : localRequire('@deepseek-ai/schemastery');
10
+ const z = schemastery.default ?? schemastery;
11
+ const localeId = () => z.string().pattern(/^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/u).required();
12
+ const pack = z.object({
13
+ id: localeId(),
14
+ label: z.string().required(),
15
+ fallback: localeId(),
16
+ dictionaries: z.dict(z.dict(z.string())).required(),
17
+ });
18
+
19
+ export const Config = z.object({ pack: z.union([z.const(false), pack]).default(false).volatile() });
20
+
21
+ export function apply(ctx) {
22
+ ctx.inject(['settings'], scope => scope.effect(
23
+ () => scope.settings.configure({ auto: false }, ctx.fiber),
24
+ ));
25
+ }
package/locale/en.json ADDED
@@ -0,0 +1 @@
1
+ {"meta":{"title":"Locale pack loader","description":"Registers language and namespace dictionaries supplied by DSH bundle configuration."}}
package/locale/zh.json ADDED
@@ -0,0 +1 @@
1
+ {"meta":{"title":"语言包加载器","description":"注册 DSH 整合包提供的语言和命名空间词典。"}}
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "dsh-locale-pack-loader",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Registers languages and dictionaries declared by DSH bundle configuration.",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/butterfly301/dsh-locale-pack-loader.git"
10
+ },
11
+ "engines": {
12
+ "dsh": ">=0.2.2-rc.5 <0.3.0"
13
+ },
14
+ "exports": {
15
+ ".": "./index.js",
16
+ "./client": "./client.js",
17
+ "./locale/*.json": "./locale/*.json",
18
+ "./icon": "./icon.svg",
19
+ "./package.json": "./package.json"
20
+ },
21
+ "files": [
22
+ "index.js",
23
+ "client.js",
24
+ "locale",
25
+ "icon.svg",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
29
+ "dsh": {
30
+ "client": {
31
+ "platform": "web",
32
+ "immediately": true,
33
+ "inject": [
34
+ "@deepseek-ai/dsh-client-locale",
35
+ "@deepseek-ai/dsh-client-ui-settings"
36
+ ]
37
+ }
38
+ }
39
+ }