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

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

Open
brechmos opened this issue Jul 10, 2015 · 13 comments

Comments

@brechmos
Copy link

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
Copy link
Contributor

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
Copy link
Contributor

Did you ever manage to figure this out @brechmos?

@brechmos
Copy link
Author

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
#47 (comment)
.

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
Copy link

Lythimus commented Aug 5, 2015

@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:

  • Django==1.7.3
  • dj-database-url==0.3.0
  • django-extensions==1.5.5
  • django-jsonfield==0.9.13
  • django-model-utils==2.2
  • django-phonenumber-field==0.6
  • django-select2==4.3.1
  • django-user-accounts==1.0.1
  • django-recurrence==1.2.0
  • eventlog==0.10.0
  • gondor==1.2.5
  • gunicorn==19.1.1
  • lxml==3.4.1
  • metron==1.3.5
  • opbeat==2.1
  • pinax-theme-bootstrap==5.6.0
  • psycopg2==2.5.4
  • twilio==4.4.0

@dominicrodger
Copy link
Contributor

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
Copy link

Lythimus commented Aug 5, 2015

@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
Copy link
Contributor

@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
Copy link

Lythimus commented Aug 5, 2015

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
Copy link
Author

brechmos commented Aug 6, 2015

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link

Barium commented Jul 22, 2020

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 #153 solved the issue for me, perhaps the documentation should be update to reflect this.

@pedrofaria09
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants