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

canonicalize_locale_for_moment() returns null but my localization lang is set #8190

Open
clem-tri opened this issue Jun 25, 2024 · 0 comments

Comments

@clem-tri
Copy link

Environment

Sonata packages

show

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle        4.30.2 4.30.2 The missing Symfony Admin Generator

Transitive dependencies not required in composer.json:
sonata-project/block-bundle        5.1.0  5.1.0  Symfony SonataBlockBundle
sonata-project/doctrine-extensions 2.4.0  2.4.0  Doctrine2 behavioral extensions
sonata-project/exporter            3.3.0  3.3.0  Lightweight Exporter library
sonata-project/form-extensions     2.4.0  2.4.0  Symfony form extensions
sonata-project/twig-extensions     2.4.0  2.4.0  Sonata twig extensions

Symfony packages

show

$ composer show --latest 'symfony/*'
Direct dependencies required in composer.json:
symfony/console                    v6.4.8  v7.1.1  Eases the creation of beautiful and testable command line interfaces
symfony/dotenv                     v6.4.8  v7.1.1  Registers environment variables from a .env file
symfony/flex                       v2.4.5  v2.4.5  Composer plugin for Symfony
symfony/framework-bundle           v6.4.8  v7.1.1  Provides a tight integration between Symfony components and the Symfony full-stack framework     
symfony/runtime                    v6.4.8  v7.1.1  Enables decoupling PHP applications from global state
symfony/yaml                       v6.4.8  v7.1.1  Loads and dumps YAML files

Transitive dependencies not required in composer.json:
symfony/asset                      v6.4.8  v7.1.1  Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript file...  
symfony/cache                      v6.4.8  v7.1.1  Provides extended PSR-6, PSR-16 (and tags) implementations
symfony/cache-contracts            v3.5.0  v3.5.0  Generic abstractions related to caching
symfony/clock                      v6.4.8  v7.1.1  Decouples applications from the system clock
symfony/config                     v6.4.8  v7.1.1  Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/dependency-injection       v6.4.8  v7.1.1  Allows you to standardize and centralize the way objects are constructed in your application     
symfony/deprecation-contracts      v3.5.0  v3.5.0  A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge            v6.4.8  v7.1.1  Provides integration for Doctrine with various Symfony components
symfony/error-handler              v6.4.8  v7.1.1  Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher           v6.4.8  v7.1.1  Provides tools that allow your application components to communicate with each other by disp...  
symfony/event-dispatcher-contracts v3.5.0  v3.5.0  Generic abstractions related to dispatching event
symfony/expression-language        v6.4.8  v7.1.1  Provides an engine that can compile and evaluate expressions
symfony/filesystem                 v6.4.8  v7.1.1  Provides basic utilities for the filesystem
symfony/finder                     v6.4.8  v7.1.1  Finds files and directories via an intuitive fluent interface
symfony/form                       v6.4.8  v7.1.1  Allows to easily create, process and reuse HTML forms
symfony/http-foundation            v6.4.8  v7.1.1  Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                v6.4.8  v7.1.1  Provides a structured process for converting a Request into a Response
symfony/options-resolver           v6.4.8  v7.1.1  Provides an improved replacement for the array_replace PHP function
symfony/password-hasher            v6.4.8  v7.1.1  Provides password hashing utilities
symfony/polyfill-intl-grapheme     v1.30.0 v1.30.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          v1.30.0 v1.30.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-normalizer   v1.30.0 v1.30.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.30.0 v1.30.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php83             v1.30.0 v1.30.0 Symfony polyfill backporting some PHP 8.3+ features to lower PHP versions
symfony/property-access            v6.4.8  v7.1.1  Provides functions to read and write from/to an object or array using a simple string notation   
symfony/property-info              v6.4.8  v7.1.1  Extracts information about PHP class' properties using metadata of popular sources
symfony/routing                    v6.4.8  v7.1.1  Maps an HTTP request to a set of configuration variables
symfony/security-acl               v3.3.3  v3.3.3  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v6.4.8  v7.1.1  Provides a tight integration of the Security component into the Symfony full-stack framework     
symfony/security-core              v6.4.8  v7.1.1  Symfony Security Component - Core Library
symfony/security-csrf              v6.4.8  v7.1.1  Symfony Security Component - CSRF Library
symfony/security-http              v6.4.8  v7.1.1  Symfony Security Component - HTTP Integration
symfony/serializer                 v6.4.8  v7.1.1  Handles serializing and deserializing data structures, including object graphs, into array s...  
symfony/service-contracts          v3.5.0  v3.5.0  Generic abstractions related to writing services
symfony/string                     v6.4.8  v7.1.1  Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and graph...  
symfony/translation                v6.4.8  v7.1.1  Provides tools to internationalize your application
symfony/translation-contracts      v3.5.0  v3.5.0  Generic abstractions related to translation
symfony/twig-bridge                v6.4.8  v7.1.1  Provides integration for Twig with various Symfony components
symfony/twig-bundle                v6.4.8  v7.1.1  Provides a tight integration of Twig into the Symfony full-stack framework
symfony/validator                  v6.4.8  v7.1.1  Provides tools to validate values
symfony/var-dumper                 v6.4.8  v7.1.1  Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter               v6.4.8  v7.1.1  Allows exporting any serializable PHP data structure to plain PHP code

PHP version

$ php -v
PHP 8.3.4 (cli) (built: Mar 13 2024 11:42:47) (NTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.3.4, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.4, Copyright (c), by Zend Technologies

Subject

I'm trying to localize my moment.js dates, and I saw that in standard_layout.html.twig, there should be some .js files in public/bundles/sonataform/moment-locale/ for that.

# sonata-project/admin-bundle/src/Resources/views/standard_layout.html.twig
{# TODO: Drop locale for moment calls when dropping support for `sonata-project/form-extensions` 1.x #}
{# localize moment #}
{% set localeForMoment = canonicalize_locale_for_moment() %}
{% if localeForMoment %}
    <script src="{{ asset('bundles/sonataform/moment-locale/' ~ localeForMoment ~ '.js') }}"></script>
{% endif %}

Right now, by following the simple installation documentation, I only have this in my public/bundles/sonataform directory after launching php bin/console assets:install (the files pathes don't fit the asset path pasted above btw 🤔 ) :
image

I've set my language in translation.yaml like that :

framework:
    default_locale: fr
    translator:
        default_path: '%kernel.project_dir%/translations'
        fallbacks:
            - en
        providers:

When debuging, I can see that the twig function canonicalize_locale_for_moment() returns null, so I was thinking that I maybe missed something in the documentation but I didn't found anything related.

Minimal repository with the bug

https://github.com/clem-tri/sf-sonata-sample/tree/master

Steps to reproduce

Expected results

If I didn't omit a step by following the sonata admin installation documentation, I guess there should be a moment.js localized file loaded if you have defined the locale in your symfony config?

Actual results

No file loaded and there is a discrepancy between the files generated in public/bundles/sonataform and the asset path in the standard_layout.html.twig file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant