@capacitor-mlkit/translation

中文文档
8.2.2发布于 2026/10/31Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 7082

Capacitor plugin for ML Kit Translation on Android and iOS.

原始使用文档
文档目录31 节
  1. Use Cases
  2. Compatibility
  3. Installation
  4. Android
  5. iOS
  6. Configuration
  7. Demo
  8. Usage
  9. Translate a text
  10. Download a language model
  11. List the downloaded language models
  12. Delete a downloaded language model
  13. API
  14. deleteDownloadedModel(...)
  15. downloadModel(...)
  16. getDownloadedModels()
  17. translate(...)
  18. Interfaces
  19. Enums
  20. FAQ
  21. Which platforms are supported by this plugin?
  22. Which languages are supported?
  23. Does the translation work offline?
  24. How much storage do the language models require?
  25. What if I don't know the source language of the text?
  26. Can I install this plugin using Swift Package Manager?
  27. Related Plugins
  28. Terms & Privacy
  29. Newsletter
  30. Changelog
  31. License

Capacitor ML Kit Translation Plugin

Unofficial Capacitor plugin for ML Kit Translation.[^1]

Use Cases

The Translation plugin is typically used to translate text directly on the device, for example:

  • Chat translation: Translate incoming messages into the language of the user.
  • Content translation: Let users translate user-generated content such as comments, reviews, or posts.
  • Offline translation: Download language models in advance so users can translate text without an internet connection.
  • Travel apps: Help travelers translate text on the go, even when roaming without a data connection.

Compatibility

Plugin VersionCapacitor VersionStatus
8.x.x>=8.x.xActive support
7.x.x7.x.xDeprecated
6.x.x6.x.xDeprecated
5.x.x5.x.xDeprecated

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:

