Developed with love by KnpLabs Hire us for your project!
24

translate-bundle

by weglot

Translate your Symfony website easily.

<!-- logo -->

Symfony Translate Bundle

<!-- tags -->
Latest Stable Version
Maintainability
License

Overview

Seamless integration of Weglot into your Symfony project.

Requirements

  • PHP version 5.5 and later
  • Weglot API Key, starting at free level

Installation

You can install the library via Composer. Run the following command:

composer require weglot/translate-bundle

To use the library, use Composer's autoload:

require_once __DIR__. '/vendor/autoload.php';

Getting Started

Bundle Register

Symfony 4

Add Weglot bundle in the config/bundles.php:
php
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
// ... Other bundles ...
Weglot\TranslateBundle\WeglotTranslateBundle::class => ['all' => true],
];

Symfony 3 & 2

Add Weglot bundle to app/AppKernel.php file:
php
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
// ... Other bundles ...
new Weglot\TranslateBundle\WeglotTranslateBundle(),
);

Configuration

For Symfony 4, create configuration file under config/packages/weglot_translate.yml and add following content.
For Symfony 3 & 2, add following content to your app/config/config.yml.
yaml
weglot_translate:
api_key: 'YOUR_WEGLOT_API_KEY'
original_language : 'en'
cache: false
destination_languages:
- 'fr'
- 'de'

This is an example of configuration, enter your own API key, your original language and destination languages that you want.
- api_key : is your personal API key. You can get an API Key by signing up on Weglot.
- original_language : original language is the language of your website before translation.
- destination_languages : are the languages that you want your website to be translated into.
- cache : if you wanna use cache or not. It's not a required field and set as false by default. Look at Caching part for more details.

There is also a non-required parameters exclude_blocks where you can list all blocks you don't want to be translated. For example, if I've a block with class "site-name", you've to do as following:
yaml
exclude_blocks:
- .site-name

Caching

We implemented usage of cache.app service for both Symfony 4 and Symfony 3 (symfony/cache bundle was released with Symfony 3, so no compatibility for Symfony 2).

If you wanna use cache, just add cache: true to this bundle configuration. It will use whatever cache.app is using.

Optional - Hreflang links

Hreflang links are a way to describe your website and to tell webcrawlers (such as search engines) if this page is available in other languages.
More details on Google post about hreflang: https://support.google.com/webmasters/answer/189077

You can add them through the Twig function: weglot_hreflang_render

Just put the function at the end of your <head> tag:
```twig


...

    {{ weglot_hreflang_render() }}
</head>

### Optional - Language button

You can add a language button if you're using Twig with function: `weglot_translate_render`

Two layouts exists:
```twig
<!-- first layout -->
{{ weglot_translate_render(1) }}

<!-- second layout -->
{{ weglot_translate_render(2) }}

Examples

You'll find a short README with details about example on each repository

About

translate-bundle is guided and supported by the Weglot Developer Team.

translate-bundle is maintained and funded by Weglot SAS.
The names and logos for translate-bundle are trademarks of Weglot SAS.

License

The MIT License (MIT)

weglot_translate:
api_key: ~ # Required
original_language: ~ # Required
destination_languages: [] # Required
exclude_blocks: []
cache: false
  • Merge branch 'hotfix/0.6.1' into develop
    By Korbeil, 3 months ago
  • forgot important twig template
    By Korbeil, 3 months ago
  • Merge branch 'release/0.6' into develop
    By Korbeil, 3 months ago
  • Merge branch 'release/0.6'
    By Korbeil, 3 months ago
  • updating changelog
    By Korbeil, 3 months ago
  • Merge branch 'feature/twig-href-lang-extension' into develop
    By Korbeil, 3 months ago
  • cleaning WeglotHrefLangExtension construct
    By Korbeil, 3 months ago
  • removing un-used variable
    By Korbeil, 3 months ago
  • updating readme
    By Korbeil, 3 months ago
  • updating readme
    By Korbeil, 3 months ago
  • adding to changelog
    By Korbeil, 3 months ago
  • adding Twig extension for hreflangs
    By Korbeil, 3 months ago
  • cleaning useless code
    By Korbeil, 3 months ago
  • Merge branch 'feature/caching' into develop
    By Korbeil, 3 months ago
  • updating changelog
    By Korbeil, 3 months ago
  • adding Caching part for our README
    By Korbeil, 3 months ago
  • adding utility function & imports
    By Korbeil, 3 months ago
  • fixing wording & cc issue
    By Korbeil, 3 months ago
  • adding optional cache parameter, default false
    By Korbeil, 3 months ago
  • switching Kernel version check, better to check compatible version
    By Korbeil, 3 months ago
  • moving client service out of yml file to use cache set only for SF3 & SF4
    By Korbeil, 3 months ago
  • adding caching for SF4
    By Korbeil, 4 months ago
  • adding SF2 example
    By Korbeil, 4 months ago
  • updating README & CHANGELOG to add SF3 example
    By Korbeil, 4 months ago
  • updating changelog
    By Korbeil, 4 months ago
  • removing Enum for templates & updating README
    By Korbeil, 4 months ago
  • adding backlink on readme
    By Korbeil, 4 months ago
  • updating config file path for SF3 & SF2 in readme
    By Korbeil, 4 months ago
  • Merge branch 'release/0.5' into develop
    By Korbeil, 4 months ago
  • Merge branch 'release/0.5'
    By Korbeil, 4 months ago