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

IBX-2964: Flatpickr widget localization #2059

Merged
merged 6 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
barw4 marked this conversation as resolved.
Show resolved Hide resolved
})(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;
}
}