Created
September 18, 2012 13:43
-
-
Save dommmel/3743178 to your computer and use it in GitHub Desktop.
Localize your greeting message with javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################## | |
# # | |
# Copyright (C) 2012 Dommmel <dommmel@gmail.com> # | |
# This code is released under WTFPL, version 2.0. # | |
# # | |
################################################################## | |
# Usage: | |
# <span id="sayhi">привет</span> | |
# <script> | |
# replace_text_with_greeting("#sayhi"); | |
# </script> | |
# country codes should have the ISO 3166 format. | |
# See http://en.wikipedia.org/wiki/ISO_3166-2 | |
greeting_for = | |
"default" : "Hi" | |
"DE" : | |
"default" : "Hallo" | |
"Baden-Wurttemberg" : "Grüß Gottle" | |
"Bayern" : "Servus" | |
"Hamburg" : "Moin" | |
"CH" : "Grüezi" | |
"AT" : "Habe die Ehre" | |
"FR" : "Salut" | |
"US" : "Hello" | |
replace_text_with_greeting = (selector) -> | |
$.getJSON "http://freegeoip.net/json/?callback=?", (resp) -> | |
$(selector).text( | |
if greeting_for[resp.country_code]? | |
greeting_for[resp.country_code][resp.region_name] or greeting_for[resp.country_code]["default"] or greeting_for[resp.country_code] | |
else | |
greeting_for["default"] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment