Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit dea3a6d

Browse files
Add support for ML Kit Natural Language Translation #1287
1 parent 32d768a commit dea3a6d

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

demo-ng/app/tabs/mlkit/mlkit.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ export class MLKitComponent {
308308
console.log(`Translating '${languageIdResult.languageCode}' to 'en'`);
309309

310310
firebase.mlkit.translation.ensureTranslationModelDownloaded({
311-
from: "" + languageIdResult.languageCode,
311+
from: languageIdResult.languageCode,
312312
to: "en"
313313
}).then(() => {
314314
firebase.mlkit.translation.translateText({

docs/ML_KIT.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ To be able to use Cloud features you need to do two things:
8686
|[Image labeling](#image-labeling)|✅|✅
8787
|[Landmark recognition](#landmark-recognition)||✅
8888
|[Natural language identification](#natural-language-identification)|✅|
89+
|[Translate text](#translate-text)|✅|
8990
|[Smart reply](#smart-reply)|✅|
9091
|[Custom model inference](#custom-model-inference)|✅|✅
9192

@@ -449,6 +450,34 @@ firebase.mlkit.naturallanguageidentification.identifyNaturalLanguage({
449450
.catch(errorMessage => console.log("ML Kit error: " + errorMessage));
450451
```
451452
453+
### Translate text (Android only for now)
454+
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/master/docs/images/features/mlkit_text_translation.png" height="153px" alt="ML Kit - Translate text"/>
455+
456+
> Because of a model download bug on iOS it currently only works on Android.
457+
458+
[Firebase documentation 🌎](https://firebase.google.com/docs/ml-kit/translation)
459+
460+
#### Still image
461+
You could use MLKit to perform OCR, then identify the language, and then translate it to another language.
462+
Check [demo-ng](demo-ng) if you're interested in such an approach.
463+
464+
```typescript
465+
const firebase = require("nativescript-plugin-firebase");
466+
467+
firebase.mlkit.translation.ensureTranslationModelDownloaded({
468+
from: "nl",
469+
to: "en"
470+
}).then(() => {
471+
firebase.mlkit.translation.translateText({
472+
from: "nl",
473+
to: "en",
474+
text: "De kat krabt de krullen van de trap" // some Dutch text
475+
})
476+
.then(result => console.log(`Translated to English: ${result}`))
477+
.catch(console.error)
478+
}).catch(console.error);
479+
```
480+
452481
### Smart reply
453482
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/master/docs/images/features/mlkit_smart_reply.png" height="153px" alt="ML Kit - Smart reply"/>
454483
68.1 KB
Loading

0 commit comments

Comments
 (0)