Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Gtranslate Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

GtranslateBundle

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.


🚀 Features

  • Easy integration of the GTranslate.io widget.
  • Configurable via Symfony config (config/packages/gtranslate.yaml).
  • Supports all widget variants: dropdown, floating, dark floating (dwf.js).
  • Twig function gtranslate_widget() to drop the widget anywhere in your templates.
  • Optional overrides per call — change languages, script, or wrapper at runtime.
  • Unit & integration tests included.

📦 Installation

Require the bundle in your Symfony app:

composer require addweb/gtranslate-bundle:"*@dev"

⚙️ Configuration

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.

🖥️ Usage

Twig

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
}) }}

Controller

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>');
    }
}

✅ Verify

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.

🧪 Tests

Run the test suite in the bundle directory:

vendor/bin/phpunit

Tests cover:

  • The renderer’s HTML output.
  • Per-call overrides.
  • DI wiring with a test kernel.

📜 License

This bundle is under the MIT license. For the whole copyright, see the LICENSE file distributed with this source code.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament