Use tgrep to search source documents and compare matching lines with their translations in context.
I built tgrep while translating the Kubernetes documentation so I could look up translations of the same term across multiple pages at once.
Watch the search-to-editor demo (GIF)
Install with Homebrew on macOS or Linux.
brew install antfrog/tap/tgrepHomebrew downloads a prebuilt binary for Apple Silicon, Intel Macs, or Linux on ARM64 and x86_64.
From a clone of this repository, use Go 1.23 or later and a C compiler to build and install the binary.
GOBIN="$HOME/.local/bin" go install ./cmd/tgrepYou can also run ./tgrep from the clone. The launcher builds bin/tgrep and runs it with your current working directory. Run the test suite with go test ./....
Keep the same document path in each language directory. For example, the translations of en/guide/setup.md go in ko/guide/setup.md and ja/guide/setup.md.
cd docs
tgrep 'sign in'Use Up and Down to select a result and preview it in the source and available translations. When searching English, the Japanese preview highlights the same line that opens in the side-by-side comparison. Type part of a path, such as setup, or a source line number to narrow the list. Press Esc to quit.
Search patterns are case-insensitive extended regular expressions. Only source files with at least one translation are searched. Hidden paths and untracked files covered by Git ignore rules are skipped.
Search skips code blocks fenced with three or more backticks. Matches after a block keep their original line numbers.
Press F1 on a result to open the source on the left and the first target language on the right. F2 opens the second target language. With TGREP_TARGET_LANGS=ko,ja, F1 opens Korean and F2 opens Japanese. These shortcuts use vim on your PATH and require its WinScrolled event (available in Vim 9).
When the comparison opens, matching text is highlighted in both panes using the original search pattern.
- The panes scroll together by default. Long lines wrap to fit. Use Up and Down to move one screen line, or Page Up and Page Down to move one page.
- To scroll independently, press
s, then select the source with Left or the translation with Right. Presssagain to link both panes at the active pane’s position. - Press
Escto return to the same search result.
For English–Japanese comparisons, tgrep finds the nearest preceding shared anchor or corresponding Markdown heading, then counts paragraphs and lines from there. With no matching anchor or heading, it counts from the start of the document. If the match falls beyond the end of the Japanese paragraph, the cursor lands on its last line. Linked scrolling keeps the initial line offset between panes.
Press Enter on a search result to open the first available translation in TGREP_TARGET_LANGS order. It opens in $EDITOR, which defaults to vi. Here the English match is on line 6, and the Korean translation is being edited on that line in Vim.
vi, Vim, Neovim, nano, Emacs and VS Code jump to the selected line. Other editors receive the file path.
Create ~/.config/tgrep/config to set your defaults. tgrep sources this file with zsh when available and uses /bin/sh otherwise. The example works in both shells.
TGREP_DOCS_DIR="$HOME/kubernetes/website/content"
TGREP_ORIGIN_LANG=en
TGREP_TARGET_LANGS=ko,ja
TGREP_ENTER_ACTION=editBefore searching, tgrep checks the source directory and every configured translation directory. If a directory is missing, tgrep lists the affected paths and exits. If you have only English and Korean documents, set TGREP_TARGET_LANGS=ko in your config.
| Setting | Default | Meaning |
|---|---|---|
TGREP_DOCS_DIR |
. |
Directory containing the language directories. Relative paths start at the current working directory. |
DOCS_{LANGCODE}_ROOT |
TGREP_DOCS_DIR/<lang> |
Source or translation directory for one language. Relative paths start at TGREP_DOCS_DIR. Use DOCS_PT_BR_ROOT for pt-BR. |
TGREP_ORIGIN_LANG |
en |
Source language to search. |
TGREP_TARGET_LANGS |
ko,ja |
Comma-separated target languages to preview. |
TGREP_ENTER_ACTION |
edit |
Enter action. edit opens the first available translation in $EDITOR (default: vi). print outputs the source path, line number, and matching text. |
TGREP_BEFORE_LINES |
3 |
Number of lines before the match (0 or more). |
TGREP_AFTER_LINES |
3 |
Number of lines after the match (0 or more). |
TGREP_BEFORE_LINES_{LANGCODE} |
Value of TGREP_BEFORE_LINES |
Leading context by language. For example, TGREP_BEFORE_LINES_PT_BR=1 shows one preceding line for pt-BR. |
TGREP_AFTER_LINES_{LANGCODE} |
Value of TGREP_AFTER_LINES |
Trailing context for one language. For example, TGREP_AFTER_LINES_KO=5 shows five following lines in Korean. |
For example, set DOCS_KO_ROOT="$HOME/website-ko/content" if your Korean translation is in a separate checkout. The Korean translation of en/guide/setup.md is then read from $HOME/website-ko/content/guide/setup.md.
A nonempty environment variable overrides the corresponding file setting for that invocation. For example, to preview only Japanese with the root and source language from your config:
TGREP_TARGET_LANGS=ja tgrep 'sign in'

