mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 00:01:54 +08:00
add switch language button
This commit is contained in:
+14
-3
@@ -1,6 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html itemscope itemtype="http://schema.org/CreativeWork">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<!--
|
||||
A Dark Room (v1.4)
|
||||
==================
|
||||
@@ -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>
|
||||
|
||||
+28
-1
@@ -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.'))
|
||||
@@ -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);
|
||||
@@ -168,6 +178,7 @@ var Engine = {
|
||||
Ship.init();
|
||||
}
|
||||
|
||||
Engine.saveLanguage();
|
||||
Engine.travelTo(Room);
|
||||
|
||||
},
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user