Skip to content

Commit

Permalink
IBX-2964: Flatpickr widget localization (#2059)
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Aug 22, 2022
1 parent 734db95 commit 173caf6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bundle/Resources/config/services/ui_config/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@ services:
$configResolver: '@ezpublish.config.resolver'
tags:
- { name: ezplatform.admin_ui.config_provider, key: 'iconPaths' }

Ibexa\AdminUi\UI\Config\Provider\BackOfficeLanguage:
tags:
- { name: ezplatform.admin_ui.config_provider, key: 'backOfficeLanguage' }
1 change: 1 addition & 0 deletions src/bundle/Resources/encore/ez.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const layout = [
path.resolve(__dirname, '../public/js/scripts/admin.notifications.modal.js'),
path.resolve(__dirname, '../public/js/scripts/admin.location.add.translation.js'),
path.resolve(__dirname, '../public/js/scripts/admin.form.autosubmit.js'),
path.resolve(__dirname, '../public/js/scripts/widgets/flatpickr.js'),
];
const fieldTypes = [];

Expand Down
9 changes: 9 additions & 0 deletions src/bundle/Resources/public/js/scripts/widgets/flatpickr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import flatpickrLanguages
from '../../../../../../../../../../public/bundles/ezplatformadminuiassets/vendors/flatpickr/dist/l10n';

(function (global, doc, eZ, flatpickr) {
const { backOfficeLanguage } = eZ.adminUiConfig;
const flatpickrLanguage = flatpickrLanguages[backOfficeLanguage] ?? flatpickrLanguages.default;

flatpickr.localize(flatpickrLanguage);
})(window, window.document, window.eZ, window.flatpickr);
36 changes: 36 additions & 0 deletions src/lib/UI/Config/Provider/BackOfficeLanguage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\AdminUi\UI\Config\Provider;

use EzSystems\EzPlatformAdminUi\UI\Config\ProviderInterface;
use EzSystems\EzPlatformUser\UserSetting\UserSettingService;

final class BackOfficeLanguage implements ProviderInterface
{
/** @var \EzSystems\EzPlatformUser\UserSetting\UserSettingService */
private $userSettingService;

public function __construct(UserSettingService $userSettingService)
{
$this->userSettingService = $userSettingService;
}

/**
* @inheritdoc
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
public function getConfig(): string
{
$language = $this->userSettingService->getUserSetting('language');

return $language->value;
}
}

0 comments on commit 173caf6

Please sign in to comment.