Skip to content

Commit 9021aa8

Browse files
author
Jérôme Poskin
committed
Fix translation warning when no route prefix is defined or when the translation is a simple slash
1 parent c9d7563 commit 9021aa8

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SnowcapAdminBundle
1+
SnowcapI18nBundle
22
==================
33

44
The SnowcapI18nBundle provides a set of tools and helpers for multi-locale websites.
@@ -8,9 +8,6 @@ Features include:
88
- A @I18nRoute annotation to handle localized routes based on locale prefixes
99
- A few twig functions and filters
1010

11-
**Caution:** This bundle is developed in sync with [symfony's repository](https://github.com/symfony/symfony).
12-
For Symfony 2.2.x, you need to use the 2.2.x branch of the bundle.
13-
1411
[![Build Status](https://secure.travis-ci.org/snowcap/SnowcapI18nBundle.png?branch=master)](http://travis-ci.org/snowcap/SnowcapI18nBundle)
1512

1613
Documentation

Routing/I18nAnnotatedRouteControllerLoader.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Sensio\Bundle\FrameworkExtraBundle\Routing\AnnotatedRouteControllerLoader;
88
use Snowcap\I18nBundle\Registry;
99
use Symfony\Component\Routing\RouteCollection;
10-
use Symfony\Component\Translation\TranslatorInterface;
1110

1211
class I18nAnnotatedRouteControllerLoader extends AnnotatedRouteControllerLoader {
1312
/**
@@ -67,19 +66,19 @@ protected function addRoute(
6766

6867
foreach($this->registry->getRegisteredLocales() as $locale) {
6968
$i18nAnnot = new Route($annot->data);
70-
$i18nGlobals = $globals;
7169

7270
if($i18n) {
7371
$i18nAnnot->setName($this->helper->alterName($i18nAnnot->getName(), $locale));
7472
$i18nAnnot->setPath($this->helper->alterPath($i18nAnnot->getPath(), $locale));
7573
$i18nAnnot->setDefaults($this->helper->alterdefaults($i18nAnnot->getDefaults(), $locale));
7674

77-
$i18nGlobals['path'] = $this->helper->alterPath($i18nGlobals['path'], $locale);
78-
79-
$i18nGlobals['path'] = rtrim('/' . $locale . '/' . ltrim($i18nGlobals['path'], '/'), '/');
75+
if (isset($globals['path']) && !empty($globals['path'])) {
76+
$globals['path'] = $this->helper->alterPath($globals['path'], $locale);
77+
$globals['path'] = rtrim('/' . $locale . '/' . ltrim($globals['path'], '/'), '/');
78+
}
8079
}
8180

82-
parent::addRoute($collection, $i18nAnnot, $i18nGlobals, $class, $method);
81+
parent::addRoute($collection, $i18nAnnot, $globals, $class, $method);
8382
}
8483
}
8584
}

Routing/I18nLoaderHelper.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class I18nLoaderHelper {
1717

1818
/**
1919
* @param TranslatorInterface $translator
20+
* @param string $translationDomain
2021
*/
2122
public function __construct(TranslatorInterface $translator, $translationDomain)
2223
{
@@ -35,15 +36,15 @@ public function alterName($name, $locale)
3536
}
3637

3738
/**
38-
* @param $path
39-
* @param $locale
39+
* @param string $path
40+
* @param string $locale
4041
* @return string
4142
*/
4243
public function alterPath($path, $locale)
4344
{
44-
$translatedPath = trim($this->translator->trans($path, array(), $this->translationDomain, $locale), '/');
45+
$translatedPath = $this->translator->trans($path, array(), $this->translationDomain, $locale);
4546

46-
return rtrim('/' . $translatedPath, '/');
47+
return '/' . trim( $translatedPath, '/');
4748
}
4849

4950
/**

0 commit comments

Comments
 (0)