# General Translation Integrations: paraglide-context install
URL: https://generaltranslation.com/zh/docs/integrations/paraglide/reference/install.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 在收集 Paraglide JS 源代码上下文之前，安装某种组件格式所需的框架软件包。paraglide-context install 命令的 API 参考。

当 collect 运行警告某种格式所需的工具缺失时，请在应用目录中运行此命令。该命令不会分析源文件，也不会写入元数据。

## 概览 [#overview]

```bash
npx paraglide-context install <language...> [options]
```

[`paraglide-context`](/docs/integrations/paraglide/reference/paraglide-context) 负责写入元数据。此子命令则为你指定的语言安装该命令所需加载的工具。

## 工作原理 [#how-it-works]

* 该命令会使用为项目检测到的包管理器安装开发依赖项。若未检测到包管理器，则使用 npm。
* 项目已能加载的软件包会被跳过。若所有软件包均已可用，该命令会列出这些软件包，而不会运行包管理器。
* 多种语言共同需要的软件包只会安装一次。
* 软件包会被添加到 [`--root`](#flags) 所在目录或其上层目录中距离最近的 `package.json` 所属的项目中。
* TypeScript 以 `typescript@^6` 的形式安装，其他软件包则不指定版本范围。TypeScript 7 没有 JavaScript API，因此若已安装该版本的 TypeScript，`vue`、`svelte`、`markdown` 和 `mdx` 会使命令终止，且本次运行不会安装任何内容。

| 语言         | 软件包                                         |
| ---------- | ------------------------------------------- |
| `vue`      | `@vue/language-core`, `typescript@^6`       |
| `svelte`   | `svelte2tsx`, `svelte`, `typescript@^6`     |
| `astro`    | `@astrojs/astro2tsx`                        |
| `mdx`      | `@mdx-js/language-service`, `typescript@^6` |
| `markdown` | `@vue/language-core`, `typescript@^6`       |
| `angular`  | `@angular/compiler`                         |
| `analog`   | `@angular/compiler`                         |
| `marko`    | `@marko/language-tools`, `@marko/compiler`  |
| `ember`    | `@glint/ember-tsc`                          |

`angular` 涵盖内联 Angular 组件模板和 Angular HTML 模板。`analog` 使用同一个 `@angular/compiler` 软件包。`markdown` 指 VitePress Markdown，所用软件包与 `vue` 相同。Pug 插件需单独安装：如果模板使用了 `lang="pug"`，请安装 `@vue/language-plugin-pug`。

collect 运行时给出的警告可能会提到某个将这些工具引入应用的软件包，例如 `vue-tsc` 或 `svelte-check`。安装该软件包或运行此命令，均可满足该格式的要求 (参见[支持的文件格式](/docs/integrations/paraglide/reference/file-formats)) 。

## 选项 [#flags]

| 参数              | 描述                                        | 类型         | 可选 | 默认      |
| --------------- | ----------------------------------------- | ---------- | -- | ------- |
| `<language...>` | 上表中的语言名称，至少传入一个。                          | `string[]` | 否  | —       |
| `--root <dir>`  | 项目中的某个目录。软件包会添加到离该目录最近的 `package.json` 中。 | `string`   | 是  | 当前工作目录  |
| `-h, --help`    | 显示用法说明。                                   | `boolean`  | 是  | `false` |

## 示例 [#example]

```bash
# 为工作目录中的应用安装 Vue 和 Svelte 工具
npx paraglide-context install vue svelte

# 为 monorepo 中的某个应用安装 MDX 工具
npx paraglide-context install mdx --root apps/web
```

## 其他说明 [#notes]

| 退出码 | 含义                                                    |
| --- | ----------------------------------------------------- |
| `0` | 软件包已安装，或各软件包均已可用。                                     |
| `1` | 无法启动包管理器，或项目的 TypeScript 未提供 JavaScript API。          |
| `2` | 未指定语言、语言未知、标志未知或缺少标志值。此时会打印用法说明；语言未知的情况除外，此时会列出支持的语言。 |

* 如果包管理器启动后运行失败，该命令会以包管理器的退出码退出。
* 该命令自身的错误会输出到标准错误，并以 `paraglide-context Error:` 开头。包管理器的输出则原样显示。

## Sitemap

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