Skip to content

Instantly share code, notes, and snippets.

@IlanFrumer
Created November 14, 2013 09:52
Show Gist options
  • Save IlanFrumer/7464242 to your computer and use it in GitHub Desktop.
Save IlanFrumer/7464242 to your computer and use it in GitHub Desktop.
detectLanguage = ->
lang = undefined
lang = lang[1] if navigator and navigator.userAgent and (lang = navigator.userAgent.match(/android.*\W(\w\w)-(\w\w)\W/i))
if not lang and navigator
if navigator.language
lang = navigator.language
else if navigator.browserLanguage
lang = navigator.browserLanguage
else if navigator.systemLanguage
lang = navigator.systemLanguage
else lang = navigator.userLanguage if navigator.userLanguage
lang = lang.substr(0, 2)
if /^(be|ru|uk)/.test(lang)
"russian"
else if /^(iw|he)/.test(lang)
"hebrew"
else
"english"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment