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

插件详情v2.3.5

auto_translator

一个命令行工具,使用云翻译服务来翻译 ARB 文件。

macOSWindowsLinux
近 30 天下载
453
喜欢数
35
Pub 分数
150

安装插件

flutter pub add auto_translator

插件介绍

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

一个命令行工具,旨在使用云翻译服务自动化 ARB(App Resource Bundle)文件的翻译。它通过将英文 ARB 文件转换为多种目标语言,简化了本地化工作流程,减少了国际化过程中的手动操作。非常适合管理多语言 Flutter 应用的开发者,可无缝集成到现有的构建流程中,并支持在 macOS、Windows 和 Linux 上跨平台运行。该工具利用外部翻译 API,确保翻译质量的同时,保持语言文件之间的一致性。

适合场景

  • 自动化 ARB 文件翻译
  • 与 CI/CD 流水线集成
  • 支持多语言 Flutter 应用程序
  • 减少人工翻译工作量
  • 批量更新翻译
  • 跨团队同步语言文件

主要特点

  • 基于云的 API 翻译
  • 命令行界面
  • 跨平台兼容性
  • ARB 文件格式支持
  • 批量翻译处理
  • 与 Flutter 本地化工作流程集成

适合对象

  • Flutter 开发人员管理多种语言
  • 使用 ARB 进行本地化的团队
  • 翻译的CI/CD自动化
  • 需要频繁翻译更新的项目
  • 寻求节省时间的本地化工具的开发者

使用建议

  • 需要互联网访问以进行翻译API调用
  • 依赖第三方翻译服务的质量
  • 高用量情况下的潜在成本
  • 需要正确的 API 密钥配置
  • 仅限 ARB 文件格式
  • 可能需要为自定义翻译提供商进行额外设置

原始 README

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

Auto Translator

A command-line tool that simplifies translation of an ARB template file to selected languages. This package is designed to work seamlessly with the flutter_localizations and intl packages, Flutter's preferred internationalization approach.

Features

  • Seamless integration with flutter_localizations and intl packages.
  • Works with Google Cloud Translate & DeepL Translate.
  • Minimal quota usage.
  • Works with simple & complex ARB strings, conditions, and variables.
  • Uses placeholder examples for more accurate translations involving proper nouns and other unique cases.
  • Specify translator service and/or source language for individual target languages.

Support the developer

If you found this package useful, please consider contribuitng to it's continued development. Or just show the developer a little love & support. Every little bit helps!

Buy me a coffee

Getting Started

1. Setup Translation Service(s)

Auto Translator supports Google Cloud Translate and DeepL out of the box. You may specify either one as your primary service in the l10n.yaml config file. If neither is provided, the default (Google) is used. You may also specify different translators on a per-language basis, as seen in Preferred Services.

If you are configuring only one service, you can save the API key in a file in the project root directory called translator_key or as a json map in translator_keys. If configuring both services, you must use the json map approach.

:warning: DO NOT publish your key file to Github or similar VCS.

You can also specify an alternate key file path.

Google Cloud Translate

If you do not have a Google Cloud Project with the Cloud Translation API enabled, follow the guide here.

DeepL Translate

If you do not have DeepL API access, follow DeepL's guide to creating an account and obtaining API access here

2. Add auto_translator to your project

Add auto_translator under dev_dependencies in pubspec.yaml

dev_dependencies:
  auto_translator: ^2.3.6
3. Setup the config files

auto_translator uses the same config file as the intl package, Flutter's recommended package for internationalizing your app, as explained here.

If you have not already created the l10n.yaml file, do so now.

arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart

translator:
  #Defaults to Google Translate.
  service: Google

  targets:
    - es-ES
    - fr
    - ja

The first three parameters are used by intl as well as auto_translator. The translator section is specific to auto_translator.

The targets parameter is required and tells auto_translator which languages to translate the template file to. Available languages can be found here.

You can also configure preferred source templates for any given target language.

Regional Designations

You can use 2-letter language codes and regional designations (en-US, en-GB, es-Es, etc.).

4. Run the package

Once configured, run the package from the command line.

flutter pub get
dart run auto_translator

All translations will be placed in the defined location and be compatible with flutter_localizations and intl.

Additional Usage

Placeholder Examples

Some translations are more accurate when using an example in place of a generic placeholder variable name. auto_translator now passes a placeholder's example if provided to ensure better quality translations.

"viewingArtwork": "Now viewing {artworkTitle}.",
  "@viewingArtwork": {
      "placeholders": {
          "artworkTitle": {
              "type": "String",
              "example": "Mona Lisa"
          }
      }
  }
Force Translation

To prevent unecessary Google Cloud Translate quota usage, messages that already exist in a target ARB file are not retranslated. You can force a translation by adding the force parameter to translator options in a message's metadata in the template file.

"title": "New Title",
"@title": {
  "description": "...",
  "translator": {
    "force": true
  }
}
Ignore ARB String

You can also tell the translator to ignore a particular message with the ignore tag.

"doNotTranslate": "DO NOT TRANSLATE THIS STRING!!!",
"@doNotTranslate": {
  "description": "...",
  "translator": {
    "ignore": true
  }
}
Preferred Templates

Sometimes, you may wish to specify a language that translates more accurately to a target than the language used in the template-arb-file. For that, you can provide a prefer-lang-templates map to specify a preferred source language to use as a template for any target language.

translator:
  # use es-ES template for fr translation ja for ko
  # all other translations will use [template-arb-file]
  prefer-lang-templates:
    fr: es
    ko: ja
Preferred Services

As one service may outperform the other in a given language you may wish to specify a service an a per-language basis. This can be done by providing a prefer-service map in the config file.

translator:
  # use DeepL for tr and uk
  # all other translations will use the primary service
  # (presumably Google in this case)
  prefer-service:
    # capitilization does not matter for service name
    DeepL:
      - tr
      - uk

Each API key must be provided in the key file (service name capitalization does not matter).

{
  "google": "CLOUD_TRANSLATE_API_KEY",
  "deepL": "DEEP_L_API_KEY"
}
Verbose output

You can enable verbose output with the --verbose (-v) flag. This is especially helpful in pinpointing the cause of errors.

Alternate config file

By default, the config file is named l10n.yaml and is located in the project's root directory. You can pass in an alternate file path when running on the command line using the --config-file option.

Alternate key file

By default, auto_translator looks for keys in the project root at translator_keys or translator_key. You may specify a different location in the config file.

translator:
  key_file: path/to/key/file

所属分类

依赖

依赖清单 3 项

源码仓库

使用此插件的项目

暂无相关数据。