yaaliuzhipeng / react-native-mlkit-translate-text

🧑‍🏫 machine learning translator for react native . based on Google MLKit.
17 stars 2 forks source link

📢 Arhived ! Use New Library (support new arch) instead (fast-mlkit-translate-text)

MLKitTranslator

A MachineLearning Language Translator

Build Powerful React Native With Greate Language Identifier And Translator Amazing ⚡️

MIT License

MLKitTranslator
⚡️ Identify Language Immediately over 50 languages supported (full list)
😎 Lazy loaded. download models when needed
🔄 Offline-first. no network required for using
📱 Multiplatform. iOS, Android
Fast. About TO Migrating to RN New Arch(JSI)
🔗 Relational. Built on MLKit Translation foundation
⚠️ Static typing Full-Support TypeScript

Why MLKitTranslator?

Key capabilities

Installation

yarn add react-native-mlkit-entity-extraction

or

npm i --save react-native-mlkit-entity-extraction

Usage

Quick example: identify language type

import MLKitTranslator, { LANG_TAGS } from './MLKitTranslator';

const Lang = 'Bonjour, c’est en français';

MLKitTranslator.identifyLanguage(text).then((result: string) => {
    setLanguageType(getHumanLang(result));
});

Translate text example: identify 、download model and translate

etc: you'd like to translate french to english

1️⃣ download model firstly

import MLKitTranslator, { LANG_TAGS } from './MLKitTranslator';
//better do this in async function
await MLKitTranslator.downloadModel(LANG_TAGS.FRENCH);
await MLKitTranslator.downloadModel(LANG_TAGS.ENGLISH);

Remember !✨ Always check model firstly ; Do not translate text if the model is not downloaded

use NativeMLKitTranslateText.isModelDownloaded to check

2️⃣ translate text

await MLKitTranslator.translateText(text, LANG_TAGS.FRENCH, LANG_TAGS.ENGLISH);

// 🎉 got it, dude

Author and license

ReactNativeMLKitTranslateText was created by @yaaliuzhipeng

react-native-mlkit-translate-text is available under the MIT license. See the LICENSE file for more info.