add switch language button

This commit is contained in:
Vanadar
2014-05-19 11:49:46 +02:00
parent 1f52094384
commit 09b5f3aba1
3 changed files with 44 additions and 6 deletions
+14 -3
View File
@@ -1,6 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html itemscope itemtype="http://schema.org/CreativeWork"> <html itemscope itemtype="http://schema.org/CreativeWork">
<head> <head>
<meta charset="UTF-8"/>
<!-- <!--
A Dark Room (v1.4) A Dark Room (v1.4)
================== ==================
@@ -28,9 +29,19 @@
<script src="lib/translate.js"></script> <script src="lib/translate.js"></script>
<script> <script>
//load language // try to read "lang" param's from url
document.write('<script src="lang/fr/strings.js"><\/script>'); var lang = decodeURIComponent((new RegExp('[?|&]lang=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
document.write('<link rel="stylesheet" type="text/css" href="lang/fr/main.css" \/>'); // 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>
<script src="script/Button.js"></script> <script src="script/Button.js"></script>
+28 -1
View File
@@ -109,6 +109,14 @@ var Engine = {
.addClass('menu') .addClass('menu')
.appendTo('body'); .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>') $('<span>')
.addClass('lightsOff menuBtn') .addClass('lightsOff menuBtn')
.text(_('lights off.')) .text(_('lights off.'))
@@ -137,7 +145,9 @@ var Engine = {
.addClass('menuBtn') .addClass('menuBtn')
.text(_('app store.')) .text(_('app store.'))
.click(function() { window.open('https://itunes.apple.com/us/app/a-dark-room/id736683061'); }) .click(function() { window.open('https://itunes.apple.com/us/app/a-dark-room/id736683061'); })
.appendTo(menu); .appendTo(menu);
// Register keypress handlers // Register keypress handlers
$('body').off('keydown').keydown(Engine.keyDown); $('body').off('keydown').keydown(Engine.keyDown);
@@ -168,6 +178,7 @@ var Engine = {
Ship.init(); Ship.init();
} }
Engine.saveLanguage();
Engine.travelTo(Room); Engine.travelTo(Room);
}, },
@@ -580,6 +591,22 @@ var Engine = {
handleStateUpdates: function(e){ 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;
}
} }
}; };
+2 -2
View File
@@ -1,13 +1,13 @@
(function(){ (function(){
//only used for poedit to find translatable strings //only used for poedit to find translatable strings
var keywords = [ _('saved.'), _('wood'),_('builder'),_('teeth'),_('meat'),_('fur'), _('alien alloy'), _('bullets'), 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'), _('torch'),_('medicine'),_('hunter'),_('trapper'),_('tanner'),
_("charcutier"),_('iron miner'),_('coal miner'), _('sulphur miner'), _('armourer'), _("charcutier"),_('iron miner'),_('coal miner'), _('sulphur miner'), _('armourer'),
_('steelworker'),_('bait'),_('cured meat'), _('scales'), _('compass'), _('laser rifle'), _('steelworker'),_('bait'),_('cured meat'), _('scales'), _('compass'), _('laser rifle'),
_('gatherer'),_('cloth'), _('scales'), _('cured meat'), _('thieves'), _('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 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 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.')]; _('the compass points northeast.'), _('the compass points northwest.'), _('the compass points southeast.'), _('the compass points southwest.')];
delete keywords; delete keywords;