Skip to content

Commit

Permalink
First part of i18n (all but admin section), and french l10n.
Browse files Browse the repository at this point in the history
  • Loading branch information
kissifrot committed Oct 4, 2017
1 parent ff09cb0 commit 7dfcb76
Show file tree
Hide file tree
Showing 41 changed files with 385 additions and 145 deletions.
Expand Up @@ -29,5 +29,5 @@
<div class="form-group">
<input type="submit" id="_submit" name="_submit" class="btn-default btn" value="{{ 'security.login.submit'|trans }}" />
</div>
<p><a href="{{ path('fos_user_resetting_request') }}">Lost your password?</a></p>
<p><a href="{{ path('fos_user_resetting_request') }}">{{ 'security.login.lost_password.text'|trans({}, 'messages') }}</a></p>
</form>
13 changes: 13 additions & 0 deletions app/Resources/translations/messages.en.yml
@@ -0,0 +1,13 @@
global.welcome.title: 'Welcome'
global.default.title: 'Wishlist management'
global.navbar.text.logged: 'Logged in as %username%.&nbsp;<a href="%logoutUrl%">logout</a>'
global.navbar.text.guest: 'Unknown user, please <a href="%loginUrl%">login</a>'
global.navbar.admin_access: 'Admin access'
global.navbar.options: 'Options'
global.navbar.lists: 'Lists'
security.login.lost_password.text: 'Lost your password?'
home.welcome.title.logged: 'Welcome %username%,'
home.welcome.title.guest: 'Welcome,'
home.welcome.text.logged: 'Please use the menu on the top to navigate, or <a href="%logoutUrl%">logout</a>'
home.welcome.text.guest: 'Please use the menu on the top to navigate'
home.welcome.text_user_not_logged: 'Unknown user, please <a href="%loginUrl%">login</a>'
13 changes: 13 additions & 0 deletions app/Resources/translations/messages.fr.yml
@@ -0,0 +1,13 @@
global.welcome.title: 'Bienvenue'
global.default.title: 'Gestion de liste de souhaits'
global.navbar.text.logged: 'Connecté en tant que %username%.&nbsp;<a href="%logoutUrl%">se déconnecter</a>'
global.navbar.text.guest: 'Utilisateur inconnu, veuillez vous <a href="%loginUrl%">connecter</a>'
global.navbar.admin_access: 'Accès administrateur'
global.navbar.options: 'Options'
global.navbar.lists: 'Listes'
security.login.lost_password.text: 'Mot de passe perdu ?'
home.welcome.title.logged: 'Bienvenue %username%,'
home.welcome.title.guest: 'Bienvenue,'
home.welcome.text.logged: 'Utilisez le menu du haut pour naviguer, ou <a href="%logoutUrl%">déconnectez-vous</a>'
home.welcome.text.guest: 'Utilisez le menu du haut pour naviguer'
home.welcome.text_user_not_logged: 'Utilisateur inconnu, veuillez vous <a href="%loginUrl%">connecter</a>'
16 changes: 8 additions & 8 deletions app/Resources/views/base.html.twig
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bestwishes - {% block title %}Wishlist management{% endblock %}</title>
<title>{{ site_name }} - {% block title %}Wishlist management{% endblock %}</title>
<link href="{{ asset('bundles/app/css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ asset('bundles/app/css/main.css') }}" rel="stylesheet">
{% block stylesheets %}{% endblock %}
Expand All @@ -28,30 +28,30 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{{ path('homepage') }}">{% block site_name %}BestWishes{% endblock %}</a>
<a class="navbar-brand" href="{{ path('homepage') }}">{{ site_name }}</a>
</div>

