Skip to content

Commit

Permalink
Rebase to upstream 12-4-24 (#2)
Browse files Browse the repository at this point in the history
* Added gitattributes - exclude docs, tests from archive

* Added template name and line number to exception thrown by DefaultApplyingNodeVisitor

* Update FormExtractor.php

Trying to get property 'key' of non-object

* Fix --intl-icu option

`--intl-icu` option was never interpreted because of a misuse of InputInterface::hasParameterOption

* fix: require symfony/expression-language

* Fallback to 'messages' domain when domain is null in trans|transchoice method

* Support named argument for extracting domain

* Bump nikic/php-parser to ^4.9

* Add attributes for routes

* Allow to use translate controller without sensio/framework-extra-bundle

* resolved deprecation notice with Symfony 5.4

PR resolves this deprecation:

Method "Symfony\Component\Config\Definition\ConfigurationInterface::getConfigTreeBuilder()" might add "TreeBuilder" as a native return type declaration in the future. Do the same in implementation "JMS\TranslationBundle\DependencyInjection\Configuration" now to avoid errors or add an explicit @return annotation to suppress this message.

* github actions, testing and coding standard, drop symfony 3.4 support

* symfony 6 support

* Handle properly promoted constructor properties default values

* Fix schmittjoh#575: Remove deprecation notices with string interpolation

Resolve pull request schmittjoh#576

* add void return signatures

* chore: fix coding style

* fix: fix wrong return type-hint depending on which symfony/translation version is installed

* chore: bump symfony version for tests

* chore(deps): upgrade nikic/php-parser@^5

* fix: prevent type error on choices array with optional keys

* chore: fix phpcs + nikic/php-parser@4 compatibility

* Fix tests

* tests + ecs

---------

Co-authored-by: iamvar <iamvar@gmail.com>
Co-authored-by: Asmir Mustafic <goetas@gmail.com>
Co-authored-by: Adam Wójs <adam@wojs.pl>
Co-authored-by: Vladimir Pak <TheRatW@gmail.com>
Co-authored-by: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com>
Co-authored-by: Quentin Dreyer <quentin.dreyer@gmail.com>
Co-authored-by: François-Xavier de Guillebon <deguif@gmail.com>
Co-authored-by: Tomas Ludvik <ludviktomas@gmail.com>
Co-authored-by: GRandFather <HenkerX64@users.noreply.github.com>
Co-authored-by: Derek Stephen McLean <delboy1978uk@gmail.com>
Co-authored-by: qkdreyer <quentin.dreyer@rgsystem.com>
  • Loading branch information
12 people authored Apr 15, 2024
1 parent 334336f commit 25e1a2e
Show file tree
Hide file tree
Showing 58 changed files with 472 additions and 321 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/CHANGELOG.md export-ignore
/CONTRIBUTING.md export-ignore
/README.md export-ignore
/Tests export-ignore
/phpunit.xml.dist export-ignore
61 changes: 61 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# yamllint disable rule:line-length
# yamllint disable rule:braces

name: CI

on:
pull_request:
push:
branches:
- "master"

jobs:
phpunit:
name: "PHPUnit"
runs-on: "ubuntu-20.04"

strategy:
fail-fast: false
matrix:
symfony-version:
- '^4.4'
- '^5.4'
- '^6.4'
php-version:
- "7.4"
- "8.0"
- "8.1"
dependencies:
- "lowest"
- "highest"
exclude:
- symfony-version: '^6.4'
php-version: '7.4'
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
with:
fetch-depth: 2

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "pcov"
ini-values: "zend.assertions=1"

- name: Configure symfony version
uses: php-actions/composer@v6
with:
command: config
args: extra.symfony.require ${{ matrix.symfony-version }}

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "${{ matrix.dependencies }}"
composer-options: "${{ matrix.composer-options }}"

- name: Run tests
run: |
SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/simple-phpunit ${PHPUNIT_FLAGS}
35 changes: 35 additions & 0 deletions .github/workflows/coding-standards.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "Coding Standards"

on:
pull_request:
push:
branches:
- "master"

jobs:
coding-standards:
name: "Coding Standards"
runs-on: "ubuntu-20.04"

strategy:
matrix:
php-version:
- "7.4"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: "cs2pr"
extensions: pdo_sqlite

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Run PHP_CodeSniffer"
run: "vendor/bin/phpcs"
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,41 @@ phpunit.xml
composer.lock
vendor/
.phpunit.result.cache
/.idea
.phpcs-cache
phpcs.xml


/bin/
/config/
/public/
/src/
/templates
/tests
/translations
/var/
/.env*
/.phpunit.result.cache

.idea/
/symfony.lock

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###

###> squizlabs/php_codesniffer ###
/.phpcs-cache
/phpcs.xml
###< squizlabs/php_codesniffer ###

###> symfony/phpunit-bridge ###
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###
57 changes: 0 additions & 57 deletions .travis.yml

This file was deleted.

9 changes: 0 additions & 9 deletions .travis/install_cs.sh

This file was deleted.

9 changes: 0 additions & 9 deletions .travis/install_test.sh

This file was deleted.

5 changes: 0 additions & 5 deletions .travis/script_cs.sh

This file was deleted.

6 changes: 0 additions & 6 deletions .travis/script_test.sh

This file was deleted.

6 changes: 0 additions & 6 deletions .travis/success_test.sh

This file was deleted.

9 changes: 3 additions & 6 deletions Command/ExtractTranslationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,10 @@ public function __construct(ConfigFactory $configFactory, Updater $updater, arra
parent::__construct();
}

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName('translation:extract')
->setName('jms:translation:extract')
->setDescription('Extracts translation messages from your code.')
->addArgument('locales', InputArgument::IS_ARRAY, 'The locales for which to extract messages.')
->addOption('enable-extractor', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'The alias of an extractor which should be enabled.')
Expand Down Expand Up @@ -180,7 +177,7 @@ private function updateWithInput(InputInterface $input, ConfigBuilder $builder)
$builder->setOutputFormat($outputFormat);
}

if ($input->hasParameterOption('intl-icu')) {
if ($input->hasParameterOption('--intl-icu')) {
$builder->setUseIcuMessageFormat(true);
}

Expand Down
7 changes: 2 additions & 5 deletions Command/ResourcesListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,10 @@ public function __construct(string $projectDir, array $bundles, ?string $rootDir
parent::__construct();
}

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName('translation:list-resources')
->setName('jms:translation:list-resources')
->setDescription('List translation resources available.')
->addOption('files', null, InputOption::VALUE_OPTIONAL, 'Display only files');
}
Expand Down
2 changes: 2 additions & 0 deletions Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*
* @Route("/api")
*/
#[Route('/api')]
class ApiController
{
/**
Expand Down Expand Up @@ -65,6 +66,7 @@ public function __construct(ConfigFactory $configFactory, Updater $updater)
* defaults = {"id" = null},
* options = {"i18n" = false})
*/
#[Route('/configs/{config}/domains/{domain}/locales/{locale}/messages', name: 'jms_translation_update_message', methods: [Request::METHOD_PUT], defaults: ['id' => null], options: ['i18n' => false])]
public function updateMessageAction(Request $request, $config, $domain, $locale)
{
$id = $request->query->get('id');
Expand Down
21 changes: 18 additions & 3 deletions Controller/TranslateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
use JMS\TranslationBundle\Util\FileUtils;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Twig\Environment;

/**
* Translate Controller.
Expand All @@ -45,15 +47,21 @@ class TranslateController
*/
private $loader;

/**
* @var Environment|null
*/
private $twig;

/**
* @var string
*/
private $sourceLanguage;

public function __construct(ConfigFactory $configFactory, LoaderManager $loader)
public function __construct(ConfigFactory $configFactory, LoaderManager $loader, ?Environment $twig = null)
{
$this->configFactory = $configFactory;
$this->loader = $loader;
$this->twig = $twig;
}

/**
Expand All @@ -67,11 +75,12 @@ public function setSourceLanguage($lang)
/**
* @param Request $request
*
* @return array
* @return Response|array
*
* @Route("/", name="jms_translation_index", options = {"i18n" = false})
* @Template("@JMSTranslation/Translate/index.html.twig")
*/
#[Route('/', name: 'jms_translation_index', options: ['i18n' => false])]
public function indexAction(Request $request)
{
$configs = $this->configFactory->getNames();
Expand Down Expand Up @@ -136,7 +145,7 @@ public function indexAction(Request $request)
$existingMessages[$id] = $message;
}

return [
$variables = [
'selectedConfig' => $config,
'configs' => $configs,
'selectedDomain' => $domain,
Expand All @@ -151,5 +160,11 @@ public function indexAction(Request $request)
'file' => (string) $files[$domain][$locale][1],
'sourceLanguage' => $this->sourceLanguage,
];

if (null !== $this->twig) {
return new Response($this->twig->render('@JMSTranslation/Translate/index.html.twig', $variables));
}

return $variables;
}
}
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/IntegrationPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

class IntegrationPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('translation.loader.xliff')) {
return;
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/MountDumpersPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class MountDumpersPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('jms_translation.file_writer')) {
return;
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/MountExtractorsPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class MountExtractorsPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('jms_translation.extractor_manager')) {
return;
Expand Down
Loading

0 comments on commit 25e1a2e

Please sign in to comment.