# General Translation Integrations: paraglide-context
URL: https://generaltranslation.com/ja/docs/integrations/paraglide/reference/paraglide-context.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Paraglide JS の各メッセージが使用されている箇所の周辺ソースコードをメタデータファイルに書き出します。paraglide-context コマンドの API リファレンスです。

このコマンドは `@generaltranslation/paraglide-js` に同梱されています。1 回の実行でアプリを解析し、メタデータファイルを書き出して終了します。[`gt translate`](/docs/cli/reference/commands/translate) より前に実行してください。

## 概要 [#overview]

```bash
npx paraglide-context [root] [options]
```

`root` にはプロジェクト、またはその中のディレクトリを指定します。デフォルトは作業ディレクトリです。フラグで指定するパスはすべてプロジェクトルートからの相対パスになります。プロジェクトルートとは、`root` と同じ階層またはそれより上の階層にある、最も近い `package.json` の場所を指します。

[`collectContext`](/docs/integrations/paraglide/reference/collect-context) は同じ処理をコードから実行するもので、受け取るオプションも同じです。

## 仕組み [#how-it-works]

* 原文ファイルを選択し、それらのインポート文を解決したうえで、Paraglide JS メッセージの使用箇所をすべて検出します ([使用箇所の検出](/docs/integrations/paraglide/reference/usage-detection)を参照) 。
* ベースロケールの各メッセージファイルと同じ場所に、`messages/en.metadata.json` のようなメタデータファイルを書き出します ([メタデータファイル](/docs/integrations/paraglide/reference/metadata-files)を参照) 。
* アプリのバンドラーを実行することはありません。インポートのエイリアスは `tsconfig.json`、`package.json`、および Vite、webpack、rspack の設定ファイルから読み取ります。
* スキップした項目があれば警告を出力します。警告が出ても終了コードは変わりません。

## フラグ [#flags]

各フラグは [`collectContext`](/docs/integrations/paraglide/reference/collect-context#options) のオプションを1つずつ設定します。各オプションの動作の詳細はそちらを参照してください。*繰り返し可* と記載されたフラグは、複数回指定することで複数の値を渡せます。

| パラメータ                 | 説明                                                                                                                                             | 型          | 任意 | デフォルト          |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | -- | -------------- |
| `[root]`              | プロジェクト、またはその中のディレクトリ。[`root`](/docs/integrations/paraglide/reference/collect-context#root) を設定します。                                             | `string`   | はい | 作業ディレクトリ       |
| `--include <path>`    | 解析対象のパスまたは glob。繰り返し可。[`include`](/docs/integrations/paraglide/reference/collect-context#include) を設定します。                                      | `string[]` | はい | プロジェクト全体       |
| `--exclude <path>`    | 解析から除外するパスまたは glob。繰り返し可。[`exclude`](/docs/integrations/paraglide/reference/collect-context#exclude) を設定します。                                   | `string[]` | はい | テストとツールの設定ファイル |
| `--outdir <dir>`      | 検証を行わずに使用する Paraglide JS の出力ディレクトリ。繰り返し可。[`outdirs`](/docs/integrations/paraglide/reference/collect-context#outdirs) を設定します。                   | `string[]` | はい | 自動検出           |
| `--project <dir>`     | メッセージのメタデータファイルを生成する対象の inlang プロジェクト。繰り返し可。[`inlangProjects`](/docs/integrations/paraglide/reference/collect-context#inlang-projects) を設定します。 | `string[]` | はい | 自動検出           |
| `--alias <name=path>` | `~=./src` のようなインポートエイリアス。`.` で始まる置換先はプロジェクトルートを基準に解決されます。繰り返し可。[`alias`](/docs/integrations/paraglide/reference/collect-context#alias) を設定します。 | `string[]` | はい | —              |
| `--no-bundler-config` | バンドラーの設定ファイルからエイリアスを読み取りません。[`bundlerConfigs`](/docs/integrations/paraglide/reference/collect-context#bundler-configs) を `[]` に設定します。          | `boolean`  | はい | `false`        |
| `--radius <lines>`    | 各使用箇所の前後に含める文脈の行数。0以上の整数で指定します。[`radius`](/docs/integrations/paraglide/reference/collect-context#radius) を設定します。                               | `number`   | はい | `10`           |
| `--verbose`           | 検出した使用箇所、解析したファイル、使用した出力ディレクトリ、エイリアスの読み取り元となった設定ファイルの概要を出力します。                                                                                 | `boolean`  | はい | `false`        |
| `-h, --help`          | 使用方法を表示します。                                                                                                                                    | `boolean`  | はい | `false`        |

`targets`、`languages`、`autoImports`、`conditions`、`rootDirectory` の各オプションには対応するフラグがありません。これらは [`collectContext`](/docs/integrations/paraglide/reference/collect-context) で設定してください。

## 例 [#example]

```bash
# 作業ディレクトリ内のアプリを解析する
npx paraglide-context

# モノレポ内の特定のアプリを解析し、サマリーを表示する
npx paraglide-context apps/web --verbose

# src と共有パッケージを解析し、前後5行のコンテキストを含める
npx paraglide-context --include src --include ../shared --radius 5

# エイリアスを宣言し、バンドラーの設定をスキップする
npx paraglide-context --alias ~=./src --no-bundler-config
```

## その他の注意事項 [#notes]

| 終了コード | 意味                                                                |
| ----- | ----------------------------------------------------------------- |
| `0`   | 実行が完了しました (警告の有無は問いません) 。                                         |
| `1`   | メタデータファイルを書き込めなかった場合など、エラーにより実行が中断されました。エラー内容が出力されます。             |
| `2`   | 不明なフラグ、値の不足、`root` の複数指定、または `--radius` が非負整数でない場合です。使用方法が出力されます。 |

* 警告は `[paraglide-context]` で始まり、標準エラー出力に出力されます。
* メタデータファイルは内容が変わった場合にのみ書き込まれます。そのため、翻訳元に変更がなければ、2 回目の実行では何も書き込まれません。

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
