Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n #10

Merged
merged 53 commits into from
Dec 5, 2014
Merged

i18n #10

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2e0863b
init feature i18n for victoire
FloSeas Nov 18, 2014
4f0fb53
adding form_row(local) and translation
FloSeas Nov 19, 2014
0ca9488
tmplate working and link beetwin view and translation
FloSeas Nov 19, 2014
1e327c4
work neraly finished need debug
FloSeas Nov 19, 2014
3d55dd0
corecting bug for view cache generator and doing some tasks of insight
FloSeas Nov 20, 2014
c4c5162
insight corrections and some bug correction
FloSeas Nov 20, 2014
7b9cb79
fix bug on clone
FloSeas Nov 20, 2014
69e8990
locale switcher nearly finished
FloSeas Nov 20, 2014
dc6d1f1
locale switcher working need to change logic
FloSeas Nov 21, 2014
2b4d107
the logic to clone a view
FloSeas Nov 21, 2014
9f67e7e
fix non cloning widgets
FloSeas Nov 21, 2014
40d8dc9
adding the structure of the generic url resolver for switching locale
FloSeas Nov 21, 2014
a11f836
url resolver nearly finished
FloSeas Nov 21, 2014
efc99e0
many to many relation
FloSeas Nov 24, 2014
478e8ca
starting dynamic entity
FloSeas Nov 24, 2014
add20e7
i18n generation on cache ok
FloSeas Nov 24, 2014
6d39bae
anotation ok in twig template
FloSeas Nov 24, 2014
d9a885f
work in progress need subscriber to change metadata
FloSeas Nov 24, 2014
ac21888
add annotation reader
FloSeas Nov 25, 2014
a79fcbf
try solutions to track metadata
FloSeas Nov 25, 2014
7e8cfc5
driver chain fixed
FloSeas Nov 25, 2014
8e15f85
remove unnecessary Code
FloSeas Nov 25, 2014
4556c50
adding translator
FloSeas Nov 26, 2014
5a6046e
correction view with new architecture, correcting skeleton
FloSeas Nov 26, 2014
c27859b
locale switcher ok
FloSeas Nov 27, 2014
de963f5
adding a command to update to i18n
FloSeas Nov 27, 2014
df0646d
fix typo
FloSeas Nov 27, 2014
bc14539
update i18n command and page clone
FloSeas Nov 28, 2014
c2bb8ec
update cloner, need to strip the widgetmaps level
FloSeas Nov 28, 2014
b9c7a9a
fail
FloSeas Nov 28, 2014
770b9e1
widgetCloned ok
FloSeas Dec 1, 2014
03f176d
adding translation for template
FloSeas Dec 1, 2014
f762009
finished template translation
FloSeas Dec 1, 2014
2527d16
automatic template cloning
FloSeas Dec 1, 2014
ccb6502
translator ok
FloSeas Dec 1, 2014
0489404
adding recursive call to cloneView to clone all view contained in a page
FloSeas Dec 2, 2014
d522b28
trying to finish recursive
FloSeas Dec 2, 2014
35758c7
recursive mode on template ok still a bug on first root layout creation
FloSeas Dec 2, 2014
00d0019
translator ok and new translation
FloSeas Dec 3, 2014
8c9444e
add translation
FloSeas Dec 3, 2014
bfcd5ba
parameters in config
FloSeas Dec 3, 2014
36be16b
k
FloSeas Dec 3, 2014
7e5a3f5
disable locales already translated
FloSeas Dec 3, 2014
64ee72f
phpdoc
FloSeas Dec 3, 2014
d2bb85f
starting readme
FloSeas Dec 3, 2014
c6aa028
fix few bugs
FloSeas Dec 4, 2014
82907ff
viclink
FloSeas Dec 4, 2014
14b42ac
fix a bug an changing locale on cloned page
FloSeas Dec 4, 2014
4acf851
fix bug
FloSeas Dec 4, 2014
409f04e
deleting url in form
FloSeas Dec 4, 2014
fbde3e8
fix bug on locale page
FloSeas Dec 4, 2014
e4effef
fix bug on slots
FloSeas Dec 4, 2014
3e22761
Fix case typo
Dec 5, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Bundle/BlogBundle/Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,20 @@ public function newBlogArticleAction(Blog $blog)
* @param Request $request
* @param Page $article
*
* @return template
* @Route("/{id}/settings", name="victoire_blog_article_settings")
* @Template()
* @Route("/{id}/{newTranslation}/settings", name="victoire_blog_article_settings", defaults={"newTranslation"=false})
*
* @ParamConverter("article", class="VictoireBlogBundle:Article")
* @return template
*/
public function settingsAction(Request $request, BasePage $article)
public function settingsAction(Request $request, BasePage $article, $newTranslation=false)
{
$response = parent::settingsAction($request, $article);
$response = parent::settingsAction($request, $article, $newTranslation);

$pattern = $article->getTemplate();

$page = $this->container->get('victoire_page.page_helper')->findPageByParameters(array(
'viewId' => $pattern->getId(),
'locale' => $request->getSession()->get('victoire_locale'),
'entityId' => $article->getId()
));
$response['url'] = $this->generateUrl('victoire_core_page_show', array('url' => $page->getUrl()));
Expand Down
6 changes: 3 additions & 3 deletions Bundle/BlogBundle/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public function newAction($isHomepage = false)
* @param Page $blog
*
* @return template
* @Route("/{id}/settings", name="victoire_blog_settings")
* @Route("/{id}/{newTranslation}/settings", name="victoire_blog_settings", defaults={"newTranslation"=false})
* @Template()
* @ParamConverter("blog", class="VictoirePageBundle:BasePage")
*/
public function settingsAction(Request $request, BasePage $blog)
public function settingsAction(Request $request, BasePage $blog, $newTranslation = false)
{
return new JsonResponse(parent::settingsAction($request, $blog));
return new JsonResponse(parent::settingsAction($request, $blog, $newTranslation));
}

/**
Expand Down
6 changes: 5 additions & 1 deletion Bundle/BlogBundle/Form/ArticleType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ class ArticleType extends ViewType
{
private $em;

public function __construct(EntityManager $em)
/**
* Constructor
*/
public function __construct(EntityManager $em, $applicationLocales)
{
parent::__construct($applicationLocales);
$this->em = $em;
}

Expand Down
2 changes: 1 addition & 1 deletion Bundle/BlogBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
#ARTICLE
victoire_blog.article.form.type:
class: Victoire\Bundle\BlogBundle\Form\ArticleType
arguments: ["@doctrine.orm.entity_manager"]
arguments: ["@doctrine.orm.entity_manager", "%victoire_i18n.application_locales%"]
tags:
- { name: form.type, alias: victoire_article_type }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
*/
class BusinessEntityPagePatternType extends ViewType
{

/**
* Constructor
*/
public function __construct($applicationLocales)
{
parent::__construct($application_locales);
}
/**
* @param FormBuilderInterface $builder
* @param array $options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
victoire_business_entity_page.business_entity_page_pattern.form.type:
class: Victoire\Bundle\BusinessEntityPageBundle\Form\BusinessEntityPagePatternType
arguments:
- "%victoire_core.layouts%"
- "%victoire_i18n.application_locales%"
tags:
- { name: form.type, alias: victoire_business_entity_page_type }

Expand Down
60 changes: 55 additions & 5 deletions Bundle/CoreBundle/Entity/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Victoire\Bundle\PageBundle\Entity\Slot;
use Victoire\Bundle\PageBundle\Entity\WidgetMap;
use Victoire\Bundle\WidgetBundle\Entity\Widget;
use Victoire\Bundle\I18NBundle\Entity\I18n;

/**
* Victoire View
Expand Down Expand Up @@ -78,7 +79,7 @@ abstract class View
*
* @Assert\NotNull()
* Could be Template or BusinessEntityPagePattern
* @ORM\ManyToOne(targetEntity="\Victoire\Bundle\TemplateBundle\Entity\Template", inversedBy="inheritors")
* @ORM\ManyToOne(targetEntity="\Victoire\Bundle\TemplateBundle\Entity\Template", inversedBy="inheritors", cascade={"persist"})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vérifie que c'est bien utile svp

* @ORM\JoinColumn(name="template_id", referencedColumnName="id", onDelete="CASCADE")
*
*/
Expand Down Expand Up @@ -161,15 +162,45 @@ abstract class View
//This is used to speed up the routing system and to identify virtual pages (BusinessEntityPage)
protected $reference;

/**
* @ORM\Column(name="locale", type="string")
*/
protected $locale;

/**
* @var string
*
* @ORM\OneToOne(targetEntity="\Victoire\Bundle\I18NBundle\Entity\I18n")
*/
protected $i18n;

/**
* contruct
**/
public function __construct()
public function __construct($locale = "fr")
{
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
$this->widgets = new ArrayCollection();
$this->widgetMap = array();
$this->locale = $locale;
$this->initI18n();
}

public function initI18N()
{
$this->i18n = new I18n();
$this->i18n->setTranslation($this->locale, $this);
}
public function getI18n()
{
return $this->i18n;
}

public function setI18n(I18n $i18n)
{
$this->i18n = $i18n;
return $this;
}

/**
Expand Down Expand Up @@ -201,6 +232,25 @@ public function setId($id)
$this->id = $id;
}

/**
* Get locale
*
* @return string
*/
public function getLocale()
{
return $this->locale;
}

/**
* Set locale
* @param $locale
*/
public function setLocale($locale)
{
$this->locale = $locale;
}

/**
* Get name
*
Expand Down Expand Up @@ -296,17 +346,17 @@ public function getInheritors()
/**
* Set parent
*
* @param parent $parent
* @param \Victoire\Bundle\PageBundle\Entity\BasePage $parent
*/
public function setParent($parent)
public function setParent(\Victoire\Bundle\PageBundle\Entity\BasePage $parent = null)
{
$this->parent = $parent;
}

/**
* Get parent
*
* @return parent
* @return \Victoire\Bundle\PageBundle\Entity\BasePage parent
*/
public function getParent()
{
Expand Down
30 changes: 30 additions & 0 deletions Bundle/CoreBundle/Form/ViewType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Victoire\Bundle\TemplateBundle\Entity\Template;
use Victoire\Bundle\CoreBundle\Entity\View;

/**
* Page Type
*/
abstract class ViewType extends AbstractType
{

protected $applicationLocales;

public function __construct($applicationLocales)
{
$this->applicationLocales = $applicationLocales;
}

/**
* define form fields
* @param FormBuilderInterface $builder
Expand Down Expand Up @@ -52,6 +60,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'query_builder' => $getAllTemplateWithoutMe,
));
}
if (!$form->has('locale')) {

$form->add('locale', 'choice', array(
'expanded' => false,
'multiple' => false,
'choices' => $this->getAvailableLocales($view),
'label' => 'form.view.type.local.label'));
}
});

$builder
Expand All @@ -60,4 +76,18 @@ public function buildForm(FormBuilderInterface $builder, array $options)
));
}

protected function getAvailableLocales(View $view)
{
$choices = array();
$i18n = $view->getI18n();

foreach($this->applicationLocales as $localeKey => $localeVal) {
if($i18n->getTranslation($localeVal) === null ) {
$choices[$localeVal] = $localeVal;
}
}

return $choices;
}

}
5 changes: 5 additions & 0 deletions Bundle/CoreBundle/Helper/ViewCacheHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public function buildItemNode($viewReference, $itemNode)
if (array_key_exists('entityNamespace', $viewReference)) {
$itemNode->addAttribute('entityNamespace', $viewReference['entityNamespace']);
}
if (array_key_exists('locale', $viewReference)) {
$itemNode->addAttribute('locale', $viewReference['locale']);
}

}
/**
* Write given views references in a xml file
Expand Down Expand Up @@ -118,6 +122,7 @@ public function getReferenceByParameters($parameters)

if ($xmlReference = $this->readCache()->xpath("//viewReference[" . implode(' and ', $arguments) . "]")) {
$viewReference['id'] = $xmlReference[0]->getAttributeAsPhp('id');
$viewReference['locale'] = $xmlReference[0]->getAttributeAsPhp('locale');
$viewReference['entityId'] = $xmlReference[0]->getAttributeAsPhp('entityId');
$viewReference['entityNamespace'] = $xmlReference[0]->getAttributeAsPhp('entityNamespace');
$viewReference['url'] = $xmlReference[0]->getAttributeAsPhp('url');
Expand Down
Loading