Created
January 25, 2013 17:49
-
-
Save peterjmit/4636445 to your computer and use it in GitHub Desktop.
Symfony 2 Multi lingual
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// namespaces etc... | |
class ArticleType | |
{ | |
// ... | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
// ... | |
// old definitions | |
// ... | |
$builder->add('translations', 'a2lix_translations'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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