Я пытаюсь использовать localizeddate, чтобы показать дату на французском языке на моем веб-сайте:
<td>{{ saison.start|localizeddate('medium', 'none') }}</td>
Я следовал различным документам и:
sudo pacman -S php-intlcomposer require twig/extensionscomposer require symfony/intlЯ также отредактировал config/services.yaml, чтобы изменить локаль, но, похоже, это не дало эффекта:
parameters:
locale: 'fr'
Я включил расширения Date и Intl в файлах configpackages\twig_extensions.yaml`:
services:
_defaults:
public: false
autowire: true
autoconfigure: true
# Uncomment any lines below to activate that Twig extension
#Twig\Extensions\ArrayExtension: ~
Twig\Extensions\DateExtension: ~
Twig\Extensions\IntlExtension: ~
#Twig\Extensions\TextExtension: ~
Но у меня все еще есть дата, показанная на английском языке в выходном файле.
Я также попытался более четко указать локаль в localizeddate следующим образом:
<td>{{ saison.start|localizeddate('medium', 'none', 'fr') }}</td>
Но в этом случае я получаю сообщение об ошибке:
An exception has been thrown during the rendering of a template ("The Symfony\Component\Intl\DateFormatter\IntlDateFormatter::__construct() method's argument $locale value 'fr' behavior is not implemented. Only the locale "en" is supported. Please install the "intl" extension for full localization capabilities.").
Я не знаю, чего не хватает.
Нет, не совсем. Вместо этого я использовал: <date variable>|date('d/m/Y')






Поскольку я не нашел правильного ответа, я решил проблему следующим образом (поскольку мне не нужна международная поддержка):
<date variable>|date('d/m/Y')
Это неудовлетворительно, так как localizedate сделано именно для этого, но пока работает.
Имя фильтра изменилось.
Теперь вы должны использовать format_datetime, предоставленный пакетом twig/intl-extra.
https://twig.symfony.com/doc/2.x/filters/format_datetime.html
Похоже, расширение PHP intl было установлено неправильно, так как symfony/intl работает только с локалью en.
The replacement layer is limited to the
enlocale. If you want to use other locales, you should install the intl extension. There is no conflict between the two because, even if you use the extension, this package can still be useful to access the ICU data.
https://symfony.com/doc/current/components/intl.html
Если вы посмотрите на метод __construct() для Symfony\Component\Intl\NumberFormatter, вы увидите, почему ваш код вызвал это исключение:
if ('en' !== $locale && null !== $locale) {
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
}
https://github.com/symfony/intl/blob/v4.0.0/NumberFormatter/NumberFormatter.php#L262
У меня такая же проблема, ты решил ее?