npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@capacitor-mlkit/translation

v6.1.0

Published

Capacitor plugin for ML Kit Translation.

Downloads

270

Readme

@capacitor-mlkit/translation

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

Installation

npm install @capacitor-mlkit/translation
npx cap sync

Android

Variables

This plugin will use the following project variables (defined in your app’s variables.gradle file):

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

Configuration

No configuration required for this plugin.

Demo

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

Usage

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

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

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

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

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

API

deleteDownloadedModel(...)

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

Delete the language model for the given language.

Only available on Android and iOS.

| Param | Type | | ------------- | ------------------------------------------------------------------------------------- | | options | DeleteDownloadedModelOptions |

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.

| Param | Type | | ------------- | ------------------------------------------------------- | | options | DownloadModel |

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.

| Param | Type | | ------------- | ------------------------------------------------------------- | | options | TranslateOptions |

Returns: Promise<TranslateResult>

Since: 0.0.1


Interfaces

DeleteDownloadedModelOptions

| Prop | Type | Description | Since | | -------------- | --------------------------------------------- | ------------------------------------------- | ----- | | language | Language | The language for which to delete the model. | 0.0.1 |

DownloadModel

| Prop | Type | Description | Since | | -------------- | --------------------------------------------- | --------------------------------------- | ----- | | language | Language | The language to download the model for. | 0.0.1 |

GetDownloadedModelsResult

| Prop | Type | Description | | --------------- | ----------------------- | ---------------------------------------------------- | | languages | Language[] | The languages for which a model has been downloaded. |

TranslateResult

| Prop | Type | Description | Since | | ---------- | ------------------- | -------------------- | ----- | | text | string | The translated text. | 0.0.1 |

TranslateOptions

| Prop | Type | Description | Since | | -------------------- | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | | text | string | The text to translate. | 0.0.1 | | sourceLanguage | Language | The 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 | | targetLanguage | Language | The target language to translate the text to. | 0.0.1 |

Enums

Language

| Members | Value | Since | | ---------------- | ----------------- | ----- | | 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 |

Terms & Privacy

This plugin uses the Google ML Kit:

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.