lsv/google-translation-bundle

Symfony bundle to translate text with google translation

Installs: 35

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

v1.0.0 2024-10-31 21:23 UTC

This package is auto-updated.

Last update: 2024-10-31 21:25:00 UTC


README

codecov SymfonyInsight Mutation testing badge

Usage

Command

bin/console google-translate:detect "your text here to detect language code used"
bin/console google-translate:translate "da" "your text here to translate"

Service

<?php

use Lsv\GoogleTranslationBundle\Translate\TranslatorInterface;

final readonly class TranslateText
{
    public function __construct(
        private TranslatorInterface $translator,
    )
    {
    }

    public function translate(string $text): string
    {
        return $this->translator->translate($text, 'en', isHtml: true)->text;
    }
}

Installation

composer require lsv/google-translate-bundle

You need to get a Google API key from the Google Cloud Console, and change it in your environment file.

With flex

The bundle will be automatically enabled and the configuration will be added to your .env file.

Without flex

Add the bundle to your config/bundles.php file

return [
    // ...
    Lsv\GoogleTranslationBundle\GoogleTranslationBundle::class => ['all' => true],
];

Configuration

# config/packages/google_translation.yaml
lsv_google_translate:
  google_api_key: '%env(GOOGLE_API_KEY)%'
# .env
GOOGLE_API_KEY=your_api_key_here