Skip to content

Commit 1368a98

Browse files
committed
✨ 完成了单文件的翻译
1 parent f590aa4 commit 1368a98

File tree

6 files changed

+116
-36
lines changed

6 files changed

+116
-36
lines changed

.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 将这个文件重命名成 .env.local ,然后进行定制化修改
2+
3+
AI_GATEWAY_ENDPOINT=https://api.deepseek.com
4+
OPENAI_API_KEY="API <DeepSeek Key >"
5+
AI_MODEL=deepseek-chat

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ package-lock.json
1717
pnpm-lock.yaml
1818
en.bak
1919
.env.local
20-
.env

docs/.vitepress/i18n/en.json

Whitespace-only changes.

docs/en/intro.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# What is dweb-browser
2+
3+
dweb-browser is a browser platform built following the Dweb standards, exposing browser capabilities and related native system capabilities through various dweb modules. Currently, we support mainstream platforms such as Android, IOS, MacOS, Windows, and Linux.
4+
5+
We modularize the functionalities of the operating system and then interconnect them using a unified communication standard, thus assembling a new platform. Note that this assembly is not just for a single device but for all devices trusted by the user. When users install DwebBrowser on their devices, each device's capabilities are modularized, simultaneously providing services to the user. The reassembled platform will be even more powerful. For example, I can run my AIGC program on a PC but use it on a mobile device, without the developer needing to intervene in how the devices should interconnect. Developers can treat it as developing an application locally, with the service provider behind the scenes being either the local device or cloud services.
6+
7+
We are passionate about advancing Web technology. We have deployed a JsRuntime locally, which, for developers, is similar to well-known JsRuntimes like Nodejs or Deno, except that the latter always runs on cloud servers. We bring these capabilities down to mobile devices, allowing developers to use traditional server-side development techniques to deploy and run their sites locally on users' devices. All of this happens locally, meaning neither developers nor users need to pay any deployment costs. We have moved server-side technology to local mobile devices, which is a significant innovation.
8+
9+
Deploying applications using local server-side technology, unlike traditional WebApps, does not consume a lot of memory, and the longer it runs, the higher the memory usage inevitably becomes. We prioritize the backend concept, allowing us to deploy SSR technology locally, which is more advanced than SSG, offering faster first-screen loading experiences and more memory savings.
10+
11+
Thus, user privacy is better protected under this programming model. And because services are deployed locally, developers can more easily solve offline availability issues.
12+
13+
We open-source everything, we do not monopolize, we simply return Web technology to users, allowing them to freely deploy their programs.
14+
15+
To achieve cross-platform programming, we provide a cross-platform windowed view standard, using multi-window technology uniformly on mobile devices. This is a core point of our commitment to cross-platform. Without multi-window technology, it would be difficult for us to provide a unified programming interface for users and developers across multiple platforms.
16+
17+
We will also make more efforts for user privacy. In the future, we will add features like "identity wallet" to make it easier for users to manage their account passwords and personal information in apps and web pages. The community can build around these standardized infrastructures provided by dweb to offer users a better experience.
18+
19+
We hope developers will open their applications to each other through standards. The current internet world is like isolated islands of information, driven by interests. We do not deny these objective phenomena but hope to introduce a series of new technical standards to provide users with a better Web environment, making it truly the "internet."
20+
21+
Imagine being able to play chess with your friend without even connecting to a chess server, but simply through a chat app to connect with your friend and then play chess together. This does not require the chess app developer to purchase any servers, nor does it require the chat app developer to develop any chess functionality. They can interconnect through open standards.
22+
23+
At the same time, chat servers do not even need to be purchased. Under the dweb technical standard framework, all nodes are servers. This openness is based on the protection of user devices. Users can choose trusted operators to protect their openness, and this operator could be the user's own desktop device at home. Therefore, users do not need to worry about any of their data being sold to operators.
24+
25+
## What is dweb?
26+
27+
Dweb is a decentralized Web consensus standard. It is directly reflected in your domain name, such as: `example.dweb`
28+
However, because the dweb domain does not actually exist on the internet, it means it does not belong to any organization. That is, how to interpret the `example.dweb` domain name is entirely up to you (your device) to decide.
29+
The dweb consensus standard is composed of several parts:
30+
31+
### Communication Standard
32+
33+
Inspired by the http protocol, we use JSON and CBOR, web data formats, to define the communication standard between two modules. Modules that follow this message-based communication are called dweb-micro-modules (Chinese: "dweb modules").
34+
This communication standard uses the `file:` protocol header combined with the `.dweb` domain to define its URL, for example: `file://dns.std.dweb/`.
35+
36+
### General Standards
37+
38+
- `dns.std.dweb` is the core part of the dweb consensus standard, defining functions such as interconnection, registration, and query between two dweb modules, which are the core technologies required for dweb module interconnection.
39+
- `http.std.dweb` is the standard for http services. Any module can obtain a dedicated `.dweb` domain through it, enabling interoperability with Web technology.
40+
- `file.std.dweb` is the file service standard. It operates on a module basis, with each module having an independent file service, which do not interfere with each other but can safely collaborate.
41+
- `permission.std.dweb` is the permission management standard. Data belongs to the user, including the data managed by the module. Therefore, modules can register permissions to ensure data services are authorized by the user.
42+
43+
### System Standards
44+
45+
This covers some standards for common operating system modules, including platform-independent standards and unified abstract standards:
46+
47+
- `file.sys.dweb`
48+
- `camera.sys.dweb`
49+
- `camera.harmonyos-sys.dweb`
50+
- `camera.android-sys.dweb`
51+
- `camera.ios-sys.dweb`
52+
- `camera.windows-sys.dweb`
53+
- `status-bar.sys.dweb`
54+
- `status-bar.android-sys.dweb`
55+
- `status-bar.ios-sys.dweb`
56+
- `toast.sys.dweb`
57+
- `share.sys.dweb`
58+
- `process.sys.dweb`
59+
- `account.sys.dweb`
60+
- _etc._
61+
62+
These `*sys.dweb` standards are encapsulations of the operating system's standard interfaces. We will not tamper with them but will follow up with updates to the native system, making them long-term stable and used as standard libraries for application development.
63+
64+
### Deep Link Standard
65+
66+
`dweb-deeplink` is a link in the format of `dweb://action?params`, providing a consensus platform for dweb modules. For example, modules can rely on consensus rather than actual dweb modules.
67+
A concrete example is implementing a share function: I can bind in my share button: `dweb:share?title=hello_world&files=http...`, then the dweb kernel will look for which module has declared the implementation of `dweb:share` and route the request to that module. If the consensus is implemented by multiple modules simultaneously, preference selection will be made through platform-standard interactions on different platforms.
68+
69+
In environments with command lines, `dweb-deeplink` can also be accessed via command line: `dweb-browser install app --url=xx` will be parsed as: `dweb:install/app?url=xx`
70+
71+
> Note: DwebBrowser here is just a software implementation of the dweb protocol. There may be other implementations in the community, or we may also introduce dweb-cloud, a runtime service for the cloud in the future.

