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

Add auto-detect locale support #33

Merged
merged 1 commit into from
Dec 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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