<div class="collapse navbar-collapse" id="bw-navbar-collapse">
<ul class="nav navbar-nav">
{% block navbar %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Lists <span class="caret"></span></a>
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ 'global.navbar.lists'|trans }} <span class="caret"></span></a>
<ul class="dropdown-menu">
{{ render(controller('AppBundle:List:index')) }}
</ul>
</li>
<li><a href="#">Show PDF</a></li>
{% block navbar_extra %}{% endblock %}
{% if is_granted('IS_AUTHENTICATED_FULLY') or is_granted('IS_AUTHENTICATED_REMEMBERED') %}
<li><a href="{{ path('user_home') }}">Options</a></li>
<li><a href="{{ path('user_home') }}">{{ 'global.navbar.options'|trans }}</a></li>
{% endif %}
{% endblock %}
</ul>
<p class="navbar-text navbar-right">
{% if is_granted('IS_AUTHENTICATED_FULLY') or is_granted('IS_AUTHENTICATED_REMEMBERED') %}
Logged in as {{ app.user.username }}.&nbsp;<a href="{{ path('fos_user_security_logout') }}">Logout</a>
{% if is_granted('ROLE_ADMIN') %}&nbsp;<a href="{{ path('admin_lists') }}">Admin access</a>{% endif %}
{{ 'global.navbar.text.logged'|trans({ '%username%': app.user.username, '%logoutUrl%': path('fos_user_security_logout') })|raw }}
{% if is_granted('ROLE_ADMIN') %}&nbsp;<a href="{{ path('admin_lists') }}">{{ 'global.navbar.admin_access'|trans }}</a>{% endif %}
{% else %}
<span class="glyphicon glyphicon-user" aria-hidden="true"></span> Unknown user, please <a href="{{ path('fos_user_security_login') }}">login</a>
<span class="glyphicon glyphicon-user" aria-hidden="true"></span>&nbsp;{{ 'global.navbar.text.guest'|trans({ '%loginUrl%': path('fos_user_security_login') })|raw }}
{% endif %}
</p>
</div><!-- /.navbar-collapse -->
Expand Down
12 changes: 6 additions & 6 deletions app/Resources/views/default/home.html.twig
@@ -1,17 +1,17 @@
{% extends 'base.html.twig' %}

{% block title %}Welcome{% endblock %}
{% block title %}{{ 'global.welcome.title'|trans }}{% endblock %}

{% block content %}
<div class="container">
{% if is_granted('IS_AUTHENTICATED_FULLY') or is_granted('IS_AUTHENTICATED_REMEMBERED') %}

<h1>Welcome {{ app.user.username }},</h1>
<p>Please use the menu on the top to navigate, or <a href="{{ path('fos_user_security_logout') }}">logout</a></p>
<h1>{{ 'home.welcome.title.logged'|trans({ '%username%': app.user.username }) }}</h1>
<p>{{ 'home.welcome.text.logged'|trans({ '%logoutUrl%': path('fos_user_security_logout') })|raw }}</p>
{% else %}
<h1>Welcome</h1>
<p>Please use the menu on the top to navigate</p>
<span class="glyphicon glyphicon-user" aria-hidden="true"></span> Unknown user, please <a href="{{ path('fos_user_security_login') }}">login</a>
<h1>{{ 'home.welcome.title.guest'|trans }}</h1>
<p>{{ 'home.welcome.text.guest'|trans }}</p>
<span class="glyphicon glyphicon-user" aria-hidden="true"></span>&nbsp;{{ 'home.welcome.text_user_not_logged'|trans({ '%loginUrl%': path('fos_user_security_login') })|raw }}
{% endif %}

</div>
Expand Down
4 changes: 3 additions & 1 deletion app/config/config.yml
Expand Up @@ -13,7 +13,7 @@ parameters:

framework:
#esi: ~
translator: { fallbacks: ["%locale%"] }
translator: { fallbacks: ["%locale%", fr] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
Expand Down Expand Up @@ -41,6 +41,8 @@ twig:
strict_variables: "%kernel.debug%"
form_themes:
- 'bootstrap_3_layout.html.twig'
globals:
site_name: "%site_name%"

# Doctrine Configuration
doctrine:
Expand Down
2 changes: 2 additions & 0 deletions app/config/parameters.yml.dist
Expand Up @@ -23,3 +23,5 @@ parameters:

# A secret key that's used to generate certain security-related tokens
secret: PleaseChangeThisSecretToken
# Site name, leave defaults to show support ;)
site_name: BestWishes
6 changes: 3 additions & 3 deletions src/AppBundle/Controller/CategoryController.php
Expand Up @@ -64,7 +64,7 @@ public function createAction(Request $request, GiftList $list)
$em->persist($category);
$em->flush();

$this->addFlash('notice', sprintf('Category "%s" added',$category->getName()));
$this->addFlash('notice', $this->get('translator')->trans('category.message.updated', ['%categoryName%' => $category->getName()]));

return $this->redirectToRoute('list_show', ['id' => $list->getId()]);
}
Expand Down Expand Up @@ -95,7 +95,7 @@ public function editAction(Request $request, Category $category)
$em->persist($category);
$em->flush();

$this->addFlash('notice', sprintf('Category "%s" updated', $category->getName()));
$this->addFlash('notice', $this->get('translator')->trans('category.message.updated', ['%categoryName%' => $category->getName()]));

