yiisoft / yii2-jui

Yii 2 JQuery UI extension.
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
131 stars 114 forks source link

When $app->language is set as 'en-US', it fails to load ui/i18n/datepicker-en.js #74

Closed fonemi closed 5 years ago

fonemi commented 6 years ago

What steps will reproduce the problem?

Set $app->language = 'en-US', use DatePickerWidget anywhere in page.

What's expected?

If language JS file doesn't exist, it shouldn't be included.

What do you get instead?

404 not found error in javascript console of the browser.

Additional info

Q A
Yii vesion 2.0.13.1
PHP version 7.1.4
Operating system macOS Sierra
samdark commented 6 years ago

https://github.com/yiisoft/yii2-jui/pull/15

samdark commented 5 years ago

Can't be easily fixed in 2.0. Closing it unless there's a bright new idea.

smohadjer commented 4 years ago

For me even if the language in config/web.php is set to "en" this problem happens. In vendor/bower/jquery-ui/ui/i18n folder there is no datepicker-en.js. There are only en-AU, en-GB, and en-NZ versions. Any idea why is that and how I can fix this problem? I'm on Yii 2.0.35.

smohadjer commented 4 years ago

I guess when the language of a website is "en" we don't need a language file for datepicker and that's why jQueryUI doesn't provide a datepicker-en.js, so why is Yii trying to load such a script?

martin-paliza commented 2 years ago

Quick and dirty "solution" for cases when the language is set to 'en-US' and cant be changed, just add in the config/web.php file the following:

'components'=>[
...
    'assetManager' => [
            'bundles' => [
                'yii\jui\DatePickerLanguageAsset' => [                  
                    'autoGenerate' => false,                            
                ]
            ]
        ],
]
raimon-segura commented 7 months ago

@martin-paliza solution works well to avoid that error in browser. To change widget's language, as current language in yii2, you can create a custom AssetBundle & register it at "main.php" layout template like:

backend\assets\DatePickerAllLanguagesAsset::register($this);

`<?php

namespace backend\assets;

use yii\web\AssetBundle;

class DatePickerAllLanguagesAsset extends AssetBundle {

public $sourcePath = '@bower/jquery-ui/ui';

public $jsOptions = array(
    'position' => \yii\web\View::POS_END
);

public $js = [
    'i18n/datepicker-af.js',
    'i18n/datepicker-ar-DZ.js',
    // ...and other js files
];

}`

By the way, if you are compressing all files in a single minified one, maybe you have to put this "DatePickerAllLanguagesAsset" at the end in the "bundles" list , or at least after "yii\jui\JuiAsset"

hope this helps :D