jazzband / django-recurrence

Utility for working with recurring dates in Django.
https://django-recurrence.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
475 stars 188 forks source link

Django 1.8 / Python 3.3/3.4 Uncaught ReferenceError: pgettext is not defined #47

Open brechmos opened 9 years ago

brechmos commented 9 years ago

I recently moved over to django 1.8 and Python3. I completely understand that this is experimental for Python 3 and is valid for up to Django 1.7 but I am having an issue.

I continue to get Uncaught ReferenceError: pgettext is not defined. I tried following the instructions:

js_info_dict = {
    'packages': ('recurrence', ),
}
# jsi18n can be anything you like here
urlpatterns += patterns(
    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
)

but I am still getting errors. I am not sure if the errors are "expected" with Django 1.8 or if I might be just doing something wrong.

The error is at:

recurrence.display.weekdays_oneletter = [
    pgettext('Monday first letter', 'M'),   <-- Here
    pgettext('Tuesday first letter', 'T'),
    pgettext('Wednesday first letter', 'W'),

though is probably not too surprising. :-)

Any ideas would be appreciated.

dominicrodger commented 9 years ago

Works for me with Django 1.8, though I've not tested with Python 3 (though that should be irrelevant, since the issue is with the JavaScript rather than the Python). Are you sure that you're seeing the jsi18n JavaScript included in your output HTML? That's what adds pggettext to global scope. That should be included automatically as part of {{ form.media }}, so I'm not quite sure what could be going on here.

dominicrodger commented 9 years ago

Did you ever manage to figure this out @brechmos?

brechmos commented 9 years ago

Sorry, I was away on vacation this past week. I found a small hack to get around it but I have not figured it out. I will have more time this week to see if I can figure out where my issue is.

On Fri, Jul 24, 2015 at 3:44 PM, Dominic Rodger notifications@github.com wrote:

Did you ever manage to figure this out @brechmos https://github.com/brechmos?

— Reply to this email directly or view it on GitHub https://github.com/django-recurrence/django-recurrence/issues/47#issuecomment-124674733 .

Craig Jones craigj@jhu.edu 443-712-8152 mri.jhu.edu/~craig Google Talk: brechmos Skype: brechmos FM Kirby Center, Kennedy Krieger Institute Dept of Radiology, Johns Hopkins Medical Insitutes

Lythimus commented 9 years ago

@brechmos would you mind sharing your hack? I'm getting the same issue using Python 2.7.6 running django 1.7.3 and recurrence 1.2.0. I also set up i18n preferences to see if that would get me past the missing requirement with no luck. I'm manually including recurrence.css, recurrence.js, and recurrence-widget.js in an extrastyle block in one of my templates in that order.

Here are my requirements if it's of any help:

dominicrodger commented 9 years ago

So you also need to include the javascript_catalog view - which is where pgettext is defined (see https://docs.djangoproject.com/en/1.8/topics/i18n/translation/#module-django.views.i18n). May I ask why you're including things manually instead of just using {{ form.media }}?

Lythimus commented 9 years ago

@dominicrodger I have some other fields which need specific DOM elements wrapped around them in the form field for a library's sake. I included the javascript_catalog view import in my urls.py, but I'm still receiving the same error. I'll play with it some more tomorrow.

dominicrodger commented 9 years ago

@Lythimus - are you actually including the jsi18n JavaScript in your HTML? The missing pgettext method is a JavaScript method defined in that file, so the browser needs to be able to see it for django-recurrence to work.

Lythimus commented 9 years ago

I wasn't manually including the jsi18n file. I wasn't sure if you meant danabr's implementation of jsI18n or Ted or if it mattered, but regardless, my preference remained installing without requiring internationalization. So I threw the following in my template before pulling in recurrence.js and it seems to be functioning:

// @TODO: Remove this hack when django-recurrence internationalization detection
// is fixed or when i18n support is added to Knock
if (!pgettext) {
    function pgettext(ignore, t) {
        return gettext(t);
    }
}

I should probably not I wasn't passing any arguments into the template rendering of the form view other than for DOM rendering: {{ form.recurrences|bootstrap_horizontal:"col-md-6" }}

Thanks for the assistance @dominicrodger.

brechmos commented 9 years ago

I actually ended up doing what @Lythimus did too.

I hate to ask such a stupid question, though, how do you include the jsi18n in there? I tried the "Set up Internationalization" in the Installation docs, but it didn't seem to do anything for me. I was still getting the pgettext problem.

dominicrodger commented 9 years ago

If you're using a form with a RecurrenceField on it, you should just add a {{ form.media }} somewhere in your template, and it should include the JavaScript for you.

@Lythimus - when you say "when django-recurrence internationalization detection is fixed" in your comment above - do you mean that django-recurrence should detect the missing pgettext reference, and supply a dummy implementation (as you're doing above)? How would you like to see this resolved?

As far as I can tell, all you have to do for django-recurrence is either:

  1. Add the javascript_catalog view to your urls.py, and just ensure {{ form.media }} is included in your template; or
  2. Add the javascript_catalog view to your urls.py, and manually include it in your template.

Both of those options require using javascript_catalog, regardless of the value of USE_I18N, which is probably a bug, so I'm open to pull requests to fix that (probably using a variation of @Lythimus's example code above) if anyone's got time to throw one together.

williamrexhardin commented 8 years ago

I revised the docs and created a pull request to better reflect the current state of the package. Configuring internationalization is not something we should suggest users to 'skip' as it throws an exception in the browser and breaks the form.

Barium commented 4 years ago

I have same problem using Python 3.8, django-recurrence 1.10.3, Django version 3.0.8. It works in the admin page, but does not work when viewing the regular form. I get the error:

Uncaught ReferenceError: pgettext is not defined

http://localhost:8000/staic/recurrence/js/recurrence.js:1038

Tested with both Firefox and Safari. I have followed the guide and added the JavaScript catalog to the urls.py of the project. I have added {{ form.media }} to the form template before the {{ form }} but after csrf token, as shown in the guide.

I have tried with both LANGUAGE_CODE set to en-us and da, and the same behavior exists.

Following the solution in https://github.com/django-recurrence/django-recurrence/issues/153 solved the issue for me, perhaps the documentation should be update to reflect this.

pedrofaria09 commented 3 years ago

Hello, Im with a problem using recurrence and autocomplete at the same time. My page is divided in 2 forms: 1st form- containing autocomplete, datepicker, etc. 2nd form- containing recurrence and MultiSelectField. When I comment {{ form2.media }}, I got autocomplete working but recurrence doesn't work: Captura de ecrã 2021-08-13, às 15 13 21

When I use {{ form2.media }}, recurrence works, but autocomplete doesn't: Captura de ecrã 2021-08-13, às 15 14 05

If I use the recurrence in 1st form, neither autocomplete and datepicker works, only recurrence.

Any help please?