GithubHelp home page GithubHelp logo

pinkeen / aotranslationbundle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adrianolek/aotranslationbundle

0.0 1.0 0.0 351 KB

Doctrine as symfony translation provider + a nice gui for editing translations.

PHP 88.37% CSS 1.67% JavaScript 9.96%

aotranslationbundle's Introduction

AOTranslationBundle Overview

This bundle provides doctrine as translations storage and a nice web gui accessible from the profiler for easy translation.

Build Status

Features

  • All translation messages are automatically saved in the database (no extraction necessary)
  • Translation panel available in the Symfony web debug toolbar
  • Only messages used in current action are loaded from the database
  • Translations management backend available via SonataAdminBundle

Installation

Require vendor libraries

Require ao/translation-bundle & stof/doctrine-extensions-bundle in composer.json:

"require": {
  "symfony/symfony": "2.1.*",
  "_comment": "other packages",
  "stof/doctrine-extensions-bundle": "1.1.*@dev",
  "ao/translation-bundle": "1.0.*@dev"
}

Then install or update composer bundles with:

php composer.phar install

or

php composer.phar update

Add bundles to your application kernel

In app/AppKernel.php add:

// app/AppKernel.php
public function registerBundles()
{
    return array(
        //...
        new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
        new AO\TranslationBundle\AOTranslationBundle()
        //...
    );
}

Configure translator

# app/config/config.yml
# enable translation component
framework:
    translator: ~

# use AOTranslationBundle as translator
parameters:
    translator.class: AO\TranslationBundle\Translation\Translator

# configure locales avaliable for translation 
ao_translation:
    locales:
        en: ~
        de:
          label: German
        fr: ~

Configure doctrine extensions bundle

Timestampable behavior has to be enabled.

# app/config/config.yml
stof_doctrine_extensions:
    orm:
        default:
            timestampable: true

Update your db schema

If you use migrations:

app/console doctrine:migrations:diff
app/console doctrine:migrations:migrate

Otherwise:

app/console doctrine:schema:update

Add routing information

# app/config/routing.yml
ao_translation:
    resource: "@AOTranslationBundle/Controller/"
    type:     annotation
    prefix:   / 

Usage

Use translation methods like described in Symfony Translations documentation.

Translations panel

You can access translations panel by clicking on Translations in the web debug toolbar.

Translations web debug toolbar

Now you can edit all your translation messages. Message parameters can be inserted directly into translation by clicking on the link in Parameters (2) column. After you are done click the Save Translations button (1).

As the translator needs to know which messages are used in each action, it stores this relation in a cache table. Therefore, when a message is not used anymore it will still be visible in the translations panel. To clear the cached messages use the Reset action cache (3) button, which will clear the cache for current action. Alternatively use the Reset cache (4) button, which will clear cache for all actions. The cache will be rebuilt with the next execution of an action.

Translations panel

Translations backend

In order to use translations backend you need to install SonataAdminBundle and SonataDoctrineORMAdminBundle. Please refer to their installation guide. After installation and configuration the backend will be available under /admin/ao/translation/message/list.

Additional features

Using separate database connection for storing translations

In case you need to share the translations database (eg. when multiple developers collaborate) you can configure separate entity manager for the bundle.

# app/config/config.yml
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                ...
            # configure translations database connection
            translations:
                ...
                
orm:
    ...
    default_entity_manager: default
    entity_managers:
        default:
            connection: default
            mappings:
                ...
        translations:
            connection: translations
            mappings:
                AOTranslationBundle: ~

ao_translation:
    entity_manager: translations

stof_doctrine_extensions:
    orm:
        ...
        # enable timestampable behavior for translations entity manager
        translations:
            timestampable: true

To create translations schema add use --em parameter like:

app/console doctrine:schema:create --em=translations

aotranslationbundle's People

Contributors

adrianolek avatar pinkeen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.