Repository: wagtail/wagtail

Issue:
Broken URL for jquery.ui.datepicker when 'en-US' used as lang 
This isn't a big deal at all, but wanted to post just in case anyone wants to take a look.

When loading a page with `jquery.ui.datepicker.js`, I notice in console that a call to http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-en-US.js returns a 404.

I searched out the CDN for the directory in which the file is attempting to be called:
http://jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/

As you can see, there is no `../jquery.ui.datepicker-en-US.js` present (not that there necessarily ought to be)

The call stems from:
https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailadmin/templatetags/localize.py#L42

The interpolation inserts `en-US` into the URI

Again, no big deal... just FYI

Cheers, all!

Edit:

I should add, this issue does _not_ break usability - a fallback seems to be in place.



Discussion:
Thanks @Nicksil, nice catch !

The `get_localized_datepicker_js`tries to include the correct translation file depending on the currently selected language. Of course a translation for en-US doesn't exist and since it can't find it it will use the default language (which _actually is_  en-US).

In any case, trying to include a non-existent JS is not good; I will include a check to `get_localized_datepicker_js` to return `''` if the language is en-US.

Same for en-CA.

You may also want to consider hosting the translation files within Wagtail rather than pulling them from googlecode.com as they must be well out-of-date compared to the version of JQuery UI being used.


Resolving patch:
diff --git a/wagtail/wagtailadmin/templatetags/localize.py b/wagtail/wagtailadmin/templatetags/localize.py
--- a/wagtail/wagtailadmin/templatetags/localize.py
+++ b/wagtail/wagtailadmin/templatetags/localize.py
@@ -1,5 +1,6 @@
 from django import template
 from django.conf import settings
+from django.templatetags.static import static
 from django.utils import formats
 from django.utils.translation import get_language
 
@@ -25,6 +26,15 @@ def get_date_format_override():
     else: # Fall back to ISO if I18N is *not* used
         return 'yy-mm-dd'
 
+# This is a list of all supported langs for jquery-ui datepicker which exist in
+# wagtailadmin/js/venor/i18n/. In case any new translations are added there the
+# language code should also be added in this list.
+SUPPORTED_DATEPICKER_LANGS = ['af', 'ar-DZ', 'ar', 'az', 'be', 'bg', 'bs', 'ca', 'cs', 'cy-GB', 'da', 'de',
+    'el', 'en-AU', 'en-GB', 'en-NZ', 'eo', 'es', 'et', 'eu', 'fa', 'fi', 'fo', 'fr-CA', 'fr-CH', 'fr', 'gl',
+    'he', 'hi', 'hr', 'hu', 'hy', 'id', 'is', 'it', 'ja', 'ka', 'kk', 'km', 'ko', 'ky', 'lb', 'lt', 'lv',
+    'mk', 'ml', 'ms', 'nb', 'nl-BE', 'nl', 'nn', 'no', 'pl', 'pt-BR', 'pt', 'rm', 'ro', 'ru', 'sk', 'sl', 'sq',
+    'sr-SR', 'sr', 'sv', 'ta', 'th', 'tj', 'tr', 'uk', 'vi', 'zh-CN', 'zh-HK', 'zh-TW'
+]
 # Get the correct i18n + l10n settings for datepicker depending on current 
 # thread language  
 @register.simple_tag
@@ -39,10 +49,14 @@ def get_localized_datepicker_js():
             lang = lang_parts[0].lower() +'-'+ lang_parts[1].upper()
         else:
             lang=lang.lower()
-        return '<script src="//jquery-ui.googlecode.com/svn/tags/latest/ui/i18n/jquery.ui.datepicker-{0}.js"></script>'.format(
-            lang
-        )
+        if lang in SUPPORTED_DATEPICKER_LANGS:
+            translation_file = static("wagtailadmin/js/vendor/i18n/jquery.ui.datepicker-{0}.js".format(
+                lang
+            ))
+            return '<script src="{0}"></script>'.format(translation_file)
+        else: # Don't return anything if language is not supported
+            return ''
         
-    else: # Don't write anything if we don't use I18N and L10N
+    else: # Don't return anything if we don't use I18N and L10N
         return ''        
         
\ No newline at end of file


Test patch: