2017 © Pedro Peláez
 

symfony-bundle symfony-translation-bundle

Symfony bundle that allows .json files to be translated between multiple languages.

image

devture/symfony-translation-bundle

Symfony bundle that allows .json files to be translated between multiple languages.

  • Monday, January 29, 2018
  • by spantaleev
  • Repository
  • 1 Watchers
  • 0 Stars
  • 26 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 4 % Grown

The README.md

Description

Web UI for managing Symfony bundles' translation files inside the actual web application., (*1)

This is a port of the similarly named Silex bundle: devture/silex-translation-bundle, (*2)

Finds all source language files (example: messages.en.json, another-domain.en.json) in a given list of base directories and allows these files to be translated to all given languages., (*3)

A {translationDomain}.{targetLanguage}.json file is generated and saved next to {translationDomain}{sourceLanguage}.json for each locale, whenever the translations for it are saved., (*4)

A {translationDomain}{targetLanguage}.hash.json file is also saved in the same directory. It contains "hints" telling the translation system which source translation string a given translation is derived from. This is so that a translation can be considered outdated if the source translation string changes. At this moment, outdated translations are automatically marked as untranslated in the web UI (that is to say, they are not marked as "already translated, but outdated", but simply as "not translated")., (*5)

Installation

Install through composer (composer require --dev devture/symfony-translation-bundle)., (*6)

Add to config/bundles.php:, (*7)

Devture\Bundle\TranslationBundle\DevtureTranslationBundle::class => ['dev' => true],

Permissions

Since the translation system needs to save translation files in the project, we need to grant file-writing privileges to the web server user., (*8)

Example:, (*9)

$ find /srv/http/my-project/src -type d -name translations | xargs chown :http
$ find /srv/http/my-project/src -type d -name translations | xargs chmod g+w

Configuration

You most likely want this bundle active only for your development (dev) environment. Thus, you can drop the following routing config in config/packages/dev/devture_translation.yaml, (*10)

devture_translation:
    source_language_locale_key: en
    paths_to_translate:
        - "%kernel.project_dir%/src"
        - "%kernel.project_dir%/translations"
    locales:
        - {"key": "en", "name": "English"}
        - {"key": "ja", "name": "Japanese"}
    twig_layout_path: "base.html.twig"

locales needs to contain all languages that the translation system should be active for (including the source language)., (*11)

Multiple paths can be specified in paths_to_translate. Each is scanned for files matching the following pattern: */translations/<some translation domain>.<source_language_locale_key>.json., (*12)

twig_layout_path is the path to your layout file, which would contain the translation system. The only requirement is that it defines a content block. The translation system would render within it., (*13)

Example layout file:, (*14)

<!doctype html>
<html>
    <body>
        <h1>Website</h1>
        {% block content %}{% endblock %}
    </body>
</html>

Routing example

You most likely want this bundle active only for your development (dev) environment. Thus, you can drop the following routing config in config/routes/dev/DevtureTranslationBundle.yaml:, (*15)

DevtureTranslationBundleWebsite:
    prefix: /{_locale}/translation
    resource: "@DevtureTranslationBundle/Resources/config/routes/website.yaml"
    requirements:
        _locale: "en|ja"

The Web UI is available at the devture_translation.manage route., (*16)

Styling

This bundle relies on Bootstrap v4 for styling. Unless you install and include it (somewhere in your twig_layout_path template), things would look ugly., (*17)

Additionally, you can make the pages look prettier by including a flag icon for each language somewhere in your layout or CSS file., (*18)

<style>
    .devture-translation-flag {
        border: 1px solid #dbdbdb;
        width: 20px;
        height: 13px;
        display: inline-block;
        vertical-align: text-top;
    }
    .devture-translation-flag.en {
        background: url('/images/flag/en_US.png') no-repeat;
    }
    .devture-translation-flag..ja {
        background: url('/images/flag/ja_JP.png') no-repeat;
    }
</style>

The Versions

29/01 2018

dev-master

9999999-dev

Symfony bundle that allows .json files to be translated between multiple languages.

  Sources   Download

BSD-3-Clause

The Requires

 

by Slavi Pantaleev

bundle symfony translation internationalization

26/01 2018

1.0

1.0.0.0

Symfony bundle that allows .json files to be translated between multiple languages.

  Sources   Download

BSD-3-Clause

The Requires

 

by Slavi Pantaleev

bundle symfony translation internationalization