Merge pull request #493 from yusancky/update-manual-translate

Update Chinese translation of manual
pull/502/head
Wilfred Hughes 2023-03-15 22:25:30 +07:00 committed by GitHub
commit c07cf052d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 83 additions and 60 deletions

@ -5,7 +5,7 @@
- [使用](./usage.md)
- [Git](./git.md)
- [Mercurial](./mercurial.md)
- [支持语言](./languages_supported.md)
- [支持语言](./languages_supported.md)
- [解析](./parsing.md)
- [差异分析](./diffing.md)
- [棘手的例子](./tricky_cases.md)

@ -1,6 +1,6 @@
# Git
Git[支持使用外部的diff工具](https://git-scm.com/docs/diff-config#Documentation/diff-config.txt-diffexternal)。你可以使用`GIT_EXTERNAL_DIFF`来进行一键git命令
Git [支持使用外部差异分析工具](https://git-scm.com/docs/diff-config#Documentation/diff-config.txt-diffexternal)。你可以使用 `GIT_EXTERNAL_DIFF` 命令暂时地设置 diff 工具
```
$ GIT_EXTERNAL_DIFF=difft git diff
@ -8,17 +8,17 @@ $ GIT_EXTERNAL_DIFF=difft git log -p --ext-diff
$ GIT_EXTERNAL_DIFF=difft git show e96a7241760319 --ext-diff
```
如果你想默认使用Difftastic可以使用`git config`。
如果你想默认使用 Difftastic可以使用 `git config`
```
# Set git configuration for the current repository.
# 仅为当前存储库设置
$ git config diff.external difft
# Set git configuration for all repositories.
# 为全局设置
$ git config --global diff.external difft
```
在运行`git config`后,`git diff`命令将会自动使用`difft`。其他情况则需要使用`--ext-diff`来使用`diff.external`。
在运行 `git config` 后,`git diff` 命令将会自动使用 `difft`。其他情况则需要使用 `--ext-diff` 来使用 `diff.external`
```
$ git diff
@ -28,9 +28,9 @@ $ git show e96a7241760319 --ext-diff
## git-difftool
[git difftool](https://git-scm.com/docs/git-difftool) 是一款使用不同diff工具来查看当前修改的git命令。如果你想要偶尔使用Difftastic的话这将会非常有用。
[git difftool](https://git-scm.com/docs/git-difftool) 是一个 Git 命令,用于使用不同差异分析工具来查看当前修改。如果你想要偶尔使用 Difftastic会非常有用。
添加下列内容到你的`.gitconfig`中就会让Difftastic作为你的difftool工具。
添加下列内容到你的 `.gitconfig` 文件中Difftastic 就会作为你的 diff 工具。
```ini
[diff]
@ -43,20 +43,20 @@ $ git show e96a7241760319 --ext-diff
cmd = difft "$LOCAL" "$REMOTE"
```
然后你可以使用`git difftool`来用Difftastic查看当前修改。
然后你可以使用 `git difftool` 来用 Difftastic 查看当前修改。
```
$ git difftool
```
我们还推荐使用下列设置来获得最好的difftool体验。
我们还推荐使用下列设置来获得最好的差异分析工具体验。
```ini
# Use a pager for large output, just like other git commands.
# 对于较大的输出,和其它 Git 命令一样,使用分页器
[pager]
difftool = true
# `git dft` is less to type than `git difftool`.
# `git dft` `git difftool` 更加短小
[alias]
dft = difftool
```

@ -2,49 +2,49 @@
## 从二进制安装
Difftastic以预先编译好的二进制的形式[提供Github realease](https://github.com/Wilfred/difftastic/releases) 。
Difftastic 将预先编译好的二进制文件 [提供到 GitHub realeases](https://github.com/Wilfred/difftastic/releases) 。
在以下平台上也可以使用软件包。
[![Packaging status](https://repology.org/badge/vertical-allrepos/difftastic.svg)](https://repology.org/project/difftastic/versions)
[![安装包状态](https://repology.org/badge/vertical-allrepos/difftastic.svg)](https://repology.org/project/difftastic/versions)
## 通过homebrew安装在macos或者Linux平台
## 通过 homebrew 安装macOS 或 Linux
Difftastic可以用[Homebrew](https://formulae.brew.sh/formula/difftastic)安装在macOS或Linux上。
Difftastic 可以使 [Homebrew](https://formulae.brew.sh/formula/difftastic) 安装在 macOS Linux 上。
```
$ brew install difftastic
```
## 从源码安装
## 从源码构建
### 编译要求
### 要求
Difftastic是使用Rust编写的所以你需要安装Rust。我推荐使用[rustup](https://rustup.rs/)来安装Rust
Difftastic 使用 Rust 编写,所以你需安装 Rust。我推荐使用 [rustup](https://rustup.rs/) 安装 Rust。Difftastic 要求 Rust 版本不低于 1.57
同时你也需要一个支持C++14的C++编译器。如果你正在使用GCC则GCC版本至少为8。
你也需要一个支持 C++14 C++ 编译器。如果你正在使用 GCC GCC 版本至少为 8。
### Build编译
### 构建
你可以下载并通过Cargo它是Rust的一部分来编译[difftastic on
crates.io](https://crates.io/crates/difftastic)
你可以下载并使用 CargoRust 的一部分)构建 [Difftastic on
crates.io](https://crates.io/crates/difftastic)。
```
$ cargo install difftastic
```
Difftastic使用`cc`程序箱来构建C/C++的依赖关系。这使得你可以通过环境变量`CC`和`CXX`来控制使用的编译器参照see [the cc
docs](https://github.com/alexcrichton/cc-rs#external-configuration-via-environment-variables))。
Difftastic 使用 `cc` 程序箱来构建 C/C++ 的依赖关系,这使你能通过环境变量 `CC``CXX` 来控制使用的编译器(参照 [cc
文档](https://github.com/alexcrichton/cc-rs#external-configuration-via-environment-variables))。
参考[contributing](./contributing.md)来查看有关构建的说明。
参考 [贡献](./contributing.md) 来查看有关构建的说明。
## 可选安装MIME数据库
## (可选)安装 MIME 数据库
如果有一个MIME数据库Difftastic将使用它来更准确地检测二进制文件。这个也是使用`file`命令时所调用的同一个数据库,你可能已经安装了它。
如果有一个 MIME 数据库Difftastic 将使用它来更准确地检测二进制文件。MIME 数据库在使用 `file` 命令时也需要被调用,因此你可能已经安装了它。
MIME数据库的路径[是在XDG的规定下](https://specifications.freedesktop.org/shared-mime-info-spec/0.11/ar01s03.html)
MIME 数据库的路径 [在 XDG 的规范下](https://specifications.freedesktop.org/shared-mime-info-spec/0.11/ar01s03.html)
* `/usr/share/mime/magic`
* `/usr/local/share/mime/magic`

@ -1,21 +1,22 @@
# 简介
Difftastic是一个根据文件的语法的结构化比较工具。它支持[超过20款编程语言](./languages_supported.html),当使用它的时候,就会知道它有多么的*棒*
Difftastic 是一个根据文件语法进行比较的结构化比较工具。它 [支持超过 30 种编程语言](./languages_supported.html)。当你使用时,便会知道它有多么 *棒*
Difftastic是一款开源软件使用MIT许可证并且可以[在Github上获得](https://github.com/wilfred/difftastic)。
Difftastic 是一款开源软件(使用 MIT 许可证),你可以 [在 GitHub 上查看其源代码](https://github.com/wilfred/difftastic)。
该说明书会表明当前版本DFT_VERSION_HERE。[变更记录](https://github.com/Wilfred/difftastic/blob/master/CHANGELOG.md)会记录每个版本的特性增加和bug的修复。
本说明书描述当前版本 DFT_VERSION_HERE。[更新日志](https://github.com/Wilfred/difftastic/blob/master/CHANGELOG.md) 会记录每个版本的新特性与 bug 的修复。
如果你正在寻找其他语言版本的说明书,我们同样提供了[英语版本](https://difftastic.wilfred.me.uk/)。
*如果你正寻找其他语言的说明书,我们同样提供了 [英文版](https://difftastic.wilfred.me.uk/)。*
## 语法差异分析
Difftastic会[检测编程语言](./usage.html#language-detection),爬取代码,随后比较句法树。见例子:
Difftastic [检测编程语言](./usage.html#language-detection)、解析代码,并比较语法树。以下是例子。
```
// old.rs
let ts_lang = guess(path, guess_src).map(tsp::from_language);
```
```
// new.rs
let ts_lang = language_override
@ -31,9 +32,9 @@ let ts_lang = language_override
</code>
</pre>
注意Difftastic是如何识别`.map`那段没有发生变化的,尽管它是在新的一行上以空格开头的
注意 Difftastic 是如何识别 `.map` 没有变化的,尽管它在带有空格的新行上
如果是以前那种面对行的差异分析表现会不理想。
面对行的差异分析表现不理想。
<pre><code style="display:block">$ diff -u old.rs new.rs
@ -45,10 +46,10 @@ let ts_lang = language_override
</code>
</pre>
一些文本差异分析工具也会突出单词的变化(例如GitHub或者是git的`--word-diff`但是它们无法做到理解代码本身。Difftastic永远会找到匹配的定界符你可以看到`or_else`结尾出的`)`已经被突出显示。
一些文本差异分析工具也会突出单词的变化(如 GitHub 或 git 的 `--word-diff`但它们仍无法理解代码本身。Difftastic 永远会找到匹配的定界符:你可以看到 `or_else` 结尾处的 `)`被突出显示。
## 另一种文本差异分析
## 备用的文本差异分析
如果输入的文件格式Difftastic无法理解他就会使用传统的以行为单位的文本差异分析并且会将单词高亮显示。
如果 Difftastic 不能理解输入文件,它将用常规的面向行的文本差异分析与单词高亮显示。
同时当输入的文件较大时Difftastic也会使用以行为单位的文本差异分析。
同时当输入的文件较大时Difftastic 也会使用面向行的文本差异分析。

@ -1,10 +1,10 @@
# 支持语言
# 支持语言
本页列出了 difftastic 支持的所有语言。你也可以用`difft --list-languages`查看你当前安装的版本所支持的语言。
本页列出了 Difftastic 支持的所有语言。你也可以用 `difft --list-languages` 查看你当前安装的版本所支持的语言。
## 编程语言
| 语言 | 使用的解析器 |
| 语言 | 使用的解析器 |
|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Bash | [tree-sitter/tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash) |
| C | [tree-sitter/tree-sitter-c](https://github.com/tree-sitter/tree-sitter-c) |
@ -17,10 +17,12 @@
| Elixir | [elixir-lang/tree-sitter-elixir](https://github.com/elixir-lang/tree-sitter-elixir) |
| Elm | [elm-tooling/tree-sitter-elm](https://github.com/elm-tooling/tree-sitter-elm) |
| Elvish | [ckafi/tree-sitter-elvish](https://github.com/ckafi/tree-sitter-elvish) |
| Erlang | [WhatsApp/tree-sitter-erlang](https://github.com/WhatsApp/tree-sitter-erlang) |
| Emacs Lisp | [wilfred/tree-sitter-elisp](https://github.com/Wilfred/tree-sitter-elisp) |
| Gleam | [gleam-lang/tree-sitter-gleam](https://github.com/gleam-lang/tree-sitter-gleam) |
| Go | [tree-sitter/tree-sitter-go](https://github.com/tree-sitter/tree-sitter-go) |
| Hack | [slackhq/tree-sitter-hack](https://github.com/slackhq/tree-sitter-hack) |
| Hare | [ecmma/tree-sitter-hare](https://git.sr.ht/~ecmma/tree-sitter-hare) |
| Haskell | [tree-sitter/tree-sitter-haskell](https://github.com/tree-sitter/tree-sitter-haskell) |
| Janet | [sogaiu/tree-sitter-janet-simple](https://github.com/sogaiu/tree-sitter-janet-simple) |
| Java | [tree-sitter/tree-sitter-java](https://github.com/tree-sitter/tree-sitter-java) |
@ -34,6 +36,9 @@
| Perl | [ganezdragon/tree-sitter-perl](https://github.com/ganezdragon/tree-sitter-perl) |
| PHP | [tree-sitter/tree-sitter-php](https://github.com/tree-sitter/tree-sitter-php) |
| Python | [tree-sitter/tree-sitter-python](https://github.com/tree-sitter/tree-sitter-python) |
| QML | [tree-sitter/tree-sitter-qmljs](https://github.com/yuja/tree-sitter-qmljs) |
| R | [r-lib/tree-sitter-r](https://github.com/r-lib/tree-sitter-r) |
| Racket | [6cdh/tree-sitter-racket](https://github.com/6cdh/tree-sitter-racket) |
| Ruby | [tree-sitter/tree-sitter-ruby](https://github.com/tree-sitter/tree-sitter-ruby) |
| Rust | [tree-sitter/tree-sitter-rust](https://github.com/tree-sitter/tree-sitter-rust) ([forked](https://github.com/Wilfred/tree-sitter-rust/tree/non_special_token)) |
| Scala | [tree-sitter/tree-sitter-scala](https://github.com/tree-sitter/tree-sitter-scala) |
@ -43,13 +48,12 @@
| Zig | [maxxnino/tree-sitter-zig](https://github.com/maxxnino/tree-sitter-zig) |
## 结构化文本格式
| 语言 | 使用的解析器 |
| 语言 | 使用的解析器 |
|----------|-----------------------------------------------------------------------------------|
| CSS | [tree-sitter/tree-sitter-css](https://github.com/tree-sitter/tree-sitter-css) |
| HCL | [MichaHoffmann/tree-sitter-hcl](https://github.com/MichaHoffmann/tree-sitter-hcl) |
| HTML | [tree-sitter/tree-sitter-html](https://github.com/tree-sitter/tree-sitter-html) |
| JSON | [tree-sitter/tree-sitter-json](https://github.com/tree-sitter/tree-sitter-json) |
| Newick | [delehef/tree-sitter-newick](https://github.com/delehef/tree-sitter-newick) |
| TOML | [ikatyang/tree-sitter-toml](https://github.com/ikatyang/tree-sitter-toml) |
| YAML | [ikatyang/tree-sitter-yaml](https://github.com/ikatyang/tree-sitter-yaml) |

@ -1,15 +1,15 @@
# Mercurial
Mercurial[支持另外的diff工具](https://www.mercurial-scm.org/wiki/ExtdiffExtension)与Extdiff扩展。通过在你的`.hgrc`中添加`extensions`条目来启用它。
Mercurial 在使用 Extdiff 拓展时,[支持使用外部差异分析工具](https://www.mercurial-scm.org/wiki/ExtdiffExtension)。你可以在 `.hgrc` 文件中添加 `extensions` 条目来启用它。
```
[extensions]
extdiff =
```
然后你可以运行`hg extdiff -p difft`命令(假定`difft`二进制文件存放在你的`$PATH`中
接下来,你可以运行 `hg extdiff -p difft` 命令(假定 `difft` 二进制文件已经存放在 `$PATH` 中)
你也可以为带有hg的difftastic的语句定义一个别名。在你的`.hgrc`中添加以下内容,以便用`hg dft`运行Difftastic。
您还可以定义一个别名,用 hg 运行 Difftastic。将以下内容添加到您的 `.hgrc` 中,以使用 `hg dft` 命令运行 Difftastic。
```
[extdiff]
@ -19,7 +19,7 @@ opts.dft = --missing-as-empty
## hg log -p
Mercurial没有办法改变默认的差异工具,至少就作者所知。
Mercurial 不能改变默认的差异工具,至少就作者所知。
如果你只想查看最近的一次提交的差异,你可以使用下面的方法。

@ -1,36 +1,54 @@
# 使用方法
## 差异比较文件
## 文件参数
### 比较文件
```
$ difft sample_files/before.js sample_files/after.js
```
## 差异比较文件夹
### 比较文件夹
```
$ difft sample_files/dir_before/ sample_files/dir_after/
```
Difftastic会递归地浏览这两个文件对同名的文件进行差异分析。
Difftastic 会递归地浏览这两个文件夹,对同名的文件进行差异分析。
对比的文件夹间有许多未改变的文件时,`--skip-unchanged`选项会十分有用。
### 从 stdin 读取
当对比的文件夹之间许多未改变的文件时,`--skip-unchanged`选项将会十分有用。
您可以通过指定 `-` 作为文件路径从标准输入stdin读取文件。
```
$ cat sample_files/before.js | difft - sample_files/after.js
```
## 语言检测
Difftastic根据文件的扩展名、文件名和第一行的内容来猜测所使用的语言。
Difftastic 根据文件的扩展名、文件名和第一行的内容猜测文件所用的语言。
你可以通过`--language`选项覆盖语言检测。如果输入的文件有所设定的后缀Difftastic将会处理它们并且忽略其他语言。
你可以通过 `--language` 选项覆盖语言检测。如果输入的文件有所设定的后缀, Difftastic 将会处理它们,并且忽略其他语言。
```
$ difft --language cpp before.c after.c
```
## Options选项
## 选项
Difftastic 包括一系列命令行选项,你可以使用 `difft --help` 获得完整列表。
Difftastic 也可以用环境变量进行配置,这同样可以在 `--help` 中看到。
例如,`DFT_BACKGROUND=light` 相当于 `--background=light`。这在使用 VCS 工具(例如 Git时会很有用因为此时不能直接调用 `difft` 二进制文件。
## 退出状态码
Difftastic包括一系列的命令行选项见`difft --help`获得完整列表。
2Difftastic 收到了无效参数。这包括用法无效(如参数数量不对)、无法读取路径(如路径不存在或权限不足)
Difftastic也可以用环境变量进行配置。这些可以在`--help`中看到。
1使用 `--exit-code` 选项时Difftastic 在发现任何语法变化(文本文件)或字节变化(二进制文件)
例如,`DFT_BACKGROUND=light`就相当于`--background=light`。这在使用VCS工具例如git的时候会很有用因为此时无法直接调用`difft`二进制文件。
0所有其他情况