Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ desktop app runs on, so they live in the desktop app (its `tw-adopt` and
`tw-scan` crates), and the only control-plane endpoint they use is
`POST /clients/{id}/key`, which issues a client its own gateway key.

## Runtime text

Core-authored runtime text is written in English. Use a stable message
code and named arguments for messages the clients translate. Built-in
security rules expose stable IDs, group slugs, and English display text.
Client applications own the translations for those IDs and slugs. Rule
patterns, user-supplied names, and upstream text retain their original
language.

## Commit messages

Conventional Commits (`fix(scope): subject`), in **English** — this is a
Expand Down
58 changes: 29 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ categories = ["network-programming", "web-programming::http-server"]

# 二进制走 CalVer,crate 走 SemVer —— 两者是两回事,卖给不同的人。
# 这里是 crate 的版本。
version = "0.99.0"
version = "0.100.0"

[workspace.dependencies]
# ── 内部 crate ───────────────────────────────────────────
Expand Down
10 changes: 5 additions & 5 deletions bin/twcore/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,8 @@ fn cmd_remote(path: &Path, what: RemoteCmd) -> Result<()> {
fn cmd_init(path: &Path, force: bool) -> Result<()> {
if path.exists() && !force {
anyhow::bail!(
"{} 已存在。如需重新生成,请添加 --force。\n\
这会覆盖当前配置,其中的密钥也将丢失",
"{} already exists. To regenerate it, pass --force.\n\
This will overwrite the current configuration and discard the keys in it.",
path.display()
);
}
Expand Down Expand Up @@ -784,9 +784,9 @@ fn cmd_check(path: &Path) -> Result<()> {

fn already_running(dir: &Path, pid: u32) -> anyhow::Error {
anyhow::anyhow!(
"已有 twcore 实例正在运行(pid {pid})。\n\
两个实例无法共用同一个网关端口,请先停止该实例。\n\
如果该进程实际已退出,请删除 {} 后重试",
"A twcore instance is already running (PID {pid}).\n\
Stop it before starting another instance on the same gateway port.\n\
If that process has already exited, remove {} and retry.",
dir.join("twcore.lock").display()
)
}
Expand Down
7 changes: 6 additions & 1 deletion bin/twcore/tests/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ fn product_text_is_written_not_spoken() {
if FORMAT.contains(&lit.as_str()) || lit.contains("CREATE TABLE") {
continue;
}
if rel_path.starts_with("bin/twcore/src")
&& lit.chars().any(|c| matches!(c, '\u{3400}'..='\u{9fff}'))
{
found.push(format!("{rel}:{line}: write CLI output in English"));
}
for w in SPOKEN.iter().filter(|w| lit.contains(**w)) {
found.push(format!("{rel}:{line} 「{w}」 {lit}"));
}
Expand All @@ -267,7 +272,7 @@ fn product_text_is_written_not_spoken() {

assert!(
found.is_empty(),
"这些文字用了口语或人称:\n{}",
"Product copy violations:\n{}",
found.join("\n")
);
}
Expand Down
17 changes: 17 additions & 0 deletions bin/twcore/tests/msg_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,23 @@ fn only_placeholders(t: &str) -> bool {
rest.is_empty()
}

#[test]
fn core_message_templates_do_not_include_client_translations() {
let (sites, _) = scan(&workspace());
for site in sites.iter().filter(|site| !site.test) {
if let Some(template) = &site.template {
assert!(
!template
.chars()
.any(|c| matches!(c, '\u{3400}'..='\u{9fff}')),
"{}:{}: write Core message templates in English",
site.file,
site.line,
);
}
}
}

/// 按源码生成的清单全文。
fn manifest(root: &Path) -> String {
let (sites, consts) = scan(root);
Expand Down
6 changes: 4 additions & 2 deletions crates/tw-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,9 @@ pub const MSG_CODES: &str = include_str!("../msg-codes.txt");
/// [`SpecSource::Upstream`] 表示上游报告的规格。请求库 SCHEMA 不变。
/// **61 起支持 Core 执行联网工具**:新增 `WebTools`、`SaveWebTools` 和 `TestWebTool`。
/// 搜索、网页读取和页内查找共用当前连接 Core 的配置。请求库 SCHEMA 不变。
pub const CONTROL_API_VERSION: u32 = 61;
/// **62 起防护规则和分组视图只返回英文说明**:客户端用规则 ID 和分组 slug 查译文。
/// 请求库 SCHEMA 不变。
pub const CONTROL_API_VERSION: u32 = 62;

/// `/live` 的速度看最近多久(见 [`LiveView::tokens_per_sec`]),毫秒
pub const LIVE_RATE_WINDOW_MS: u64 = 3_000;
Expand Down Expand Up @@ -6627,7 +6629,7 @@ pub struct RuleSnapshot {
pub builtin: bool,
/// 内置规则的 id,或者自定义规则的名字
pub id: String,
/// 显示的名字:内置规则的英文名(中文名按 id 在规则视图里取 `name_zh`),自定义规则就是它的名字
/// The built-in rule's English name, or the custom rule's original name.
pub name: String,
/// 自定义规则写的样子,原样(正则、关键词、码位)。内置规则没有
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down
8 changes: 3 additions & 5 deletions crates/tw-api/src/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,8 @@ mod tests {
"matcher: Matcher",
"scope?: Array<ContentScope>",
"replacement?: string",
// 名字、说明由 core 给,中英文各一个字段
"name_zh?: string",
"why_zh?: string",
"name: string",
"about?: string",
"about_zh?: string",
] {
assert!(rule.contains(field), "{field}: {rule}");
}
Expand All @@ -528,9 +525,10 @@ mod tests {
decl_of(&ts, "GuardDetail")
);
let kind = decl_of(&ts, "SecurityKindView");
for field in ["slug: string", "name: string", "name_zh: string"] {
for field in ["slug: string", "name: string"] {
assert!(kind.contains(field), "{field}: {kind}");
}
assert!(!rule.contains("_zh") && !kind.contains("_zh"));
assert_eq!(
decl_of(&ts, "ContentScope"),
"export type ContentScope = \"request\" | \"response\""
Expand Down
Loading
Loading