return $this->redirectToRoute('category_show', ['id' => $category->getId()]);
}
Expand Down Expand Up @@ -124,7 +124,7 @@ public function deleteAction(Request $request, Category $category)
$em->remove($category);
$em->flush();

$this->addFlash('notice', sprintf('Category "%s" deleted', $category->getName()));
$this->addFlash('notice', $this->get('translator')->trans('category.message.deleted', ['%categoryName%' => $category->getName()]));
}

return $this->redirectToRoute('list_show', ['id' => $category->getList()->getId()]);
Expand Down
10 changes: 5 additions & 5 deletions src/AppBundle/Controller/GiftController.php
Expand Up @@ -84,7 +84,7 @@ public function createAction(Request $request, Category $category)
$event = new GiftCreatedEvent($gift, $this->getUser());
$this->get('event_dispatcher')->dispatch(GiftCreatedEvent::NAME, $event);

$this->addFlash('notice', sprintf('Gift "%s" added', $gift->getName()));
$this->addFlash('notice', $this->get('translator')->trans('gift.message.created', ['%giftName%' => $gift->getName()]));

return $this->redirectToRoute('category_show', ['id' => $category->getId()]);
}
Expand Down Expand Up @@ -124,7 +124,7 @@ public function editAction(Request $request, Gift $gift)
$event = new GiftEditedEvent($originGift, $gift, $this->getUser());
$this->get('event_dispatcher')->dispatch(GiftEditedEvent::NAME, $event);

$this->addFlash('notice', sprintf('Gift "%s" updated', $gift->getName()));
$this->addFlash('notice', $this->get('translator')->trans('gift.message.updated', ['%giftName%' => $gift->getName()]));

return $this->redirectToRoute('gift_show', ['id' => $gift->getId()]);
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public function deleteAction(Request $request, Gift $gift)
$event = new GiftDeletedEvent($deletedGift, $this->getUser());
$this->get('event_dispatcher')->dispatch(GiftDeletedEvent::NAME, $event);

$this->addFlash('notice', sprintf('Gift "%s" deleted', $deletedGift->getName()));
$this->addFlash('notice', $this->get('translator')->trans('gift.message.deleted', ['%giftName%' => $deletedGift->getName()]));
}

return $this->redirectToRoute('category_show', ['id' => $gift->getCategory()->getId()]);
Expand Down Expand Up @@ -194,7 +194,7 @@ public function markReceivedAction(Request $request, Gift $gift)
$em->persist($gift);
$em->flush();

$this->addFlash('notice', sprintf('Gift "%s" marked as received', $gift->getName()));
$this->addFlash('notice', $this->get('translator')->trans('gift.message.marked_received', ['%giftName%' => $gift->getName()]));
}

return $this->redirectToRoute('category_show', ['id' => $gift->getCategory()->getId()]);
Expand Down Expand Up @@ -234,7 +234,7 @@ public function markBoughtAction(Request $request, Gift $gift)
$event = new GiftPurchasedEvent($gift, $this->getUser(), $purchaseComment);
$this->get('event_dispatcher')->dispatch(GiftPurchasedEvent::NAME, $event);

$this->addFlash('notice', sprintf('Gift "%s" marked as bought', $gift->getName()));
$this->addFlash('notice', $this->get('translator')->trans('gift.message.marked_bought', ['%giftName%' => $gift->getName()]));
}

return $this->redirectToRoute('gift_show', ['id' => $gift->getId()]);
Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/Controller/UserController.php
Expand Up @@ -25,7 +25,7 @@ public function indexAction()

/**
* @Route("/change-options", name="user_change_options")
* @Method({"GET", "POST"})
* @Method({"GET"})
*/
public function changeOptionsAction()
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace AppBundle\Subscriber;
namespace AppBundle\EventSubscriber;

use AppBundle\Event\GiftCreatedEvent;
use AppBundle\Event\GiftDeletedEvent;
Expand Down
50 changes: 50 additions & 0 deletions src/AppBundle/EventSubscriber/LocaleSubscriber.php
@@ -0,0 +1,50 @@
<?php

