services:
    oro_locale.settings:
        class: Oro\Bundle\LocaleBundle\Model\LocaleSettings
        public: true
        arguments:
            - '@oro_config.manager'
            - '@oro_locale.calendar_factory'
            - '@oro_locale.manager.localization'
            - '@oro_locale.configuration_provider'
            - '@oro_theme.registry'

    Oro\Bundle\LocaleBundle\Model\LocaleSettings:
        alias: 'oro_locale.settings'

    oro_locale.configuration_provider:
        class: Oro\Bundle\LocaleBundle\Configuration\LocaleConfigurationProvider
        arguments:
            - '@oro_locale.name_format_configuration.provider'
            - '@oro_locale.address_format_configuration.provider'
            - '@oro_locale.locale_data_configuration.provider'

    oro_locale.name_format_configuration.provider:
        class: Oro\Bundle\LocaleBundle\Configuration\NameFormatConfigurationProvider
        parent: oro.static_config_provider.abstract
        arguments:
            - '%kernel.cache_dir%/oro/locale_name_format.php'
            - '%kernel.debug%'

    oro_locale.address_format_configuration.provider:
        class: Oro\Bundle\LocaleBundle\Configuration\AddressFormatConfigurationProvider
        parent: oro.static_config_provider.abstract
        arguments:
            - '%kernel.cache_dir%/oro/locale_address_format.php'
            - '%kernel.debug%'

    oro_locale.locale_data_configuration.provider:
        class: Oro\Bundle\LocaleBundle\Configuration\LocaleDataConfigurationProvider
        parent: oro.static_config_provider.abstract
        arguments:
            - '%kernel.cache_dir%/oro/locale_data.php'
            - '%kernel.debug%'

    oro_locale.helper.localization:
        class: Oro\Bundle\LocaleBundle\Helper\LocalizationHelper
        arguments:
            - '@oro_locale.manager.localization'
            - '@oro_locale.provider.current_localization'

    Oro\Bundle\LocaleBundle\Helper\LocalizationHelper:
        alias: oro_locale.helper.localization

    oro_locale.helper.default_locale_localization:
        class: Oro\Bundle\LocaleBundle\Helper\LocalizationHelper
        arguments:
           - '@oro_locale.manager.localization'
           - '@oro_locale.provider.config_default_localization'

    oro_locale.helper.localization.link:
        tags:
            - { name: oro_service_link, service: oro_locale.helper.localization }

    oro_locale.listener.orm.localization_listener:
        class: Oro\Bundle\LocaleBundle\EventListener\ORM\LocalizationListener
        arguments:
            - '@oro_locale.translation.strategy.localization_fallback_strategy'
            - '@oro_locale.manager.localization'
        tags:
            - { name: doctrine.orm.entity_listener, entity: 'Oro\Bundle\LocaleBundle\Entity\Localization', event: postPersist }
            - { name: doctrine.orm.entity_listener, entity: 'Oro\Bundle\LocaleBundle\Entity\Localization', event: postUpdate }
            - { name: doctrine.orm.entity_listener, entity: 'Oro\Bundle\LocaleBundle\Entity\Localization', event: postRemove }

    oro_locale.datagrid.extension.localized_value:
        class: Oro\Bundle\LocaleBundle\Datagrid\Extension\LocalizedValueExtension
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_entity.orm.entity_class_resolver'
            - '@oro_locale.helper.localization'
            - '@Doctrine\Inflector\Inflector'
        tags:
            - { name: oro_datagrid.extension }

    oro_locale.datagird.formatter.localized_value_property:
        class: Oro\Bundle\LocaleBundle\Datagrid\Formatter\Property\LocalizedValueProperty
        tags:
            - { name: oro_datagrid.extension.formatter.property, type: localized_value }

    oro_locale.translation.strategy.localization_fallback_strategy:
        class: Oro\Bundle\LocaleBundle\Translation\Strategy\LocalizationFallbackStrategy
        arguments:
            - '@doctrine'
            - '@oro_locale.cache.provider.tree_fallback_strategy'
        tags:
            - { name: oro_translation.extension.translation_strategy, priority: 10 }
            - { name: kernel.cache_warmer }

    # Calendar
    oro_locale.calendar:
        shared: false
        public: true
        class: Oro\Bundle\LocaleBundle\Model\Calendar

    oro_locale.calendar_factory:
        class: Oro\Bundle\LocaleBundle\Model\CalendarFactory
        arguments:
            - '@Psr\Container\ContainerInterface'
        tags:
            - { name: container.service_subscriber, id: 'oro_locale.calendar' }

    # Converters
    oro_locale.format_converter.date_time.registry:
        class: Oro\Bundle\LocaleBundle\Converter\DateTimeFormatConverterRegistry
        arguments:
            - [] # converter names
            - ~ # service locator for converters

    oro_locale.format_converter.date_time.intl:
        class: Oro\Bundle\LocaleBundle\Converter\IntlDateTimeFormatConverter
        arguments:
            - '@oro_locale.formatter.date_time'
            - '@translator'
        tags:
            - { name: oro_locale.format_converter.date_time, alias: intl }

    oro_locale.format_converter.date_time.moment:
        class: Oro\Bundle\LocaleBundle\Converter\MomentDateTimeFormatConverter
        arguments:
            - '@oro_locale.formatter.date_time'
            - '@translator'
        tags:
            - { name: oro_locale.format_converter.date_time, alias: moment }

    oro_locale.format_converter.date_time.php:
        class: Oro\Bundle\LocaleBundle\Converter\PhpDateTimeFormatConverter
        arguments:
            - '@oro_locale.formatter.date_time'
            - '@translator'
        tags:
            - { name: oro_locale.format_converter.date_time, alias: php }

    # event listeners
    oro_locale.locale_listener:
        class: Oro\Bundle\LocaleBundle\EventListener\LocaleListener
        arguments:
            - '@oro_locale.settings'
            - '@oro_locale.provider.current_localization'
            - '@stof_doctrine_extensions.listener.translatable'
            - '@translator'
            - '@router'
            - '@oro_distribution.handler.application_status'
        tags:
            - { name: kernel.event_subscriber }

    # Formatters
    oro_locale.formatter.name:
        class: Oro\Bundle\LocaleBundle\Formatter\NameFormatter
        arguments:
            - '@oro_locale.settings'

    oro_locale.formatter.name.link:
        tags:
            - { name: oro_service_link, service: oro_locale.formatter.name }

    oro_locale.formatter.address:
        class: Oro\Bundle\LocaleBundle\Formatter\AddressFormatter
        arguments:
            - '@oro_locale.settings'
            - '@oro_locale.formatter.name'
            - '@property_accessor'
        calls:
            - [setPhoneProvider, ['@oro_address.provider.phone']]

    oro_locale.formatter.date_time:
        class: Oro\Bundle\LocaleBundle\Formatter\DateTimeFormatter
        public: true
        arguments:
            - '@oro_locale.settings'
            - '@translator'

    Oro\Bundle\LocaleBundle\Formatter\NumberFormatter:
        alias: oro_locale.formatter.number

    oro_locale.formatter.number:
        class: Oro\Bundle\LocaleBundle\Formatter\NumberFormatter
        public: true
        arguments:
            - '@oro_locale.settings'
            - '@oro_locale.formatter.factory.intl_number_formatter'

    oro_locale.formatter.factory.intl_number_formatter:
        class: Oro\Bundle\LocaleBundle\Formatter\Factory\IntlNumberFormatterFactory
        arguments:
            - '@oro_locale.settings'

    # DQL formatter
    oro_locale.dql.formatter.name:
        class: Oro\Bundle\LocaleBundle\DQL\DQLNameFormatter
        arguments:
            - '@oro_locale.formatter.name'

    oro_locale.dql.formatter.name.link:
        tags:
            - { name: oro_service_link, service: oro_locale.dql.formatter.name }

    oro_locale.formatter.language_code:
        class: Oro\Bundle\LocaleBundle\Formatter\LanguageCodeFormatter
        public: true
        arguments:
            - '@translator'
            - '@oro_locale.settings'

    oro_locale.formatter.formatting_code:
        class: Oro\Bundle\LocaleBundle\Formatter\FormattingCodeFormatter
        arguments:
            - '@translator'
            - '@oro_locale.settings'

    # Twig extensions
    oro_locale.twig.date_format:
        class: Oro\Bundle\LocaleBundle\Twig\DateFormatExtension
        arguments:
            - '@oro_platform.twig.service_locator'
        tags:
            - { name: twig.extension }

    oro_locale.twig.locale:
        class: Oro\Bundle\LocaleBundle\Twig\LocaleExtension
        arguments:
            - '@oro_platform.twig.service_locator'
        tags:
            - { name: twig.extension }

    oro_locale.twig.calendar:
        class: Oro\Bundle\LocaleBundle\Twig\CalendarExtension
        arguments:
            - '@oro_platform.twig.service_locator'
        tags:
            - { name: twig.extension }

    oro_locale.twig.date_time:
        class: Oro\Bundle\LocaleBundle\Twig\DateTimeExtension
        public: true
        arguments:
            - '@oro_platform.twig.service_locator'
        tags:
            - { name: twig.extension }

    oro_locale.twig.address:
        class: Oro\Bundle\LocaleBundle\Twig\AddressExtension
        arguments:
            - '@oro_platform.twig.service_locator'
        tags:
            - { name: twig.extension }

    oro_locale.twig.number:
        class: Oro\Bundle\LocaleBundle\Twig\NumberExtension
        arguments:
            - '@oro_platform.twig.service_locator'
        tags:
            - { name: twig.extension }

    oro_locale.twig.localization:
        class: Oro\Bundle\LocaleBundle\Twig\LocalizationExtension
        arguments:
            - '@oro_platform.twig.service_locator'
        tags:
            - { name: twig.extension }

    oro_locale.format.datetime:
        class: Oro\Bundle\LocaleBundle\Formatter\DateTimeValueFormatter
        arguments:
            - '@oro_locale.formatter.date_time'
            - '@translator'
        tags:
            - { name: oro_formatter, formatter: datetime, data_type: datetime }

    oro_locale.format.date:
        class: Oro\Bundle\LocaleBundle\Formatter\DateValueFormatter
        arguments:
            - '@oro_locale.formatter.date_time'
            - '@translator'
        tags:
            - { name: oro_formatter, formatter: date, data_type: date }

    oro_locale.format.currency:
        class: Oro\Bundle\LocaleBundle\Formatter\CurrencyFormatter
        arguments:
            - '@oro_locale.formatter.number'
        tags:
            - { name: oro_formatter, formatter: currency, data_type: money }

    oro_locale.entity_name_provider:
        class: Oro\Bundle\LocaleBundle\Provider\EntityNameProvider
        arguments:
            - '@oro_locale.formatter.name.link'
            - '@oro_locale.dql.formatter.name.link'
        tags:
            - { name: oro_entity.name_provider, priority: -80 }

    oro_locale.validator.localization:
        class: Oro\Bundle\LocaleBundle\Validator\Constraints\LocalizationValidator
        public: true
        tags:
            - { name: validator.constraint_validator, alias: oro_locale.localization_validator }

    oro_locale.validator.default_localization:
        class: Oro\Bundle\LocaleBundle\Validator\Constraints\DefaultLocalizationValidator
        arguments:
            - '@oro_locale.manager.localization'
        tags:
            - { name: validator.constraint_validator, alias: oro_locale.default_localization_validator }

    oro_locale.validator.default_localized_fallback_value.not_blank:
        class: Oro\Bundle\LocaleBundle\Validator\Constraints\NotBlankDefaultLocalizedFallbackValueValidator
        public: true
        tags:
            - { name: validator.constraint_validator, alias: oro_locale.default_localized_fallback_value.not_blank }

    oro_locale.acl.voter.localization:
        class: Oro\Bundle\LocaleBundle\Acl\Voter\LocalizationVoter
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@Psr\Container\ContainerInterface'
        calls:
            - [setClassName, ['Oro\Bundle\LocaleBundle\Entity\Localization']]
        tags:
            - { name: security.voter }
            - { name: container.service_subscriber, id: oro_config.manager }

    oro_locale.provider.localization_choices:
        class: Oro\Bundle\LocaleBundle\Provider\LocalizationChoicesProvider
        public: true
        arguments:
            - '@oro_locale.settings'
            - '@oro_locale.formatter.language_code'
            - '@oro_translation.provider.language'
            - '@oro_locale.manager.localization'

    Oro\Bundle\LocaleBundle\Manager\LocalizationManager:
        alias: oro_locale.manager.localization

    oro_locale.manager.localization:
        class: Oro\Bundle\LocaleBundle\Manager\LocalizationManager
        public: true
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_config.manager'
            - '@oro_locale.cache.manager'

    oro_locale.provider.current_localization:
        class: Oro\Bundle\LocaleBundle\Provider\CurrentLocalizationProvider
        arguments:
            - !tagged_iterator oro_locale.extension.current_localization

    oro_locale.provider.config_default_localization:
        class: Oro\Bundle\LocaleBundle\Provider\ConfigDefaultLocalizationProvider
        arguments:
            - '@oro_locale.manager.localization'

    oro_locale.storage.entity_fallback_fields_storage:
        class: 'Oro\Bundle\LocaleBundle\Storage\EntityFallbackFieldsStorage'
        arguments:
            - [] # a map of default fallback fields

    oro_locale.entity_field.extension:
        class: Oro\Bundle\LocaleBundle\EntityExtend\LocaleEntityFieldExtension
        arguments:
            - '@oro_locale.storage.entity_fallback_fields_storage'
            - '@oro_locale.provider.default_fallback_methods_names'
        tags:
            - { name: 'oro_entity_extend.entity_field_extension', priority: 90 }

    oro_locale.twig.date_time_organization:
        class: Oro\Bundle\LocaleBundle\Twig\DateTimeOrganizationExtension
        parent: oro_locale.twig.date_time
        tags:
            - { name: twig.extension }

    oro_locale.layout.data_provider.locale:
        class: Oro\Bundle\LocaleBundle\Layout\LocaleProvider
        arguments:
            - '@oro_locale.helper.localization'
        tags:
            - { name: layout.data_provider, alias: locale }

    oro_locale.localization_scope_criteria_provider:
        class: Oro\Bundle\LocaleBundle\Provider\LocalizationScopeCriteriaProvider
        arguments:
            - "@oro_locale.provider.current_localization"
        tags:
            - { name: oro_scope.provider, scopeType: web_content, priority: 1 }

    oro_locale.provider.preferred_localization_provider:
        class: Oro\Bundle\LocaleBundle\Provider\ChainPreferredLocalizationProvider
        arguments:
            - !tagged_iterator oro_locale.preferred_localization_provider

    Oro\Bundle\LocaleBundle\Provider\PreferredLocalizationProviderInterface:
        alias: 'oro_locale.provider.preferred_localization_provider'
        public: true

    # Application default localization
    # This provider should be called last
    oro_locale.provider.preferred_localization_provider.default:
        class: Oro\Bundle\LocaleBundle\Provider\DefaultPreferredLocalizationProvider
        arguments:
            - '@oro_locale.manager.localization'
        tags:
            - { name: oro_locale.preferred_localization_provider, priority: -255 }

    oro_locale_config.event_listener.localization_change:
        class: Oro\Bundle\LocaleBundle\EventListener\LocalizationChangeListener
        arguments:
            - '@oro_config.user'
            - '@doctrine'
        tags:
            - { name: kernel.event_listener, event: oro_config.update_after, method: onConfigUpdate }

    oro_locale.event_listener.cache:
        class: Oro\Bundle\LocaleBundle\EventListener\DoctrineEventListener
        arguments:
            - '@oro_locale.manager.localization'
        tags:
            - { name: doctrine.event_listener, event: onClear }

    oro_locale.event_listener.strategy_validation_event_listener:
        class: Oro\Bundle\LocaleBundle\EventListener\StrategyValidationEventListener
        arguments:
            - '@property_accessor'
        tags:
            - { name: kernel.event_listener, event: oro_importexport.strategy.build_errors, priority: -255, method: buildErrors }

    Oro\Bundle\LocaleBundle\Action\CheckIfDefaultLanguageAction:
        arguments:
            - '@oro_action.expression.context_accessor'
            - '@oro_config.global'
        tags:
            - { name: oro_action.action, alias: check_if_default_language }

    Oro\Bundle\LocaleBundle\Action\IsDefaultLanguageCondition:
        arguments:
            - '@oro_config.global'
            - '@doctrine'
        tags:
            - { name: oro_action.condition, alias: is_default_language }

    oro_locale.provider.default_fallback_methods_names:
        class: Oro\Bundle\LocaleBundle\Provider\DefaultFallbackMethodsNamesProvider
        arguments:
            - '@Doctrine\Inflector\Inflector'

    oro_locale.formatter.localized_fallback_value_formatter:
        class: Oro\Bundle\LocaleBundle\Formatter\LocalizedFallbackValueFormatter
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_locale.helper.localization'
            - '@translator'
            - '@property_accessor'
        tags:
            - { name: oro_formatter, formatter: oro_locale.localized_fallback_value_formatter }

    oro_locale.provider.localized_fallback_value_name:
        class: 'Oro\Bundle\LocaleBundle\Provider\LocalizedFallbackValueNameProvider'
        arguments:
            - '@translator'
        tags:
            - { name: oro_entity.name_provider, priority: 10 }

    oro_locale.strategy_processor.localized_fallback_value_audit_strategy:
        class: 'Oro\Bundle\LocaleBundle\Strategy\Processor\LocalizedFallbackValueAuditStrategyProcessor'
        arguments:
            - '@doctrine'
            - '@oro_locale.storage.entity_fallback_fields_storage'
        tags:
            - { name: oro_dataaudit.entity_strategy_processor, entityName: Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue }

    oro_locale.strategy_processor.abstract_localized_audit_strategy:
        class: 'Oro\Bundle\LocaleBundle\Strategy\Processor\AbstractLocalizedAuditStrategyProcessor'
        arguments:
            - '@doctrine'
        tags:
            - { name: oro_dataaudit.entity_strategy_processor, entityName: Oro\Bundle\CatalogBundle\Entity\CategoryTitle }
            - { name: oro_dataaudit.entity_strategy_processor, entityName: Oro\Bundle\CatalogBundle\Entity\CategoryShortDescription }
            - { name: oro_dataaudit.entity_strategy_processor, entityName: Oro\Bundle\CatalogBundle\Entity\CategoryLongDescription }
            - { name: oro_dataaudit.entity_strategy_processor, entityName: Oro\Bundle\ProductBundle\Entity\ProductName }
            - { name: oro_dataaudit.entity_strategy_processor, entityName: Oro\Bundle\ProductBundle\Entity\ProductShortDescription }
            - { name: oro_dataaudit.entity_strategy_processor, entityName: Oro\Bundle\ProductBundle\Entity\ProductDescription }
