Skip to content

Commit

Permalink
add switch language button
Browse files Browse the repository at this point in the history
  • Loading branch information
vanadar committed May 19, 2014
1 parent 1f52094 commit 09b5f3a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
17 changes: 14 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/CreativeWork">
<head>
<meta charset="UTF-8"/>
<!--
A Dark Room (v1.4)
==================
Expand Down Expand Up @@ -28,9 +29,19 @@
<script src="lib/translate.js"></script>

<script>
//load language
document.write('<script src="lang/fr/strings.js"><\/script>');
document.write('<link rel="stylesheet" type="text/css" href="lang/fr/main.css" \/>');
// try to read "lang" param's from url
var lang = decodeURIComponent((new RegExp('[?|&]lang=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
// if no language requested, try to read it from local storage
if(!lang){
try {
lang = localStorage.lang;
} catch(e) {}
}
// if a language different than english requested, load all translations
if(lang && lang != 'en'){
document.write('<script src="lang/'+lang+'/strings.js"><\/script>');
document.write('<link rel="stylesheet" type="text/css" href="lang/'+'lang'+'/main.css" \/>');
}
</script>

<script src="script/Button.js"></script>
Expand Down
29 changes: 28 additions & 1 deletion script/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ var Engine = {
.addClass('menu')
.appendTo('body');

$('<select>')
.addClass('menuBtn')
.append($('<option>').text("choose your language"))
.append($('<option>').text("English").val("en"))
.append($('<option>').text("Français").val("fr"))
.change(Engine.switchLanguage)
.appendTo(menu);

$('<span>')
.addClass('lightsOff menuBtn')
.text(_('lights off.'))
Expand Down Expand Up @@ -137,7 +145,9 @@ var Engine = {
.addClass('menuBtn')
.text(_('app store.'))
.click(function() { window.open('https://itunes.apple.com/us/app/a-dark-room/id736683061'); })
.appendTo(menu);
.appendTo(menu);



// Register keypress handlers
$('body').off('keydown').keydown(Engine.keyDown);
Expand Down Expand Up @@ -168,6 +178,7 @@ var Engine = {
Ship.init();
}

Engine.saveLanguage();
Engine.travelTo(Room);

},
Expand Down Expand Up @@ -580,6 +591,22 @@ var Engine = {

handleStateUpdates: function(e){

},

switchLanguage: function(dom){
var lang = $(this).val();
if(document.location.href.search(/[\?\&]lang=[a-z]+/) != -1){
document.location.href = document.location.href.replace( /([\?\&]lang=)([a-z]+)/gi , "$1"+lang );
}else{
document.location.href = document.location.href + ( (document.location.href.search(/\?/) != -1 )?"&":"?") + "lang="+lang;
}
},

saveLanguage: function(){
var lang = decodeURIComponent((new RegExp('[?|&]lang=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
if(lang && typeof Storage != 'undefined' && localStorage) {
localStorage.lang = lang;
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions script/localization.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(function(){
//only used for poedit to find translatable strings
var keywords = [ _('saved.'), _('wood'),_('builder'),_('teeth'),_('meat'),_('fur'), _('alien alloy'), _('bullets'),
_('charm'),_('leather'),_('iron'), _('steel'), _('coal'), _('enegy cell')
_('charm'),_('leather'),_('iron'), _('steel'), _('coal'), _('enegy cell'),
_('torch'),_('medicine'),_('hunter'),_('trapper'),_('tanner'),
_("charcutier"),_('iron miner'),_('coal miner'), _('sulphur miner'), _('armourer'),
_('steelworker'),_('bait'),_('cured meat'), _('scales'), _('compass'), _('laser rifle'),
_('gatherer'),_('cloth'), _('scales'), _('cured meat'), _('thieves'),
_('not enough fur'), _('not enough wood'), _('not enough coal'), _('not enough iron'), _('not enough steel'), _('baited trap'),
_('not enough scales'), _('not enough teeth'), _('not enough leather'),
_('not enough scales'), _('not enough teeth'), _('not enough leather'),
_('the compass points east.'), _('the compass points west.'), _('the compass points north.'), _('the compass points south.'),
_('the compass points northeast.'), _('the compass points northwest.'), _('the compass points southeast.'), _('the compass points southwest.')];
delete keywords;
Expand Down

0 comments on commit 09b5f3a

Please sign in to comment.