addweb/gtranslate-bundle
Symfony 7 bundle to integrate the GTranslate.io widget without copy‑pasting scripts. Configure via gtranslate.yaml, supports dropdown/float/dwf variants, provides a gtranslate_widget() Twig function with optional per-call overrides for script and settings.
A Symfony 7.x bundle that integrates the GTranslate.io widget.
It provides a Twig function and service to render the GTranslate widget with fully configurable settings — so you don’t need to copy-paste raw <script> snippets.
config/packages/gtranslate.yaml).dwf.js).gtranslate_widget() to drop the widget anywhere in your templates.Require the bundle in your Symfony app:
composer require addweb/gtranslate-bundle:"*@dev"
Create config/packages/gtranslate.yaml in your Symfony app:
gtranslate:
script_src: 'https://cdn.gtranslate.net/widgets/latest/dwf.js'
auto_wrapper: true
settings:
default_language: 'en'
languages: ['en','fr','it','es']
wrapper_selector: '.gtranslate_wrapper'
switcher_horizontal_position: 'right'
switcher_vertical_position: 'top'
switcher_text_color: '#f7f7f7'
switcher_arrow_color: '#f2f2f2'
switcher_border_color: '#161616'
switcher_background_color: '#303030'
switcher_background_shadow_color: '#474747'
switcher_background_hover_color: '#3a3a3a'
dropdown_text_color: '#eaeaea'
dropdown_hover_color: '#748393'
dropdown_background_color: '#474747'
script_src → Which GTranslate script to load (dropdown.js, float.js, dwf.js).
settings → Directly mirrors window.gtranslateSettings.
auto_wrapper → If true, a wrapper is auto-generated based on wrapper_selector.
Add the widget in any template:
{# Default (uses bundle config) #}
{{ gtranslate_widget() }}
{# Override script + settings at runtime #}
{{ gtranslate_widget({
script_src: 'https://cdn.gtranslate.net/widgets/latest/float.js',
settings: {
default_language: 'en',
languages: ['en','hi'],
switcher_horizontal_position: 'left',
switcher_vertical_position: 'bottom'
},
auto_wrapper: false
}) }}
You can render it from a controller as well:
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use AddWeb\GtranslateBundle\Service\GtranslateWidgetRenderer;
final class GtranslateDemoController extends AbstractController
{
#[Route('/gt-demo', name: 'gt_demo')]
public function demo(GtranslateWidgetRenderer $renderer): Response
{
return new Response('<html><body>'.$renderer->render().'</body></html>');
}
}
Check the Twig function is registered:
bin/console debug:twig | grep gtranslate_widget
Load your app in a browser and you should see the widget, and text should translate when you pick a language.
Run the test suite in the bundle directory:
vendor/bin/phpunit
Tests cover:
This bundle is under the MIT license. For the whole copyright, see the LICENSE file distributed with this source code.
How can I help you explore Laravel packages today?