File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 7373 }
7474 return [ fieldQueryParam , queryParams ] ;
7575 }
76-
76+
77+ function getTextSafe ( text ) {
78+ /**
79+ * Safely retrieves the translated text using gettext if available.
80+ * Django doesn't always load the admin:jsi18n URL, for instance, when
81+ * has_delete_permission is set to false. In these cases, the gettext
82+ * function may be unavailable.
83+ * Reference: https://github.com/django/django/blob/main/django/contrib/admin/templates/admin/change_list.html#L10-L12
84+ *
85+ */
86+ if ( typeof gettext !== 'undefined' ) {
87+ return gettext ( text ) ;
88+ } else {
89+ return text ;
90+ }
91+ }
92+
7793 $ ( document ) . ready ( function ( ) {
7894 $ ( '.django-admin-list-filter' ) . select2 ( {
7995 allowClear : true ,
80- placeholder : gettext ( "Filter" )
96+ placeholder : getTextSafe ( "Filter" )
8197 } ) . on ( "select2:select" , function ( e ) {
8298 var navURL = new URL ( window . location . href ) ;
8399 let [ fieldQueryParam , queryParams ] = getQueryParams ( e , $ ( this ) . data ( "isChoicesFilter" ) ) ;
You can’t perform that action at this time.
0 commit comments