Version

Documentation » Internationalization (i18n)

« 5. Number Helper

1. Create a custom timezone detector

You can create and add your own timezone detector.

1.1. Create the detector class

Todo:
  • add example class called MyCustomTimezoneDetector

1.2. Add the Service

Create a service with the sonata_intl.timezone_detector tag with a custom alias.

  • YAML
    # config/services.yaml
    
    services:
        app.my_custom_timezone_detector:
            class: App\TimezoneDetector\MyCustomTimezoneDetector
            tags:
                - { name: sonata_intl.timezone_detector }
    
  • XML
    <!-- config/services.xml -->
    
    <service id="app.my_custom_timezone_detector" class="App\TimezoneDetector\MyCustomTimezoneDetector">
        <tag name="sonata_intl.timezone_detector"/>
    </service>
    

1.3. Add the detector to the Configuration

You can now use this class by configuring the detector section:

  • YAML
    # config/packages/sonata_intl.yaml
    
    sonata_intl:
        timezone:
            detectors:
                - app.my_custom_timezone_detector
                - sonata.intl.timezone_detector.user
                - sonata.intl.timezone_detector.locale
    

Important

In order to guess the timezone, the detectors will be called in the order they are declared.

Found a typo? Something is wrong in this documentation? Just fork and edit it!