stev / google-cloud-translate-bundle
Symfony 2 Bundle for Google Cloud Translate Basic API
Installs: 15
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.5
- ext-json: *
- google/cloud-translate: ^1.12
- jms/translation-bundle: ^1.4
- symfony/framework-bundle: 2.7.*|2.8.*
- symfony/symfony: 2.7.*|2.8.*
Requires (Dev)
- symfony/phpunit-bridge: ^5.2
This package is auto-updated.
Last update: 2024-10-31 00:25:37 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.
- Extract your translations using JMS command
php app/console translation:extract --config=app
- 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.
- 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.