npx skills add capawesome-team/skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capacitor-mlkit/translation` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capacitor-mlkit/translation
npx cap sync

Attention: This plugin only supports CocoaPods for iOS dependency management. Swift Package Manager (SPM) is not supported for the ML Kit SDK, see this comment.

Android

Variables

If needed, you can define the following project variable in your app’s variables.gradle file to change the default version of the dependency:

  • $mlkitTranslateVersion version of com.google.mlkit:translate (default: 17.0.3)

This can be useful if you encounter dependency conflicts with other plugins in your project.

iOS

Minimum Deployment Target

Make sure to set the deployment target in your ios/App/Podfile to at least 15.5:

platform :ios, '15.5'

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-mlkit-plugin-demo

Usage

The following examples show how to translate a text, download a language model, list the downloaded language models, and delete a downloaded language model.

Translate a text

Use the translate(...) method to translate a text from a source language to a target language. If the language model for the given languages is not downloaded yet, it will be downloaded automatically, which may take some time. Only available on Android and iOS:

import { Translation, Language } from '@capacitor-mlkit/translation';

const translate = async () => {
  const { text } = await Translation.translate({
    text: 'Good morning!',
    sourceLanguage: Language.English,
    targetLanguage: Language.German,
  });
  return text;
};

Download a language model

Download a language model in advance to enable offline translation. Language models are around 30MB in size, so be sure to only download the models you need and only download them using a WiFi connection unless the user has specified otherwise. Only available on Android and iOS:

import { Translation, Language } from '@capacitor-mlkit/translation';

const downloadModel = async () => {
  await Translation.downloadModel({
    language: Language.English,
  });
};

List the downloaded language models

Get the languages for which a model has already been downloaded to the device. Only available on Android and iOS:

import { Translation } from '@capacitor-mlkit/translation';

const getDownloadedModels = async () => {
  const { languages } = await Translation.getDownloadedModels();
  return languages;
};

Delete a downloaded language model

Delete the language model for a given language, for example to free up storage space on the device. Only available on Android and iOS:

import { Translation, Language } from '@capacitor-mlkit/translation';

const deleteDownloadedModel = async () => {
  await Translation.deleteDownloadedModel({
    language: Language.English,
  });
};

API

deleteDownloadedModel(...)

deleteDownloadedModel(options: DeleteDownloadedModelOptions) => Promise<void>

Delete the language model for the given language.

Only available on Android and iOS.

ParamType
optionsDeleteDownloadedModelOptions

Since: 0.0.1


downloadModel(...)

downloadModel(options: DownloadModel) => Promise<void>

Download a language model for offline translation.

Language models are around 30MB in size, so be sure to only download the models you need and only download them using a WiFi connection unless the user has specified otherwise.

Only available on Android and iOS.

ParamType
optionsDownloadModel

Since: 0.0.1


getDownloadedModels()

getDownloadedModels() => Promise<GetDownloadedModelsResult>

Get the languages for which a model has been downloaded.

Only available on Android and iOS.

Returns: Promise<GetDownloadedModelsResult>

Since: 0.0.1


translate(...)

translate(options: TranslateOptions) => Promise<TranslateResult>

Translate the given text.

If the language model for the given source and target languages is not downloaded, it will be downloaded automatically which may take some time. If you want to avoid this, use the downloadModel(...) method to download the model first.

Only available on Android and iOS.

ParamType
optionsTranslateOptions

Returns: Promise<TranslateResult>

Since: 0.0.1


Interfaces

DeleteDownloadedModelOptions

PropTypeDescriptionSince
languageLanguageThe language for which to delete the model.0.0.1

DownloadModel

PropTypeDescriptionSince
languageLanguageThe language to download the model for.0.0.1

GetDownloadedModelsResult

PropTypeDescription
languagesLanguage[]The languages for which a model has been downloaded.

TranslateResult

PropTypeDescriptionSince
textstringThe translated text.0.0.1

TranslateOptions

PropTypeDescriptionSince
textstringThe text to translate.0.0.1
sourceLanguageLanguageThe source language of the text. If you don't know the source language, you can use the Language</a> Identification plugin to detect it.0.0.1
targetLanguageLanguageThe target language to translate the text to.0.0.1

Enums

Language

MembersValueSince
Afrikaans'af'0.0.1
Arabic'ar'0.0.1
Belarusian'be'0.0.1
Bulgarian'bg'0.0.1
Bengali'bn'0.0.1
Catalan'ca'0.0.1
Czech'cs'0.0.1
Welsh'cy'0.0.1
Danish'da'0.0.1
German'de'0.0.1
Greek'el'0.0.1
English'en'0.0.1
Esperanto'eo'0.0.1
Spanish'es'0.0.1
Estonian'et'0.0.1
Persian'fa'0.0.1
Finnish'fi'0.0.1
French'fr'0.0.1
Irish'ga'0.0.1
Galician'gl'0.0.1
Gujarati'gu'0.0.1
Hebrew'he'0.0.1
Hindi'hi'0.0.1
Croatian'hr'0.0.1
Haitian'ht'0.0.1
Hungarian'hu'0.0.1
Indonesian'id'0.0.1
Icelandic'is'0.0.1
Italian'it'0.0.1
Japanese'ja'0.0.1
Georgian'ka'0.0.1
Kannada'kn'0.0.1
Korean'ko'0.0.1
Lithuanian'lt'0.0.1
Latvian'lv'0.0.1
Macedonian'mk'0.0.1
Marathi'mr'0.0.1
Malay'ms'0.0.1
Maltese'mt'0.0.1
Dutch'nl'0.0.1
Norwegian'no'0.0.1
Polish'pl'0.0.1
Portuguese'pt'0.0.1
Romanian'ro'0.0.1
Russian'ru'0.0.1
Slovak'sk'0.0.1
Slovenian'sl'0.0.1
Albanian'sq'0.0.1
Swedish'sv'0.0.1
Swahili'sw'0.0.1
Tamil'ta'0.0.1
Telugu'te'0.0.1
Thai'th'0.0.1
Tagalog'tl'0.0.1
Turkish'tr'0.0.1
Ukrainian'uk'0.0.1
Urdu'ur'0.0.1
Vietnamese'vi'0.0.1
Chinese'zh'0.0.1

FAQ

Which platforms are supported by this plugin?

The plugin is available on Android and iOS. All methods are only available on Android and iOS, so there is no web implementation.

Which languages are supported?

The plugin supports more than 50 languages, including English, German, Spanish, French, Chinese, and Japanese. See the Language enum in the API section for the complete list.

Does the translation work offline?

Yes, the translation is performed on the device using downloaded language models. Use the downloadModel(...) method to download a language model in advance, for example while the device is connected to a WiFi network. Otherwise, the model is downloaded automatically on the first call to translate(...), which may take some time.

How much storage do the language models require?

Language models are around 30MB in size, so be sure to only download the models you need. You can delete a model that is no longer needed using the deleteDownloadedModel(...) method.

What if I don't know the source language of the text?

The translate(...) method requires a source language. You can use the ML Kit Language Identification plugin to detect the language of a text before translating it.

Can I install this plugin using Swift Package Manager?

No, this plugin only supports CocoaPods for iOS dependency management because the ML Kit SDK itself does not support Swift Package Manager. Also make sure to set the deployment target in your ios/App/Podfile to at least 15.5 (see Installation).

  • Speech Recognition: Transcribe speech into text, for example to translate it afterwards.
  • Speech Synthesis: Synthesize speech from text, for example to read translated text aloud.
  • App Language: Manage the app's own language override, independent of the device language.
  • ML Kit Entity Extraction: Extract entities such as addresses and dates from text before or after translating it.

Terms & Privacy

This plugin uses the Google ML Kit:

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

Changelog

See CHANGELOG.md.

License

See LICENSE.

[^1]: This project is not affiliated with, endorsed by, sponsored by, or approved by Google LLC or any of their affiliates or subsidiaries.

版本与发布记录

@capacitor-mlkit/translation 共发布 34 个版本,首次发布于 2023/02/25;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.2.2latest2026/10/319 天前
8.2.12026/09/101 个月前
8.1.12026/08/312 个月前
8.1.02026/05/076 个月前
8.0.12026/02/198 个月前
8.0.02025/12/1710 个月前

其他发布通道:next → 7.0.0-next.4,dev → 7.0.0-dev.1765885034。

关于 @capacitor-mlkit/translation 的常见问题

@capacitor-mlkit/translation 是什么?

Capacitor plugin for ML Kit Translation on Android and iOS.

如何安装 @capacitor-mlkit/translation?

在项目目录运行 npm install @capacitor-mlkit/translation,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capacitor-mlkit/translation 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capacitor-mlkit/translation 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capacitor-mlkit/translation 可以商用吗?

@capacitor-mlkit/translation 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@capacitor-mlkit/translation 的下载量有多少?

根据 npm 官方下载统计,@capacitor-mlkit/translation 在 2026/10/09 – 2026/11/07 这 30 天内被下载 7,082 次,日均约 236 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capacitor-mlkit/translation 还在维护吗?

最新版本 8.2.2 发布于 2026/10/31(9 天前);至今共发布 34 个版本,其中过去 12 个月发布了 9 个;首次发布于 2023/02/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。