-
Notifications
You must be signed in to change notification settings - Fork 611
/
DatepickerI18nAsset.php
62 lines (50 loc) · 1.32 KB
/
DatepickerI18nAsset.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\web\assets\datepickeri18n;
use Craft;
use craft\web\AssetBundle;
use craft\web\assets\jqueryui\JqueryUiAsset;
/**
* Datepicker I18n asset bundle.
*/
class DatepickerI18nAsset extends AssetBundle
{
/**
* @inheritdoc
*/
public function init(): void
{
// Figure out which Datepicker i18n script to load
$languageId = Craft::$app->getLocale()->getLanguageID();
$languages = [
Craft::$app->language,
$languageId,
];
$fallbacks = [
'cy' => 'cy-GB',
'zh' => 'zh-CN',
];
if (isset($fallbacks[$languageId])) {
$languages[] = $fallbacks[$languageId];
}
$sourcePath = __DIR__ . '/dist';
foreach ($languages as $language) {
$filename = "datepicker-$language.js";
if (file_exists("$sourcePath/$filename")) {
$this->sourcePath = $sourcePath;
$this->depends = [
JqueryUiAsset::class,
];
$this->js = [
$filename,
];
break;
}
}
parent::init();
}
}