Skip to content

Commit

Permalink
git进度消息汉化...
Browse files Browse the repository at this point in the history
修复了原本粗糙且错误的汉化操作
  • Loading branch information
zetaloop committed May 8, 2024
1 parent 605e37b commit e0b8055
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/src/lib/git/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function fetch(
// about ref updates. We don't need to bring those into the progress
// stream so we'll just punt on anything we don't know about for now.
if (progress.kind === 'context') {
if (!progress.text.startsWith('remote: Counting objects')) {
if (!progress.text_.startsWith('remote: Counting objects')) {
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/lib/git/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function pull(
// about ref updates. We don't need to bring those into the progress
// stream so we'll just punt on anything we don't know about for now.
if (progress.kind === 'context') {
if (!progress.text.startsWith('remote: Counting objects')) {
if (!progress.text_.startsWith('remote: Counting objects')) {
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/lib/progress/checkout.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GitProgressParser } from './git'

const steps = [{ title: '正在检出文件', weight: 1 }]
const steps = [{ title: 'Checking out files', weight: 1 }]

/**
* A class that parses output from `git checkout --progress` and provides
Expand Down
8 changes: 4 additions & 4 deletions app/src/lib/progress/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { GitProgressParser } from './git'
* of the individual progress reporting steps in a clone operation
*/
const steps = [
{ title: '远程端:正在压缩对象', weight: 0.1 },
{ title: '正在接收对象', weight: 0.6 },
{ title: '正在解析增量', weight: 0.1 },
{ title: '正在检出文件', weight: 0.2 },
{ title: 'remote: Compressing objects', weight: 0.1 },
{ title: 'Receiving objects', weight: 0.6 },
{ title: 'Resolving deltas', weight: 0.1 },
{ title: 'Checking out files', weight: 0.2 },
]

/**
Expand Down
55 changes: 52 additions & 3 deletions app/src/lib/progress/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface IGitOutput {
readonly kind: 'context'
readonly percent: number
readonly text: string
readonly text_: string
}

/**
Expand Down Expand Up @@ -135,6 +136,7 @@ export interface IGitProgressInfo {
* for presenting the actual output from Git to the user.
*/
readonly text: string
readonly text_: string
}

/**
Expand Down Expand Up @@ -196,7 +198,12 @@ export class GitProgressParser {
const progress = parse(line)

if (!progress) {
return { kind: 'context', text: line, percent: this.lastPercent }
return {
kind: 'context',
text: translateLn(line),
text_: line,
percent: this.lastPercent,
}
}

let percent = 0
Expand All @@ -218,7 +225,12 @@ export class GitProgressParser {
}
}

return { kind: 'context', text: line, percent: this.lastPercent }
return {
kind: 'context',
text: translateLn(line),
text_: line,
percent: this.lastPercent,
}
}
}

Expand Down Expand Up @@ -303,5 +315,42 @@ export function parse(line: string): IGitProgressInfo | null {
}
}

return { title, value, percent, total, done, text: line }
return {
title,
value,
percent,
total,
done,
text: translateLn(line),
text_: line,
}
}

function translateLn(line: string): string {
// Translate Git message to Chinese
// Ref: git/git/po/zh_CN.po, and realworld test
line = line.replace('remote: ', '远程端:')
line = line.replace('Enumerating objects', '正在枚举对象')
line = line.replace('Counting objects', '正在计算对象数量')
line = line.replace('Compressing objects', '正在压缩对象')
line = line.replace('Writing objects', '正在发送对象')
line = line.replace('Receiving objects', '正在接收对象')
line = line.replace('Indexing objects', '正在索引对象')
line = line.replace('Resolving deltas', '正在分析差异')
line = line.replace('Checking out files', '正在检出文件')
// #: builtin/pack-objects.c
// #, c-format
// msgid ""
// "Total %<PRIu32> (delta %<PRIu32>), reused %<PRIu32> (delta %<PRIu32>), pack-"
// "reused %<PRIu32> (from %<PRIuMAX>)"
// msgstr ""
// "总共 %<PRIu32>(差异 %<PRIu32>),复用 %<PRIu32>(差异 %<PRIu32>),包复用 "
// "%<PRIu32>(来自 %<PRIuMAX> 个包)"
line = line.replace(
/Total (\d+) \(delta (\d+)\), reused (\d+) \(delta (\d+)\), pack-reused (\d+) \(from (\d+)\)/,
(_, total, delta1, reused1, delta2, packReused, from) => {
return `总共${total}个 (差异${delta1}个), 复用${reused1}个 (差异${delta2}个), 包复用${packReused}个 (来自${from}个包)`
}
)
return line
}
8 changes: 4 additions & 4 deletions app/src/lib/progress/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { GitProgressParser } from './git'
* delta updates are fairly quick though.
*/
const steps = [
{ title: '远程端:正在压缩对象', weight: 0.1 },
{ title: '正在接收对象', weight: 0.7 },
{ title: '正在解析增量', weight: 0.15 },
{ title: '正在检出文件', weight: 0.15 },
{ title: 'remote: Compressing objects', weight: 0.1 },
{ title: 'Receiving objects', weight: 0.7 },
{ title: 'Resolving deltas', weight: 0.15 },
{ title: 'Checking out files', weight: 0.15 },
]

/**
Expand Down
6 changes: 3 additions & 3 deletions app/src/lib/progress/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { GitProgressParser } from './git'
* of the individual progress reporting steps in a push operation
*/
const steps = [
{ title: '正在压缩对象', weight: 0.2 },
{ title: '正在发送对象', weight: 0.7 },
{ title: '远程端:正在解析增量', weight: 0.1 },
{ title: 'Compressing objects', weight: 0.2 },
{ title: 'Writing objects', weight: 0.7 },
{ title: 'remote: Resolving deltas', weight: 0.1 },
]

/**
Expand Down

0 comments on commit e0b8055

Please sign in to comment.