Skip to content

Commit

Permalink
Add auto-detect locale support (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
greyli authored and miguelgrinberg committed Dec 22, 2017
1 parent 6503a2f commit 32e18b6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions flask_moment.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ def include_jquery(version='2.1.0', local_js=None):
return Markup(js)

@staticmethod
def locale(language):
return Markup('<script>\nmoment.locale("%s");\n</script>' % language)

def locale(language='en', auto_detect=False):
if auto_detect:
return Markup('<script>\nvar locale = window.navigator.userLanguage || window.navigator.language;\n'
'moment.locale(locale);\n</script>')
else:
return Markup('<script>\nmoment.locale("%s");\n</script>' % language)

@staticmethod
def lang(language):
return _moment.locale(language)
Expand Down

0 comments on commit 32e18b6

Please sign in to comment.