-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Move the TranslationLoader to the Translation component. #23666
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
Changes from all commits
c11a431
10d00e5
08e8e84
fd658ee
6b9775d
0d52fa2
d853843
8210985
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,56 +11,11 @@ | |
|
||
namespace Symfony\Bundle\FrameworkBundle\Translation; | ||
|
||
use Symfony\Component\Finder\Finder; | ||
use Symfony\Component\Translation\MessageCatalogue; | ||
use Symfony\Component\Translation\Loader\LoaderInterface; | ||
@trigger_error(sprintf('The class "%s" has been deprecated. Use "%s" instead. ', self::class, \Symfony\Component\Translation\Loader\TranslationLoader::class), E_USER_DEPRECATED); | ||
|
||
/** | ||
* TranslationLoader loads translation messages from translation files. | ||
* | ||
* @author Michel Salib <michelsalib@hotmail.com> | ||
* @deprecated Class moved to Symfony\Component\Translation\Loader\TranslationLoader | ||
*/ | ||
class TranslationLoader | ||
class TranslationLoader extends \Symfony\Component\Translation\Loader\TranslationLoader | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should add a deprecation notice when this class is used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And internal usages of this class should be changed to use the new class instead (which could lead to some composer dep changes in frameworkbundle probably) |
||
{ | ||
/** | ||
* Loaders used for import. | ||
* | ||
* @var array | ||
*/ | ||
private $loaders = array(); | ||
|
||
/** | ||
* Adds a loader to the translation extractor. | ||
* | ||
* @param string $format The format of the loader | ||
* @param LoaderInterface $loader | ||
*/ | ||
public function addLoader($format, LoaderInterface $loader) | ||
{ | ||
$this->loaders[$format] = $loader; | ||
} | ||
|
||
/** | ||
* Loads translation messages from a directory to the catalogue. | ||
* | ||
* @param string $directory the directory to look into | ||
* @param MessageCatalogue $catalogue the catalogue | ||
*/ | ||
public function loadMessages($directory, MessageCatalogue $catalogue) | ||
{ | ||
if (!is_dir($directory)) { | ||
return; | ||
} | ||
|
||
foreach ($this->loaders as $format => $loader) { | ||
// load any existing translation files | ||
$finder = new Finder(); | ||
$extension = $catalogue->getLocale().'.'.$format; | ||
$files = $finder->files()->name('*.'.$extension)->in($directory); | ||
foreach ($files as $file) { | ||
$domain = substr($file->getFilename(), 0, -1 * strlen($extension) - 1); | ||
$catalogue->addCatalogue($loader->load($file->getPathname(), $catalogue->getLocale(), $domain)); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Translation\Loader; | ||
|
||
use Symfony\Component\Finder\Finder; | ||
use Symfony\Component\Translation\MessageCatalogue; | ||
|
||
/** | ||
* TranslationLoader loads translation messages from translation files. | ||
* | ||
* @author Michel Salib <michelsalib@hotmail.com> | ||
*/ | ||
class TranslationLoader | ||
{ | ||
/** | ||
* Loaders used for import. | ||
* | ||
* @var array | ||
*/ | ||
private $loaders = array(); | ||
|
||
/** | ||
* Adds a loader to the translation extractor. | ||
* | ||
* @param string $format The format of the loader | ||
* @param LoaderInterface $loader | ||
*/ | ||
public function addLoader($format, LoaderInterface $loader) | ||
{ | ||
$this->loaders[$format] = $loader; | ||
} | ||
|
||
/** | ||
* Loads translation messages from a directory to the catalogue. | ||
* | ||
* @param string $directory the directory to look into | ||
* @param MessageCatalogue $catalogue the catalogue | ||
*/ | ||
public function loadMessages($directory, MessageCatalogue $catalogue) | ||
{ | ||
if (!is_dir($directory)) { | ||
return; | ||
} | ||
|
||
foreach ($this->loaders as $format => $loader) { | ||
// load any existing translation files | ||
$finder = new Finder(); | ||
$extension = $catalogue->getLocale().'.'.$format; | ||
$files = $finder->files()->name('*.'.$extension)->in($directory); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would drop the finder requirement for an iterator. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already pointed by @javiereguiluz but @Nyholm said it would need the Finder dep anyway for some other changes he wants to make. So, probably good as is. |
||
foreach ($files as $file) { | ||
$domain = substr($file->getFilename(), 0, -1 * strlen($extension) - 1); | ||
$catalogue->addCatalogue($loader->load($file->getPathname(), $catalogue->getLocale(), $domain)); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to also add a note in the CHANGELOG for 4.0.