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-12-01 00:20:29 UTC


README

A Symfony bundle to translate your application using Google cloud Translations API

#Install


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

Initialize the bundle for dev env.

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

#Configuration

Get your Google Cloud Key (https://cloud.google.com/translate/docs/quickstarts) and save it in your project in "app/data/key.json" or anywhere you want. Just make sure it's not a public folder.

Add the following configuration to config_dev.yml


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

You must have JMS Translations installed (https://jmsyst.com/bundles/JMSTranslationBundle). If not already present in your composer it will be automatically installed. Here's a sample configuration


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

#Usage

Let's suppose your default language is English.

  1. Extract your translations using JMS command
    php app/console translation:extract --config=app
  2. Translate the first set of messages in your default language (english). All default language translations must be provided by you/developers. You can use the web UI provided by JMS for that https://jmsyst.com/bundles/JMSTranslationBundle/master/webinterface.
  3. Use the following command to translate all messages from your default language to any other language supported by Google Translations:
    php app/console stev:google_cloud_translate --config=app --sourceLocale=en --destinationLocale=fr

Now if you check your French translations files you should find all of your messages translated into French.

This bundle will not translate the following messages:

  • The ones that are not NEW in the destination language.
  • The ones that are NEW in the source language.
  • Might break the messages with plural syntax or with placeholders. So those should be translated manually firstly or carefully checked afterwards for any break.