namespace AppBundle\EventSubscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class LocaleSubscriber implements EventSubscriberInterface
{
private $defaultLocale;

public function __construct($defaultLocale = 'en')
{
$this->defaultLocale = $defaultLocale;
}

public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
if (!$request->hasPreviousSession()) {
return;
}

if ($locale = $request->attributes->get('_locale')) {
$request->getSession()->set('_locale', $locale);
} else {
$prefLanguage = $request->getPreferredLanguage();
// Convert to ISO 3166-2 equivalent language when possible
switch ($prefLanguage) {
case 'fr':
case 'fr_FR':
$locale = 'fr';
break;
case 'en_US':
case 'en_GB':
default:
$locale = $this->defaultLocale;
}
$request->setLocale($request->getSession()->get('_locale', $locale));
}
}

public static function getSubscribedEvents()
{
return array(
KernelEvents::REQUEST => array(array('onKernelRequest', 15)),
);
}
}
@@ -1,6 +1,6 @@
<?php

namespace AppBundle\Subscriber;
namespace AppBundle\EventSubscriber;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
Expand Down
3 changes: 2 additions & 1 deletion src/AppBundle/Form/Type/CategoryType.php
Expand Up @@ -15,13 +15,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class)
->add('save', SubmitType::class);
->add('save', SubmitType::class, ['label_format' => 'form.save']);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Category::class,
'label_format' => 'form.category.%name%'
));
}
}
3 changes: 2 additions & 1 deletion src/AppBundle/Form/Type/GiftListType.php
Expand Up @@ -20,13 +20,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('name', TextType::class)
->add('owner', EntityType::class, ['class' => User::class, 'choice_label' => 'name'])
->add('birthDate', DateType::class, ['years' => range(date('Y') - 120, date('Y'))])
->add('save', SubmitType::class);
->add('save', SubmitType::class, ['label_format' => 'form.save']);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => GiftList::class,
'label_format' => 'form.gift_list.%name%'
));
}
}
3 changes: 2 additions & 1 deletion src/AppBundle/Form/Type/GiftType.php
Expand Up @@ -20,13 +20,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('imageUrl', UrlType::class, ['required' => false])
->add('moreDetailUrl', UrlType::class, ['required' => false])
->add('moreDetail', TextareaType::class, ['required' => false])
->add('save', SubmitType::class);
->add('save', SubmitType::class, ['label_format' => 'form.save']);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Gift::class,
'label_format' => 'form.gift.%name%'
));
}
}
2 changes: 1 addition & 1 deletion src/AppBundle/Form/Type/UserType.php
Expand Up @@ -24,7 +24,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('name', TextType::class)
->add('plainPassword', PasswordType::class, ['constraints' => new Length(['min' => 6]), 'required' => !$options['isEditing']])
->add('list', EntityType::class, ['class' => GiftList::class, 'choice_label' => 'name', 'required' => false])
->add('save', SubmitType::class);
->add('save', SubmitType::class, ['label_format' => 'form.save']);
}

public function configureOptions(OptionsResolver $resolver)
Expand Down
36 changes: 21 additions & 15 deletions src/AppBundle/Resources/config/services.yml
@@ -1,11 +1,5 @@
services:

bw.tblprefix_subscriber:
class: AppBundle\Subscriber\TablePrefixSubscriber
arguments: [ '%database_prefix%' ]
tags:
- { name: doctrine.event_subscriber }

bw.list_event_manager:
class: AppBundle\Manager\ListEventManager
arguments: ["@doctrine.orm.default_entity_manager"]
Expand All @@ -26,15 +20,6 @@ services:
class: AppBundle\Security\AclManager
arguments: [ "@security.acl.provider" ]

bw.gift_subscriber:
class: AppBundle\Subscriber\GiftSubscriber
arguments:
- "@fos_user.user_manager"
- "@bw.security_context"
- "@bw.mailer"
tags:
- { name: kernel.event_subscriber }

bw.mailer:
class: AppBundle\Mailer\Mailer
arguments:
Expand All @@ -49,3 +34,24 @@ services:
- "@fos_user.user_manager"
- "@event_dispatcher"
- "@request_stack"

bw.gift_subscriber:
class: AppBundle\EventSubscriber\GiftSubscriber
arguments:
- "@fos_user.user_manager"
- "@bw.security_context"
- "@bw.mailer"
tags:
- { name: kernel.event_subscriber }

bw.tblprefix_subscriber:
class: AppBundle\EventSubscriber\TablePrefixSubscriber
arguments: [ '%database_prefix%' ]
tags:
- { name: doctrine.event_subscriber }

bw.locale_subscriber:
class: AppBundle\EventSubscriber\LocaleSubscriber
arguments: [ '%kernel.default_locale%' ]
tags:
- { name: kernel.event_subscriber }

0 comments on commit 7dfcb76

Please sign in to comment.