services:
  _defaults:
    public: true

  prestashop.translation.translator_language_loader:
    class: PrestaShopBundle\Translation\TranslatorLanguageLoader
    arguments:
      - '@prestashop.adapter.module.repository.module_repository'

  prestashop.translation.builder.translation_tree:
    class: PrestaShop\PrestaShop\Core\Translation\Builder\TranslationsTreeBuilder
    arguments:
      - '@router.default'
      - '@prestashop.translation.builder.translation_catalogue'

  prestashop.translation.builder.translation_catalogue:
    class: PrestaShop\PrestaShop\Core\Translation\Builder\TranslationCatalogueBuilder
    arguments:
      - '@prestashop.translation.provider.catalogue_provider_factory'

  prestashop.translation.export.translation_catalogue:
    class: PrestaShop\PrestaShop\Core\Translation\Export\TranslationCatalogueExporter
    arguments:
      - '@prestashop.translation.builder.translation_catalogue'
      - '@prestashop.translation.factory.provider_definition'
      - '@prestashop.translation.dumper.xliff'
      - '@filesystem'
      - '@prestashop.utils.zip_manager'
      - "%translation_catalogues_export_dir%"

  # TRANSLATIONS FACTORIES
  prestashop.translation.translations_factory:
    class: PrestaShopBundle\Translation\Factory\TranslationsFactory

  ps.translations_factory:
    alias: "prestashop.translation.translations_factory"

  prestashop.translation.theme_translations_factory:
    class: PrestaShopBundle\Translation\Factory\ThemeTranslationsFactory
    arguments: [ '@prestashop.translation.theme_provider' ]
    calls:
      - [ addProvider, [ '@prestashop.translation.theme_provider' ] ]

  ps.theme_translations_factory:
    alias: "prestashop.translation.theme_translations_factory"

  prestashop.translation.factory.provider_definition:
    class: PrestaShop\PrestaShop\Core\Translation\Storage\Provider\Definition\ProviderDefinitionFactory

  # TRANSLATIONS PROVIDERS
  prestashop.translation.provider.catalogue_provider_factory:
    class: PrestaShop\PrestaShop\Core\Translation\Storage\Provider\CatalogueProviderFactory
    arguments:
      - '@prestashop.translation.loader.database'
      - '@prestashop.translation.extractor.legacy_module'
      - '@prestashop.translation.loader.legacy_file'
      - '@prestashop.translation.extractor.theme'
      - '@prestashop.core.addon.theme.repository'
      - '@filesystem'
      - '%themes_translations_dir%'
      - '%modules_dir%'
      - "%translations_dir%"

  prestashop.translation.backoffice_provider:
    class: PrestaShopBundle\Translation\Provider\BackOfficeProvider
    arguments:
      - "@prestashop.translation.database_loader"
      - "%translations_dir%"
    tags:
      - { name: "ps.translation_provider" }

  prestashop.translation.frontoffice_provider:
    class: PrestaShopBundle\Translation\Provider\FrontOfficeProvider
    arguments:
      - "@prestashop.translation.database_loader"
      - "%translations_dir%"
    tags:
      - { name: "ps.translation_provider" }

  prestashop.translation.mails_provider:
    class: PrestaShopBundle\Translation\Provider\MailsProvider
    arguments:
      - "@prestashop.translation.database_loader"
      - "%translations_dir%"
    tags:
      - { name: "ps.translation_provider" }

  prestashop.translation.mails_body_provider:
    class: PrestaShopBundle\Translation\Provider\MailsBodyProvider
    arguments:
      - "@prestashop.translation.database_loader"
      - "%translations_dir%"
    tags:
      - { name: "ps.translation_provider" }

  prestashop.translation.others_provider:
    class: PrestaShopBundle\Translation\Provider\OthersProvider
    arguments:
      - "@prestashop.translation.database_loader"
      - "%translations_dir%"
    tags:
      - { name: "ps.translation_provider" }

  prestashop.translation.theme_provider:
    class: PrestaShopBundle\Translation\Provider\ThemeProvider
    arguments:
      - "@prestashop.translation.database_loader"
      - "%themes_translations_dir%"
    properties:
      themeResourcesDirectory: "%themes_dir%"
      filesystem: "@filesystem"
      themeRepository: "@prestashop.core.addon.theme.repository"
      themeExtractor: "@prestashop.translation.theme_extractor"
      defaultTranslationDir: "%translations_dir%"

  prestashop.translation.modules_provider:
    class: PrestaShopBundle\Translation\Provider\ModulesProvider
    arguments:
      - "@prestashop.translation.database_loader"
      - "%translations_dir%"
    tags:
      - { name: "ps.translation_provider" }

  prestashop.translation.external_module_provider:
    class: PrestaShopBundle\Translation\Provider\ExternalModuleLegacySystemProvider
    arguments:
      - "@prestashop.translation.database_loader"
      - "%modules_dir%"
      - "@prestashop.translation.legacy_file_loader"
      - "@prestashop.translation.legacy_module.extractor"
      - "@prestashop.translation.module_provider"
    tags:
      - { name: "ps.translation_provider" }

  prestashop.translation.module_provider:
    class: PrestaShopBundle\Translation\Provider\ModuleProvider
    arguments:
      - "@prestashop.translation.database_loader"
      - "%translations_dir%"
    tags:
      - { name: "ps.translation_provider" }

  prestashop.translation.search_provider:
    class: PrestaShopBundle\Translation\Provider\SearchProvider
    arguments:
      - "@prestashop.translation.database_loader"
      - "@prestashop.translation.external_module_provider"
      - "%translations_dir%"
    tags:
      - { name: "ps.translation_provider" }

  # TRANSLATIONS
  prestashop.translation.database_loader:
    class: PrestaShopBundle\Translation\Loader\DatabaseTranslationLoader
    arguments:
      - "@doctrine.orm.entity_manager"
    tags:
      - { name: translation.loader, alias: db }

  prestashop.translation.loader.database:
    class: PrestaShop\PrestaShop\Core\Translation\Storage\Loader\DatabaseTranslationLoader
    arguments:
      - "@prestashop.core.admin.lang.repository"
      - "@prestashop.core.admin.translation.repository"

  prestashop.translation.sql_loader:
    class: PrestaShopBundle\Translation\Loader\SqlTranslationLoader
    tags:
      - { name: translation.loader, alias: db }

  prestashop.translation.reader.legacy_file:
    class: PrestaShop\PrestaShop\Core\Translation\Storage\Loader\LegacyFileReader
    arguments:
      - "@prestashop.core.translation.locale.converter"

  prestashop.translation.legacy_file_reader:
    class: PrestaShopBundle\Translation\Loader\LegacyFileReader
    arguments:
      - "@prestashop.core.translation.locale.converter"

  prestashop.translation.loader.legacy_file:
    class: PrestaShop\PrestaShop\Core\Translation\Storage\Loader\LegacyFileLoader
    arguments:
      - "@prestashop.translation.reader.legacy_file"
    tags:
      - { name: translation.loader, alias: legacy_files }

  prestashop.translation.legacy_file_loader:
    class: PrestaShopBundle\Translation\Loader\LegacyFileLoader
    arguments:
      - "@prestashop.translation.legacy_file_reader"
    tags:
      - { name: translation.loader, alias: legacy_files }

  # cannot decorate the original one because it is loaded later
  # this version activates loading legacy wordings in smarty files
  prestashop.translation.extractor.smarty.legacy:
    class: PrestaShop\TranslationToolsBundle\Translation\Extractor\SmartyExtractor
    arguments:
      - "@prestashop.compiler.smarty.template"
      - true


  prestashop.translation.extractor.theme:
    class: PrestaShop\PrestaShop\Core\Translation\Storage\Extractor\ThemeExtractor
    arguments:
      - "@prestashop.translation.extractor.smarty.legacy"

  prestashop.translation.theme_extractor:
    class: PrestaShopBundle\Translation\Extractor\ThemeExtractor
    arguments:
      - "@prestashop.translation.extractor.smarty.legacy"

  prestashop.translation.extractor.legacy_module:
    class: PrestaShop\PrestaShop\Core\Translation\Storage\Extractor\LegacyModuleExtractor
    arguments:
      - "@prestashop.translation.extractor.php"
      - "@prestashop.translation.extractor.smarty.legacy"
      - "@prestashop.translation.extractor.twig"
      - "%modules_dir%"
      - "%translations_catalogue_extract_excluded_dirs%"

  prestashop.translation.legacy_module.extractor:
    class: PrestaShopBundle\Translation\Extractor\LegacyModuleExtractor
    arguments:
      - "@prestashop.translation.extractor.php"
      - "@prestashop.translation.extractor.smarty.legacy"
      - "@prestashop.translation.extractor.twig"
      - "%modules_dir%"

  prestashop.translation.dumper.xliff:
    class: PrestaShop\TranslationToolsBundle\Translation\Dumper\XliffFileDumper

  prestashop.translation.theme.exporter:
    class: PrestaShopBundle\Translation\Exporter\ThemeExporter
    arguments:
      - "@prestashop.translation.theme_extractor"
      - "@prestashop.translation.theme_provider"
      - "@prestashop.core.addon.theme.repository"
      - "@prestashop.translation.dumper.xliff"
      - "@prestashop.utils.zip_manager"
      - "@filesystem"
    properties:
      cacheDir: "%kernel.cache_dir%"
    calls:
      - [ setExportDir, [ "%kernel.cache_dir%/export" ] ]

  # Api - i18n
  prestashop.translation.api:
    abstract: true
    class: PrestaShopBundle\Translation\Api\AbstractApi
    calls:
      - [ setTranslator, [ '@translator' ] ]

  prestashop.translation.api.stock:
    class: PrestaShopBundle\Translation\Api\StockApi
    parent: prestashop.translation.api
    public: true

  prestashop.translation.api.international:
    class: PrestaShopBundle\Translation\Api\InternationalApi
    parent: prestashop.translation.api
    public: true
