Skip to content

Commit

Permalink
Add language picker
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-c committed Mar 19, 2013
1 parent 2e51d68 commit d3e9540
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
43 changes: 43 additions & 0 deletions app/controllers/language_picker.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
$ = require 'jqueryify'
translate = require 't7e'
enUs = require '../translations/en_us'

DEFAULT = '$DEFAULT'

class LanguagePicker
@DEFAULT = DEFAULT

languages:
'English': DEFAULT
'Polski': 'pl_pl'

el: null
className: 'language-picker'

constructor: ->
preferredLanguage = localStorage.preferredLanguage || DEFAULT

@el = $("<select class='#{@className}'></select>")

for language, code of @languages
option = $("<option value='#{code}'>#{language}</option>")
option.attr 'selected', true if language is preferredLanguage
@el.append option

@el.on 'change', => @onChange arguments...

@el.trigger 'change' unless @el.val() is DEFAULT

onChange: ->
preferredLanguage = @el.val()

if preferredLanguage is DEFAULT
translate.load enUs
translate.refresh()
else
$.getJSON "./translations/#{preferredLanguage}.json", (data) ->
console?.log? "Got translations for #{preferredLanguage}", data
translate.load data
translate.refresh()

module.exports = LanguagePicker
5 changes: 5 additions & 0 deletions app/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ bc.check()
Map::tilesId = 53589
Map::apiKey = '21a5504123984624a5e1a856fc00e238'

LanguagePicker = require 'controllers/language_picker'

languagePicker = new LanguagePicker
languagePicker.el.appendTo document.body

googleAnalytics.init
account: 'UA-1224199-36'
domain: 'snapshotserengeti.org'
Expand Down
8 changes: 0 additions & 8 deletions app/lib/setup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ $ = require 'jqueryify'

translate.load enUs

preferredLanguage = localStorage.preferredLanguage

if preferredLanguage?
$.getJSON "./translations/#{language}.json", (data) ->
console.log "Got translations for #{language}", data
translate.load data
translate.refresh()

require 'json2ify'
require 'es5-shimify'

Expand Down
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h1><a href="/"><img src="images/wordmark.png" alt="Snapshot Serengeti" /></a></
window.app = require('index');
</script>

<script src="http://tracker.zooniverse.org/socket.io/socket.io.js" charset="utf-8"></script>
<script src="http://tracker.zooniverse.org/client.js" charset="utf-8"></script>
<!--<script src="http://tracker.zooniverse.org/socket.io/socket.io.js" charset="utf-8"></script>
<script src="http://tracker.zooniverse.org/client.js" charset="utf-8"></script>-->
</body>
</html>
6 changes: 3 additions & 3 deletions public/translations/pl_pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
},
"home": {
"heading": "Witaj w Snapshot Serengeti",
"content": "Setki ukrytych kamer rozmieszczonych w Parku Narodowym Serengeti w Tanzanii\nzapewniają wgląd w dynamikę najbardziej nieuchwytnych\ndzikich gatunków zwierząt w Afryce.\nPotrzebujemy Twojej pomocy w klasyfikowaniu różnych zwierząt uchwyconych\nna milionach zdjęć z ukrytych kamer."
"content": "Setki ukrytych kamer rozmieszczonych w Parku Narodowym Serengeti w Tanzanii\nzapewniają wgląd w dynamikę najbardziej nieuchwytnych\ndzikich gatunków zwierząt w Afryce.\nPotrzebujemy Twojej pomocy w klasyfikowaniu różnych zwierząt uchwyconych\nna milionach zdjęć z ukrytych kamer.",
"currentStatus": "<span class=\"classification-count\">0</span> klasyfikacji dokonało <span class=\"user-count\">0</span> ochotników",
"action": "Rozpocznij klasyfikowanie"
},
"action": "Rozpocznij klasyfikowanie",
"currentStatus": "<span class=\"classification-count\">0</span> klasyfikacji dokonało <span class=\"user-count\">0</span> ochotników",
"classify": {
"deleteAnnotation": "Usuń",
"notSignedIn": "Zaloguj się!",
Expand Down

0 comments on commit d3e9540

Please sign in to comment.