搜索插件、代码仓与 APP 分类

插件详情v1.0.4+1

translator

一个免费且无限制的 Dart Google 翻译 API。您可以用于教育目的翻译字符串和文本。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
3400
喜欢数
746
Pub 分数
150

安装插件

flutter pub add translator

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

该翻译器包为Dart提供了一个免费且无限制的Google翻译API,使开发者能够跨多种语言翻译字符串和文本。专为教育目的设计,可无缝集成到Android、iOS、Web、macOS、Windows和Linux上的Flutter应用中。该包利用Google翻译网页界面,无需API密钥,使用方便且易于访问。它支持基本的翻译功能,设置简单,非常适合学习或原型开发多语言应用程序。

适合场景

  • 实时翻译应用内容
  • 教育类语言学习工具
  • 原型设计多语言界面
  • Flutter 应用中的简单文本翻译
  • 跨语言通信功能

主要特点

  • 无需 API 密钥
  • 支持多个平台
  • 免费且无限使用
  • 与 Flutter 的轻松集成
  • 专为教育用途设计
  • 实时文本翻译

适合对象

  • 初学者Flutter开发者
  • 教育项目
  • 非商业应用
  • 快速原型设计
  • 需要基本翻译的应用程序

使用建议

  • 不适合高流量生产环境
  • 依赖网络爬虫(可能因更新而失效)
  • 仅限 Google 翻译支持的语言
  • 无官方API保证
  • 速率限制可能会通过网站行为间接应用

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

translator

Free Google Translate API for Dart

See it in pub: https://pub.dev/packages/translator
and GitHub: https://github.com/gabrielpacheco23/google-translator

ko-fi

Usage

void main() async {
  final translator = GoogleTranslator();

  final input = "Здравствуйте. Ты в порядке?";

  translator.translate(input, from: 'ru', to: 'en').then(print);
  // prints Hello. Are you okay?
  
  var translation = await translator.translate("Dart is very cool!", to: 'pl');
  print(translation);
  // prints Dart jest bardzo fajny!

  print(await "example".translate(to: 'pt'));
  // prints exemplo
}

 

Using translate method passing the args from and to designates the language from text you're typing and the language to be translated

translator.translate("I love Brazil!", from: 'en', to: 'pt').then((s) {
    print(s);
  }); 
  // prints Eu amo o Brasil!

 

or you can omit from language and it'll auto-detect the language of source text

translator.translate("Hello", to: 'es').then(print);
// prints Hola

 

and also pass the value to a var using await

var translation = await translator.translate("I would buy a car, if I had money.", from: 'en', to: 'it');
print(translation);
// prints Vorrei comprare una macchina, se avessi i soldi.

 

The returned value is a Translation object which holds the translation stuff

var translation = await translator.translate('Translation', from: 'en', to: 'es');
print('${translation.source} (${translation.sourceLanguage}) == ${translation.text} (${translation.targetLanguage})');

// prints Translation (English) == Traducción (Spanish)

 

You can use the extension method directly on the string too

print(await "example".translate(to: 'pt'));
// prints exemplo

 

There is translateAndPrint method that prints directly

translator.translateAndPrint("This means 'testing' in chinese", to: 'zh-cn');
// prints 这意味着用中文'测试'

 

TranslatedText Widget

Moved TranslatedText widget to https://github.com/gabrielpacheco23/translated_text

API

For full API docs take a look at https://pub.dev/documentation/translator/latest/

Support my work :)

ko-fi

License

MIT License

Copyright © 2021 Gabriel Pacheco

Disclaimer

This package is developed for educational purposes only. Do not depend on this package as it may break anytime as it is based on crawling the Google Translate website. Consider buying Official Google Translate API for other types of usage.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目