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

requeired field translated #285

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0d5d911
requeired field translated
Sep 6, 2017
0d9f2cc
lt-1
arlauskas Sep 14, 2017
118a43a
lt-1
arlauskas Sep 14, 2017
890623e
lt-1
arlauskas Sep 14, 2017
e87c3c1
Merge pull request #1 from ubiedigital/lt-1
Sep 14, 2017
911be31
Translation required
arlauskas Sep 14, 2017
6d809f6
Merge pull request #2 from ubiedigital/lt-1
Sep 14, 2017
b1cda6b
Translation required
arlauskas Sep 14, 2017
d28fe52
Merge pull request #3 from ubiedigital/lt-1
Sep 14, 2017
a2d8258
Constraints not blank
arlauskas Sep 14, 2017
dc00b1e
Merge pull request #4 from ubiedigital/lt-1
Sep 14, 2017
51b3bf6
Remove unnecessary stuff (#256)
imanalopher Sep 6, 2017
aab658f
Latvian translations (#244)
Sep 6, 2017
b2a5bd8
Fix travis conf (#274)
sdieunidou Sep 7, 2017
0299217
fix definition of storage service for sf 3.3 (#275)
sdieunidou Sep 7, 2017
6598962
fix tests (#276)
sdieunidou Sep 7, 2017
e6fca8b
remove dependency symfony/symfony
sdieunidou Sep 7, 2017
5cfb433
check if function apc_delete_file() exist before call it (#277)
sdieunidou Sep 7, 2017
ae35743
Replace save by saved glyphicon, looking less 'download' than 'confir…
HellFiveDay Sep 7, 2017
71231cd
fix DI for dev_tool definition
gilles-g Sep 8, 2017
8973bde
add csrf protection (#278)
sdieunidou Sep 13, 2017
91148f1
persist grid params in url + add link on overview to filter by a domain
Sep 13, 2017
f762de9
add default domain when adding a new translation
Sep 13, 2017
0422d33
update documentation
Sep 13, 2017
f3600f7
URL decode updated translation messages
Oct 5, 2017
e836b50
Fix double-encoding of translations in the web UI (#289)
jorissteyn Nov 29, 2017
70bec31
Fix error undefined index: charset (#298)
hason Dec 21, 2017
f8ce229
Replace Propel to Propel2. (#302)
eugenekurasov Jan 19, 2018
f69f600
Minor typo fixes (#296)
gustavodpont Feb 19, 2018
b1b9710
Symfony 4 support (#305)
Bukashk0zzz Feb 19, 2018
cd96410
#306. set public of 'translate' alias for compatibility with other c…
eugenekurasov Mar 12, 2018
22818c8
Fix duplicate service id
May 21, 2018
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
51 changes: 34 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
language: php

sudo: false

php:
- 5.5
- 5.6
- 7.0
- hhvm
- 7.1
- 7.2

matrix:
fast_finish: true
allow_failures:
- php: hhvm
exclude:
- php: 5.6
env: SYMFONY_VERSION=4.0.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
- php: 7.0
env: SYMFONY_VERSION=4.0.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
- php: 7.2
env: SYMFONY_VERSION=2.8.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
- php: 7.2
env: SYMFONY_VERSION=3.0.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
- php: 7.2
env: SYMFONY_VERSION=3.1.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
- php: 7.2
env: SYMFONY_VERSION=3.2.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
- php: 7.2
env: SYMFONY_VERSION=3.3.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
- php: 7.2
env: SYMFONY_VERSION=3.4.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha

services:
- mongodb

env:
- SYMFONY_VERSION=2.8.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test
- SYMFONY_VERSION=3.2.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test
- SYMFONY_VERSION=3.3.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test

- SYMFONY_VERSION=2.8.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
- SYMFONY_VERSION=3.0.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
- SYMFONY_VERSION=3.1.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
- SYMFONY_VERSION=3.2.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
- SYMFONY_VERSION=3.3.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
- SYMFONY_VERSION=3.4.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
- SYMFONY_VERSION=4.0.* DB=pdo_mysql DB_USER=root DB_NAME=lexik_test DEPENDENCIES=alpha
cache:
directories:
- $HOME/.composer/cache

before_install:
- phpenv config-add travis-php.ini
- echo "memory_limit = 2G" > /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/z.ini
- sh -c "if [ '$DB' = 'pdo_mysql' ]; then mysql -e 'create database IF NOT EXISTS $DB_NAME' -u$DB_USER; fi"
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --no-update
- composer require symfony/validator:${SYMFONY_VERSION} --no-update
- composer require symfony/finder:${SYMFONY_VERSION} --no-update
- composer require symfony/doctrine-bridge:${SYMFONY_VERSION} --no-update
- if [ "$DEPENDENCIES" = "beta" ]; then composer config minimum-stability beta; fi;
- if [ "$DEPENDENCIES" = "alpha" ]; then composer config minimum-stability alpha; fi;
- if [ -x .travis/before_install.sh ]; then .travis/before_install.sh; fi;

install: composer install --prefer-dist --no-interaction
install:
- if [ -x .travis/install.sh ]; then .travis/install.sh; fi;

script: phpunit
script:
- php vendor/bin/phpunit -v
23 changes: 23 additions & 0 deletions .travis/before_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env sh
set -ev

sh -c "if [ '$DB' = 'pdo_mysql' ]; then mysql -e 'create database IF NOT EXISTS $DB_NAME' -u$DB_USER; fi"

phpenv config-rm xdebug.ini

if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ]; then
PHP_INI_DIR="$HOME/.phpenv/versions/$(phpenv version-name)/etc/conf.d/"
TRAVIS_INI_FILE="$PHP_INI_DIR/travis.ini"
echo "memory_limit=3072M" >> "$TRAVIS_INI_FILE"

if [ "$TRAVIS_PHP_VERSION" '<' '7.0' ]; then
echo "extension=mongo.so" >> "$TRAVIS_INI_FILE"
else
echo "extension=mongodb.so" >> "$TRAVIS_INI_FILE"

# Backwards compatibility with old mongo extension
composer require "alcaeus/mongo-php-adapter" --no-update
fi
fi

composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update
6 changes: 6 additions & 0 deletions .travis/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# To be removed when these issues are resolved:
# https://github.com/composer/composer/issues/5355
# https://github.com/composer/composer/issues/5030
composer update --prefer-dist --no-interaction --prefer-stable --quiet --ignore-platform-reqs

composer update --prefer-dist --no-interaction --prefer-stable
21 changes: 19 additions & 2 deletions Command/ImportTranslationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Translation\TranslatorInterface;

/**
* Imports translation files content in the database.
Expand All @@ -19,6 +21,21 @@
*/
class ImportTranslationsCommand extends ContainerAwareCommand
{
/**
* @var TranslatorInterface
*/
private $translator;

/**
* @param TranslatorInterface $translator
*/
public function __construct(TranslatorInterface $translator)
{
parent::__construct();

$this->translator = $translator;
}

/**
* @var \Symfony\Component\Console\Input\InputInterface
*/
Expand Down Expand Up @@ -71,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($bundleName) {
$bundle = $this->getApplication()->getKernel()->getBundle($bundleName);

if (null !== $bundle->getParent()) {
if (Kernel::VERSION_ID < 40000 && null !== $bundle->getParent()) {
// due to symfony's bundle inheritance if a bundle has a parent it is fetched first.
// so we tell getBundle to NOT fetch the first if a parent is present
$bundles = $this->getApplication()->getKernel()->getBundle($bundle->getParent(), false);
Expand Down Expand Up @@ -114,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

if ($this->input->getOption('cache-clear')) {
$this->output->writeln('<info>Removing translations cache files ...</info>');
$this->getContainer()->get('translator')->removeLocalesCacheFiles($locales);
$this->translator->removeLocalesCacheFiles($locales);
}
}

Expand Down
9 changes: 9 additions & 0 deletions Controller/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Lexik\Bundle\TranslationBundle\Controller;

use Lexik\Bundle\TranslationBundle\Util\Csrf\CsrfCheckerTrait;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -11,6 +12,8 @@
*/
class RestController extends Controller
{
use CsrfCheckerTrait;

/**
* @param Request $request
*
Expand Down Expand Up @@ -50,6 +53,8 @@ public function updateAction(Request $request, $id)
throw $this->createNotFoundException(sprintf('Invalid request method %s, PUT only.', $request->getMethod()));
}

$this->checkCsrf();

$transUnit = $this->get('lexik_translation.data_grid.request_handler')->updateFromRequest($id, $request);

return $this->get('lexik_translation.data_grid.formatter')->createSingleResponse($transUnit);
Expand All @@ -64,6 +69,8 @@ public function updateAction(Request $request, $id)
*/
public function deleteAction($id)
{
$this->checkCsrf();

$transUnit = $this->get('lexik_translation.translation_storage')->getTransUnitById($id);

if (!$transUnit) {
Expand All @@ -85,6 +92,8 @@ public function deleteAction($id)
*/
public function deleteTranslationAction($id, $locale)
{
$this->checkCsrf();

$transUnit = $this->get('lexik_translation.translation_storage')->getTransUnitById($id);

if (!$transUnit) {
Expand Down
8 changes: 7 additions & 1 deletion Controller/TranslationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Lexik\Bundle\TranslationBundle\Controller;

use Lexik\Bundle\TranslationBundle\Form\Type\TransUnitType;
use Lexik\Bundle\TranslationBundle\Storage\StorageInterface;
use Lexik\Bundle\TranslationBundle\Util\Csrf\CsrfCheckerTrait;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -12,6 +14,8 @@
*/
class TranslationController extends Controller
{
use CsrfCheckerTrait;

/**
* Display an overview of the translation status per domain.
*
Expand Down Expand Up @@ -67,6 +71,8 @@ public function invalidateCacheAction(Request $request)
$message = $this->get('translator')->trans('translations.cache_removed', array(), 'LexikTranslationBundle');

if ($request->isXmlHttpRequest()) {
$this->checkCsrf();

return new JsonResponse(array('message' => $message));
}

Expand All @@ -84,7 +90,7 @@ public function newAction(Request $request)
{
$handler = $this->get('lexik_translation.form.handler.trans_unit');

$form = $this->createForm('Lexik\Bundle\TranslationBundle\Form\Type\TransUnitType', $handler->createFormData(), $handler->getFormOptions());
$form = $this->createForm(TransUnitType::class, $handler->createFormData(), $handler->getFormOptions());

if ($handler->process($form, $request)) {
$message = $this->get('translator')->trans('translations.successfully_added', array(), 'LexikTranslationBundle');
Expand Down
21 changes: 17 additions & 4 deletions DependencyInjection/LexikTranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ public function buildTranslatorDefinition(ContainerBuilder $container)
$translator = new Definition();
$translator->setClass('%lexik_translation.translator.class%');

if (Kernel::VERSION_ID >= 30300) {
if (Kernel::VERSION_ID >= 40000) {
$arguments = [
new Reference('service_container'), // Will be replaced by service locator
new Reference('translator.formatter.default'),
new Parameter('kernel.default_locale'),
[], // translation loaders
new Parameter('lexik_translation.translator.options')
];
$translator->setPublic(true);
} elseif (Kernel::VERSION_ID >= 30300) {
$arguments = [
new Reference('service_container'), // Will be replaced by service locator
new Reference('translator.selector'),
Expand Down Expand Up @@ -171,7 +180,7 @@ protected function buildTranslationStorageDefinition(ContainerBuilder $container
);

$storageDefinition = new Definition();
$storageDefinition->setClass(new Parameter(sprintf('lexik_translation.%s.translation_storage.class', $storage)));
$storageDefinition->setClass($container->getParameter(sprintf('lexik_translation.%s.translation_storage.class', $storage)));
$storageDefinition->setArguments($args);

$container->setDefinition('lexik_translation.translation_storage', $storageDefinition);
Expand Down Expand Up @@ -206,7 +215,7 @@ protected function buildDevServicesDefinition(ContainerBuilder $container)
->addMethodCall('setProfiler', array(new Reference('profiler')));

$tokenFinderDefinition = new Definition();
$tokenFinderDefinition->setClass(new Parameter('lexik_translation.token_finder.class'));
$tokenFinderDefinition->setClass($container->getParameter('lexik_translation.token_finder.class'));
$tokenFinderDefinition->setArguments(array(
new Reference('profiler'),
new Parameter('lexik_translation.token_finder.limit'),
Expand All @@ -224,7 +233,11 @@ protected function buildDevServicesDefinition(ContainerBuilder $container)
protected function registerTranslatorConfiguration(array $config, ContainerBuilder $container)
{
// use the Lexik translator as default translator service
$container->setAlias('translator', 'lexik_translation.translator');
$alias = $container->setAlias('translator', 'lexik_translation.translator');

if (Kernel::VERSION_ID >= 30400) {
$alias->setPublic(true);
}

$translator = $container->findDefinition('lexik_translation.translator');
$translator->addMethodCall('setFallbackLocales', array($config['fallback_locale']));
Expand Down
14 changes: 11 additions & 3 deletions Form/Type/TransUnitType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;

/**
* TransUnit form type.
Expand All @@ -23,12 +24,18 @@ public function buildForm(FormBuilderInterface $builder, array $options)
));
$builder->add('domain', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
'label' => 'translations.domain',
'choices' => array_combine($options['domains'], $options['domains']),
'choices' => array_merge(
array_combine($options['default_domain'], $options['default_domain']),
array_combine($options['domains'], $options['domains'])
),
));
$builder->add('translations', 'Symfony\Component\Form\Extension\Core\Type\CollectionType', array(
'entry_type' => 'Lexik\Bundle\TranslationBundle\Form\Type\TranslationType',
'label' => 'translations.page_title',
'required' => false,
'required' => true,
'constraints' => array(
new NotBlank(),
),
'entry_options' => array(
'data_class' => $options['translation_class'],
),
Expand All @@ -48,7 +55,8 @@ public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => null,
'domains' => array('messages'),
'default_domain' => ['messages'],
'domains' => [],
'translation_class' => null,
'translation_domain' => 'LexikTranslationBundle',
));
Expand Down
6 changes: 5 additions & 1 deletion Form/Type/TranslationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;

/**
* Translation form type.
Expand All @@ -22,7 +23,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('locale', 'Symfony\Component\Form\Extension\Core\Type\HiddenType');
$builder->add('content', 'Symfony\Component\Form\Extension\Core\Type\TextareaType', array(
'required' => false,
'required' => true,
'constraints' => array(
new NotBlank(),
),
));
}

Expand Down
5 changes: 1 addition & 4 deletions Manager/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ public function getFor($name, $path = null)
$hash = $this->generateHash($name, $this->getFileRelativePath($path));
$file = $this->storage->getFileByHash($hash);

if (!($file instanceof FileInterface)) {
$file = $this->create($name, $path);
}
return $file instanceof FileInterface? $file : $this->create($name, $path);

return $file;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions Model/TransUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ abstract class TransUnit

/**
* @var \Doctrine\Common\Collections\Collection
*
* @Assert\NotBlank()
*/
protected $translations;

Expand Down Expand Up @@ -192,6 +194,22 @@ public function filterNotBlankTranslations()
});
}

/**
* Return false if at least one translation without content.
*
* @return bool
*/
public function validForBlankTranslations()
{
foreach ($this->getTranslations() as $translation) {
if (empty($translation->getContent())) {
return false;
}
}

return true;
}

/**
* Get createdAt
*
Expand Down
2 changes: 1 addition & 1 deletion Propel/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Lexik\Bundle\TranslationBundle\Propel;

use Lexik\Bundle\TranslationBundle\Propel\om\BaseFile;
use Lexik\Bundle\TranslationBundle\Propel\Base\File as BaseFile;
use Lexik\Bundle\TranslationBundle\Manager\FileInterface;

class File extends BaseFile implements FileInterface
Expand Down
Loading