Skip to content

Instantly share code, notes, and snippets.

@dommmel
Created September 18, 2012 13:43

Revisions

  1. dommmel revised this gist Sep 18, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion localize_greeting.coffee
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ greeting_for =
    "default" : "Hi"
    "DE" :
    "default" : "Hallo"
    "Baden-Wurttemberg" : "Hallöle"
    "Baden-Wurttemberg" : "Grüß Gottle"
    "Bayern" : "Servus"
    "Hamburg" : "Moin"
    "CH" : "Grüezi"
  2. dommmel revised this gist Sep 18, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions localize_greeting.coffee
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    # Usage:
    # <span id="sayhi">привет</span>
    # <script>
    # replace_text_with_greeting("#sayhi")
    # replace_text_with_greeting("#sayhi");
    # </script>


    @@ -23,6 +23,7 @@ greeting_for =
    "Bayern" : "Servus"
    "Hamburg" : "Moin"
    "CH" : "Grüezi"
    "AT" : "Habe die Ehre"
    "FR" : "Salut"
    "US" : "Hello"

    @@ -34,4 +35,3 @@ replace_text_with_greeting = (selector) ->
    else
    greeting_for["default"]
    )

  3. dommmel revised this gist Sep 18, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion localize_greeting.coffee
    Original file line number Diff line number Diff line change
    @@ -21,6 +21,8 @@ greeting_for =
    "default" : "Hallo"
    "Baden-Wurttemberg" : "Hallöle"
    "Bayern" : "Servus"
    "Hamburg" : "Moin"
    "CH" : "Grüezi"
    "FR" : "Salut"
    "US" : "Hello"

    @@ -33,4 +35,3 @@ replace_text_with_greeting = (selector) ->
    greeting_for["default"]
    )


  4. dommmel renamed this gist Sep 18, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. dommmel created this gist Sep 18, 2012.
    36 changes: 36 additions & 0 deletions localize_greeting
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    ##################################################################
    # #
    # 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" : "Hallöle"
    "Bayern" : "Servus"
    "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"]
    )