Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@peterjmit
Created January 25, 2013 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterjmit/4636445 to your computer and use it in GitHub Desktop.
Save peterjmit/4636445 to your computer and use it in GitHub Desktop.
Symfony 2 Multi lingual
<?php
// namespaces etc...
class ArticleType
{
// ...
public function buildForm(FormBuilderInterface $builder, array $options)
{
// ...
// old definitions
// ...
$builder->add('translations', 'a2lix_translations');
}
default_locale: "en"
doctrine:
orm:
mappings:
gedmo_translatable:
type: annotation
alias: GedmoTranslatable
prefix: Gedmo\Translatable\Entity
# make sure vendor library location is correct
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
is_bundle: false
stof_doctrine_extensions:
default_locale: "en"
translation_fallback: true
orm:
default:
translatable: true
a2lix_translation_form:
locales: ["en", "fr", "it"] # [optional] Array of the translation locales (The default locale have to be excluded). Can also be specified in the form builder.
default_required: false
<?php
// namespaces etc...
class DefaultController
{
indexAction(Request $request)
{
// returns en at http://mywebsite.com/en/my-route
// returns it at http://mywebsite.com/it/my-route
$request->getLocale();
}
}
MyBundle\Entity\Article:
type: entity
gedmo:
translation:
locale: locale
entity: MyBundle\Entity\ArticleTranslation
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
title:
type: string
gedmo:
- translatable
content:
type: text
gedmo:
- translatable
# This is the personal translation type
oneToMany:
translations:
targetEntity: MyBundle\Entity\ArticleTranslation
mappedBy: object
cascade: [ persist, remove ]
# Before
my_route:
pattern: /my-route/{my_pattern}
defaults:
_controller: MyBundle:Default:index
# After
my_route:
pattern: /{_locale}/my-route/{my_pattern}
defaults:
_controller: MyBundle:Default:index
_locale: en
requirements:
# You can restrict the lanugages you support here
_locale: ^en|fr|it$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment