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

Drop SonataIntlBundle #5835

Merged
merged 2 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
"symfony/twig-bundle": "^4.3",
"symfony/validator": "^4.3",
"twig/extensions": "^1.5",
"twig/twig": "^2.10"
"twig/extra-bundle": "^3.0",
"twig/intl-extra": "^3.0",
"twig/twig": "^2.12"
},
"conflict": {
"doctrine/doctrine-bundle": ">=3",
Expand All @@ -66,7 +68,6 @@
"require-dev": {
"jms/translation-bundle": "^1.4",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"sonata-project/intl-bundle": "^2.4",
"symfony/browser-kit": "^4.3",
"symfony/css-selector": "^4.3",
"symfony/filesystem": "^4.3",
Expand All @@ -76,9 +77,7 @@
},
"suggest": {
"jms/translation-bundle": "Extract message keys from Admins",
"kunicmarko/sonata-auto-configure-bundle": "Auto configures Admin classes",
"sensio/generator-bundle": "Add sonata:admin:generate command",
"sonata-project/intl-bundle": "Add localized date and number into the list"
"kunicmarko/sonata-auto-configure-bundle": "Auto configures Admin classes"
},
"config": {
"sort-packages": true
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The demo website can be found at http://demo.sonata-project.org.
reference/console
reference/troubleshooting
reference/breadcrumbs
reference/internationalization

.. toctree::
:caption: Advanced Options
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,6 @@ Full Configuration Options
global_search:
show_empty_boxes: show
case_sensitive: true

# show localized information
use_intl_templates: false
18 changes: 18 additions & 0 deletions docs/reference/internationalization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Internationalization (I18N)
===========================

The admin comes with the ``use_intl_templates`` option that will load a set of templates that will
display localized information.


Configuration
-------------

.. configuration-block::

.. code-block:: yaml

# config/packages/sonata_admin.yaml

sonata_admin:
use_intl_templates: true
37 changes: 18 additions & 19 deletions src/DependencyInjection/AbstractSonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,28 @@ protected function fixTemplatesConfiguration(
],
];

// let's add some magic, only overwrite template if the SonataIntlBundle is enabled
$bundles = $container->getParameter('kernel.bundles');
if (isset($bundles['SonataIntlBundle'])) {
$useIntlTemplates = $container->getParameter('sonata.admin.configuration.use_intl_templates');
if ($useIntlTemplates) {
$defaultConfig['templates']['types']['list'] = array_merge($defaultConfig['templates']['types']['list'], [
'date' => '@SonataIntl/CRUD/list_date.html.twig',
'datetime' => '@SonataIntl/CRUD/list_datetime.html.twig',
'smallint' => '@SonataIntl/CRUD/list_decimal.html.twig',
'bigint' => '@SonataIntl/CRUD/list_decimal.html.twig',
'integer' => '@SonataIntl/CRUD/list_decimal.html.twig',
'decimal' => '@SonataIntl/CRUD/list_decimal.html.twig',
'currency' => '@SonataIntl/CRUD/list_currency.html.twig',
'percent' => '@SonataIntl/CRUD/list_percent.html.twig',
'date' => '@SonataAdmin/CRUD/Intl/list_date.html.twig',
'datetime' => '@SonataAdmin/CRUD/Intl/list_datetime.html.twig',
'smallint' => '@SonataAdmin/CRUD/Intl/list_decimal.html.twig',
'bigint' => '@SonataAdmin/CRUD/Intl/list_decimal.html.twig',
'integer' => '@SonataAdmin/CRUD/Intl/list_decimal.html.twig',
'decimal' => '@SonataAdmin/CRUD/Intl/list_decimal.html.twig',
'currency' => '@SonataAdmin/CRUD/Intl/list_currency.html.twig',
'percent' => '@SonataAdmin/CRUD/Intl/list_percent.html.twig',
]);

$defaultConfig['templates']['types']['show'] = array_merge($defaultConfig['templates']['types']['show'], [
'date' => '@SonataIntl/CRUD/show_date.html.twig',
'datetime' => '@SonataIntl/CRUD/show_datetime.html.twig',
'smallint' => '@SonataIntl/CRUD/show_decimal.html.twig',
'bigint' => '@SonataIntl/CRUD/show_decimal.html.twig',
'integer' => '@SonataIntl/CRUD/show_decimal.html.twig',
'decimal' => '@SonataIntl/CRUD/show_decimal.html.twig',
'currency' => '@SonataIntl/CRUD/show_currency.html.twig',
'percent' => '@SonataIntl/CRUD/show_percent.html.twig',
'date' => '@SonataAdmin/CRUD/Intl/show_date.html.twig',
'datetime' => '@SonataAdmin/CRUD/Intl/show_datetime.html.twig',
'smallint' => '@SonataAdmin/CRUD/Intl/show_decimal.html.twig',
'bigint' => '@SonataAdmin/CRUD/Intl/show_decimal.html.twig',
'integer' => '@SonataAdmin/CRUD/Intl/show_decimal.html.twig',
'decimal' => '@SonataAdmin/CRUD/Intl/show_decimal.html.twig',
'currency' => '@SonataAdmin/CRUD/Intl/show_currency.html.twig',
'percent' => '@SonataAdmin/CRUD/Intl/show_percent.html.twig',
]);
}

Expand Down
5 changes: 5 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,11 @@ public function getConfigTreeBuilder()
->info('Translate group label')
->end()

->booleanNode('use_intl_templates')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a call to info()

->defaultFalse()
->info('Whether localized information should be shown, it will replace some default templates')
->end()

->end()
->end();

Expand Down
19 changes: 10 additions & 9 deletions src/DependencyInjection/SonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ public function load(array $configs, ContainerBuilder $container)
]);
}

if (isset($bundles['SonataIntlBundle'])) {
// integrate the SonataUserBundle if the bundle exists
array_unshift($configs, [
'templates' => [
'history_revision_timestamp' => '@SonataIntl/CRUD/history_revision_timestamp.html.twig',
],
]);
}

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('twig.xml');
$loader->load('core.xml');
Expand Down Expand Up @@ -95,6 +86,16 @@ public function load(array $configs, ContainerBuilder $container)
$container->removeDefinition('sonata.admin.lock.extension');
}

$useIntlTemplates = $config['use_intl_templates'] || isset($bundles['SonataIntlBundle']);

$container->setParameter('sonata.admin.configuration.use_intl_templates', $useIntlTemplates);

if ($useIntlTemplates) {
if ('@SonataAdmin/CRUD/history_revision_timestamp.html.twig' === $config['templates']['history_revision_timestamp']) {
$config['templates']['history_revision_timestamp'] = '@SonataAdmin/CRUD/Intl/history_revision_timestamp.html.twig';
}
}

$container->setParameter('sonata.admin.configuration.global_search.empty_boxes', $config['global_search']['empty_boxes']);
$container->setParameter('sonata.admin.configuration.global_search.case_sensitive', $config['global_search']['case_sensitive']);
$container->setParameter('sonata.admin.configuration.templates', $config['templates']);
Expand Down
22 changes: 22 additions & 0 deletions src/Resources/views/CRUD/Intl/display_currency.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{#

This file is part of the Sonata package.

(c) Thomas Rabaix <[email protected]>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{%- apply spaceless %}
{%- if value is null -%}
&nbsp;
{%- else -%}
{% set currency = field_description.options.currency %}
{% set attributes = field_description.options.attributes|default({}) %}
{% set locale = field_description.options.locale|default(null) %}

{{ value|format_currency(currency, attributes, locale) }}
{%- endif -%}
{% endapply -%}
26 changes: 26 additions & 0 deletions src/Resources/views/CRUD/Intl/display_date.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{#

This file is part of the Sonata package.

(c) Thomas Rabaix <[email protected]>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{%- apply spaceless %}
{%- if value is empty -%}
&nbsp;
{%- else -%}
{% set pattern = field_description.options.pattern|default('') %}
{% set calendar = field_description.options.calendar|default('') %}
{% set locale = field_description.options.locale|default(null) %}
{% set timezone = field_description.options.timezone|default(null) %}
{% set dateType = field_description.options.dateType|default(null) %}

<time datetime="{{ value|date('Y-m-d', 'UTC') }}" title="{{ value|date('Y-m-d', 'UTC') }}">
{{ value|format_date(dateType, pattern, timezone, calendar, locale) }}
</time>
{%- endif -%}
{% endapply -%}
27 changes: 27 additions & 0 deletions src/Resources/views/CRUD/Intl/display_datetime.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{#

This file is part of the Sonata package.

(c) Thomas Rabaix <[email protected]>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{%- apply spaceless %}
{%- if value is empty -%}
&nbsp;
{%- else -%}
{% set pattern = field_description.options.pattern|default('') %}
{% set calendar = field_description.options.calendar|default('') %}
{% set locale = field_description.options.locale|default(null) %}
{% set timezone = field_description.options.timezone|default(null) %}
{% set dateType = field_description.options.dateType|default(null) %}
{% set timeType = field_description.options.timeType|default(null) %}

<time datetime="{{ value|date('c', 'UTC') }}" title="{{ value|date('c', 'UTC') }}">
{{ value|format_datetime(dateType, timeType, pattern, timezone, calendar, locale) }}
</time>
{%- endif -%}
{% endapply -%}
22 changes: 22 additions & 0 deletions src/Resources/views/CRUD/Intl/display_decimal.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{#

This file is part of the Sonata package.

(c) Thomas Rabaix <[email protected]>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{%- apply spaceless %}
{%- if value is null -%}
&nbsp;
{%- else -%}
{% set attributes = field_description.options.attributes|default({}) %}
{% set locale = field_description.options.locale|default(null) %}
{% set type = field_description.options.type|default('default') %}

{{ value | format_number(attributes, 'decimal', type, locale) }}
{%- endif -%}
{% endapply -%}
22 changes: 22 additions & 0 deletions src/Resources/views/CRUD/Intl/display_percent.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{#

This file is part of the Sonata package.

(c) Thomas Rabaix <[email protected]>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{%- apply spaceless %}
{%- if value is null -%}
&nbsp;
{%- else -%}
{% set attributes = field_description.options.attributes|default({}) %}
{% set locale = field_description.options.locale|default(null) %}
{% set type = field_description.options.type|default('default') %}

{{ value | format_number(attributes, 'percent', type, locale) }}
{%- endif -%}
{% endapply -%}
12 changes: 12 additions & 0 deletions src/Resources/views/CRUD/Intl/history_revision_timestamp.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{#

This file is part of the Sonata package.

(c) Thomas Rabaix <[email protected]>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{%- include '@SonataAdmin/CRUD/Intl/display_datetime.html.twig' with { value: revision.timestamp } -%}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/list_currency.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#

This file is part of the Sonata package.

(c) Thomas Rabaix <[email protected]>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{% extends admin.getTemplate('base_list_field') %}

{% block field%}
{%- include '@SonataAdmin/CRUD/Intl/display_currency.html.twig' -%}
{% endblock %}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/list_date.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#

This file is part of the Sonata package.

(c) Thomas Rabaix <[email protected]>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{% extends admin.getTemplate('base_list_field') %}

{% block field %}
{%- include '@SonataAdmin/CRUD/Intl/display_date.html.twig' -%}
{% endblock %}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/list_datetime.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#

This file is part of the Sonata package.

(c) Thomas Rabaix <[email protected]>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{% extends admin.getTemplate('base_list_field') %}

{% block field %}
{%- include '@SonataAdmin/CRUD/Intl/display_datetime.html.twig' -%}
{% endblock %}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/list_decimal.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#

This file is part of the Sonata package.

(c) Thomas Rabaix <[email protected]>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{% extends admin.getTemplate('base_list_field') %}

{% block field %}
{%- include '@SonataAdmin/CRUD/Intl/display_decimal.html.twig' -%}
{% endblock %}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/list_percent.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#

This file is part of the Sonata package.

(c) Thomas Rabaix <[email protected]>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{% extends admin.getTemplate('base_list_field') %}

{% block field %}
{%- include '@SonataAdmin/CRUD/Intl/display_percent.html.twig' -%}
{% endblock %}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/show_currency.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#

This file is part of the Sonata package.

(c) Thomas Rabaix <[email protected]>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %}

{% block field %}
{%- include '@SonataAdmin/CRUD/Intl/display_currency.html.twig' -%}
{% endblock %}
Loading