scripts/i18n.ts

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
import OpenAI from "openai";
22
import { str_trim_indent } from "@gaubee/util";
3-
import "dotenv/config";
43
import { z } from "zod";
54
import { parseArgs } from "@std/cli/parse-args";
65
import { import_meta_ponyfill } from "import-meta-ponyfill";
76
import fs from "node:fs";
87
import path from "node:path";
9-
10-
const openai = new OpenAI({
11-
baseURL: z
12-
.string({ required_error: "required env.AI_GATEWAY_ENDPOINT" })
13-
.parse(process.env.AI_GATEWAY_ENDPOINT),
14-
apiKey: z
15-
.string({ required_error: "required env.OPENAI_API_KEY" })
16-
.parse(process.env.OPENAI_API_KEY),
17-
});
8+
import { config } from "dotenv";
189

1910
const zTranslateOptions = z.object({
2011
file: z.string().array().nonempty(),
@@ -50,7 +41,7 @@ const zModes = {
5041
outputs: zFile.array(),
5142
}),
5243
/** 返回参数:翻译好的文件内容 */
53-
output: zFileWithContent.array(),
44+
output: z.object({ outputs: zFileWithContent.array() }),
5445
},
5546
increment: {
5647
input: z.object({
@@ -62,7 +53,7 @@ const zModes = {
6253
outputs: zFile.array(),
6354
}),
6455
/** 返回参数:翻译好的文件内容 */
65-
output: zGitPatch,
56+
output: z.object({ patch: zGitPatch }),
6657
},
6758
};
6859
async function translate(args: z.TypeOf<typeof zTranslateOptions>) {
@@ -100,10 +91,10 @@ async function translate(args: z.TypeOf<typeof zTranslateOptions>) {
10091
files: files,
10192
outputs: outputs,
10293
};
103-
const result = zModes.full.output.parse(
104-
await getOutput(JSON.stringify(input))
94+
const output = zModes.full.output.parse(
95+
await getOpenaiOutput(JSON.stringify(input))
10596
);
106-
result.forEach((file) => {
97+
output.outputs.forEach((file) => {
10798
fs.mkdirSync(path.dirname(file.filepath), { recursive: true });
10899
fs.writeFileSync(file.filepath, file.content);
109100
});
@@ -112,7 +103,16 @@ async function translate(args: z.TypeOf<typeof zTranslateOptions>) {
112103
}
113104
}
114105

115-
const getOutput = async (user_content: string) => {
106+
const getOpenaiOutput = async (user_content: string) => {
107+
const openai = new OpenAI({
108+
baseURL: z
109+
.string({ required_error: "required env.AI_GATEWAY_ENDPOINT" })
110+
.parse(process.env.AI_GATEWAY_ENDPOINT),
111+
apiKey: z
112+
.string({ required_error: "required env.OPENAI_API_KEY" })
113+
.parse(process.env.OPENAI_API_KEY),
114+
});
115+
116116
const completion = await openai.chat.completions.create({
117117
messages: [
118118
{
@@ -132,27 +132,33 @@ const getOutput = async (user_content: string) => {
132132
133133
## 输入输出规范
134134
输入格式(JSON Schema):
135+
\`\`\`json
135136
{
136137
"mode": "full",
137138
"files": [{
138-
"filepath": "docs/zh-CN/guide.md",
139-
"language": "zh-CN",
140-
"content": "文件内容"
139+
"filepath": "<输入路径>",
140+
"language": "<输入语言>",
141+
"content": "<文件内容>"
141142
}],
142143
"outputs": [{
143-
"filepath": "docs/en/guide.md",
144-
"language": "en"
144+
"filepath": "<目标路径>",
145+
"language": "<目标语言>"
145146
}]
146147
}
148+
\`\`\`
147149
148-
输出格式(严格遵循):
149-
[
150-
{
151-
"filepath": "输出路径",
152-
"language": "目标语言",
153-
"content": "翻译后的完整内容"
154-
}
155-
]
150+
输出格式(JSON Schema):
151+
\`\`\`json
152+
{
153+
"outputs": [
154+
{
155+
"filepath": "docs/en/guide.md",
156+
"language": "en",
157+
"content": "<翻译后的完整内容>"
158+
}
159+
]
160+
}
161+
\`\`\`
156162
157163
## 翻译规则
158164
1. 结构保留:
@@ -194,24 +200,28 @@ const getOutput = async (user_content: string) => {
194200
type: "json_object",
195201
},
196202
});
203+
console.log(completion.choices[0].message.content);
197204
return JSON.parse(completion.choices[0].message.content!);
198205
};
199206

200207
if (import_meta_ponyfill(import.meta).main) {
201208
const args = parseArgs(process.argv.slice(2), {
202209
string: ["mode"],
203-
collect: ["file", "language"],
210+
collect: ["file", "language", "env-file"],
204211
alias: {
205212
m: "mode",
206213
f: "file",
207214
l: "language",
208215
},
209216
default: {
210217
mode: "full",
218+
"env-file": [".env.local"],
211219
},
212220
});
213221

214222
console.log("args", args);
215223

224+
config({ path: [".env", ...(args["env-file"] as string[])], override: true });
225+
216226
translate(zTranslateOptions.parse(args));
217227
}

template.env

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)