Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weglot/translate-bundle
Translate your Symfony website easily.
https://github.com/weglot/translate-bundle
i18n php symfony symfony-bundle symfony2 symfony3 symfony4 weglot weglot-integration
Last synced: about 2 months ago
JSON representation
Translate your Symfony website easily.
- Host: GitHub
- URL: https://github.com/weglot/translate-bundle
- Owner: weglot
- License: mit
- Archived: true
- Created: 2018-04-16T14:40:06.000Z (over 6 years ago)
- Default Branch: develop
- Last Pushed: 2019-10-20T17:00:36.000Z (about 5 years ago)
- Last Synced: 2024-09-26T04:01:49.104Z (about 2 months ago)
- Topics: i18n, php, symfony, symfony-bundle, symfony2, symfony3, symfony4, weglot, weglot-integration
- Language: PHP
- Homepage:
- Size: 166 KB
- Stars: 10
- Watchers: 8
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Symfony Translate Bundle
[![WeglotSlack](https://weglot-community.now.sh/badge.svg)](https://weglot-community.now.sh/)
[![Latest Stable Version](https://poser.pugx.org/weglot/translate-bundle/v/stable)](https://packagist.org/packages/weglot/translate-bundle)
[![Maintainability](https://api.codeclimate.com/v1/badges/b1785d1e9225869f3da0/maintainability)](https://codeclimate.com/github/weglot/translate-bundle/maintainability)
[![License](https://poser.pugx.org/weglot/translate-bundle/license)](https://packagist.org/packages/weglot/translate-bundle)## Overview
Seamless integration of Weglot into your Symfony project.## Requirements
- PHP version 5.5 and later
- Weglot API Key, starting at [free level](https://dashboard.weglot.com/register?origin=8)## Installation
You can install the library via [Composer](https://getcomposer.org/). Run the following command:```bash
composer require weglot/translate-bundle
```When you require the bundle with `symfony/flex` (available for `symfony/symfony:^4.0`) it should ask you if you wanna execute a recipe, tell yes.
Like that it will make bundle registration in `config/bundles.php` & default config creation in `config/packages/weglot_translate.yaml`.To use the library, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
```php
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(),
);
```### Quick configuration
For Symfony 4, create configuration file under `config/packages/weglot_translate.yaml` and add following content.
For Symfony 3 & 2, add following content to your `app/config/config.yaml`.```yaml
weglot_translate:
api_key: '%env(WG_API_KEY)%'
original_language: 'en'
cache: true
destination_languages:
- 'fr'
- 'de'
```This is the default configuration file, if you want more default, check next part.
## Configuration
As already said, depending on Symfony version, we've different configuration file paths:
- Symfony 4: `config/packages/weglot_translate.yaml`
- Symfony 3 & 2: `app/config/config.yaml`There is a full configuration file:
```yaml
weglot_translate:
api_key: '%env(WG_API_KEY)%'
original_language: 'en'
cache: false
destination_languages:
- 'fr'
- 'de'
exclude_blocks:
- '.material-icons'
```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](https://dashboard.weglot.com/register?origin=8).
- `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](#caching) for more details.There is also a non-required parameters:
- `exclude_blocks`: You can list here all blocks you don't want to be translated. In this example, we won't translate all DOM tags with "material-icons" class.## Twig extensions
### 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/189077You can add them through the Twig function: `weglot_hreflang_render`
Just put the function at the end of your `` tag:
```twig
...{{ weglot_hreflang_render() }}
```### Language button
You can add a language button if you're using Twig with function: `weglot_translate_render`
Two layouts exists:
```twig{{ weglot_translate_render(1) }}
{{ weglot_translate_render(2) }}
```### Language code
Simple filter to convert ISO 639-1 code to full language name. It can takes one boolean parameter that allow you to choose having english name or original language name.
Here is some examples:
```twig{{ 'bg' | language }}
{{ 'bg' | language(false) }}
```## Caching
We implemented usage of cache pool service for both Symfony 4 and Symfony 3 (`symfony/cache` bundle was released with Symfony 3, so there is no compatibility for Symfony 2).
If you wanna use cache, just add `cache: true` to this bundle configuration. It will use a file-based cache through Symfony `cache.system` service.
To clear the cache, you just have to use the usual pool clear command:
```
$ php bin/console cache:pool:clear weglot_translate.cache
```## Examples
You'll find a short README with details about example on each repository
- Symfony 4: https://github.com/weglot/translate-bundle-example-sf4
- Symfony 3: https://github.com/weglot/translate-bundle-example-sf3
- Symfony 2: https://github.com/weglot/translate-bundle-example-sf2## 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)](LICENSE.txt)