stev/google-cloud-translate-bundle

Symfony 2 Bundle for Google Cloud Translate Basic API

v1.1 2022-04-13 06:50 UTC

This package is auto-updated.

Last update: 2024-08-31 00:33:28 UTC


README

使用Google云翻译API翻译应用程序的Symfony Bundle

#安装


composer require stev/google-cloud-translations-bundle --dev

为开发环境初始化Bundle。

$bundles[] = new \Stev\GoogleCloudTranslateBundle\StevGoogleCloudTranslateBundle();

#配置

获取您的Google Cloud密钥 (https://cloud.google.com/translate/docs/quickstarts) 并将其保存到项目中的 "app/data/key.json" 或您希望的位置。只需确保它不在公开文件夹中。

将以下配置添加到 config_dev.yml


stev_google_cloud_translate:
    keyFilePath: '%kernel.root_dir%/../data/cp-google-cloud-key.json'

您必须安装JMS Translations (https://jmsyst.com/bundles/JMSTranslationBundle)。如果它已在您的composer中,它将自动安装。以下是一个示例配置


jms_translation:
    locales: [en,fr,de]
    configs:
        app:
            dirs: ["%kernel.root_dir%/../src/AppBundle"]
            output_dir: "%kernel.root_dir%/Resources/AppBundle/translations"
            ignored_domains: [routes]
            excluded_names: ["*TestCase.php", "*Test.php"]
            excluded_dirs: [cache, data, logs]
            keep: true
            output_format: xliff

#使用方法

假设您的默认语言是英语。

  1. 使用JMS命令提取您的翻译
    php app/console translation:extract --config=app
  2. 将默认语言(英语)中的第一条消息集合翻译。所有默认语言的翻译都必须由您/开发者提供。您可以使用JMS提供的Web UI来完成此操作 https://jmsyst.com/bundles/JMSTranslationBundle/master/webinterface
  3. 使用以下命令将所有消息从默认语言翻译为Google翻译支持的其他任何语言
    php app/console stev:google_cloud_translate --config=app --sourceLocale=en --destinationLocale=fr

现在,如果您检查您的法语翻译文件,应该会发现您的所有消息都已翻译成法语。

此Bundle不会翻译以下消息

  • 那些在目标语言中不是新的消息。
  • 那些在源语言中是新的消息。
  • 可能会破坏具有复数语法或具有占位符的消息。因此,应首先手动翻译或仔细检查任何破坏。