Added lang selector.

This commit is contained in:
Oscar Rezo 2016-11-07 16:11:32 +01:00
commit b5b3b901d0
3 changed files with 51 additions and 5 deletions

View File

@ -91,6 +91,15 @@ let Header = React.createClass({
);
},
getLangSelector() {
return (
<li>
<button className="btn btn-sm btn-default" onClick={setCookie("sitelang", "fr", 30)}>{getLangText('Lang Label FR')}</button>
<button className="btn btn-sm btn-default" onClick={setCookie("sitelang", "en-US", 30)}>{getLangText('Lang Label EN')}</button>
</li>
);
},
onMenuItemClick() {
/*
This is a hack to make the dropdown close after clicking on an item
@ -217,6 +226,7 @@ let Header = React.createClass({
<HeaderNotificationDebug show={false} />
{account}
{signup}
{this.getLangSelector()}
</Nav>
<HeaderNotifications currentUser={currentUser} />
{navRoutesLinks}

View File

@ -230,7 +230,9 @@ const languages = {
'Welcome to ascribe': 'Welcome to ascribe',
'CREATE EDITIONS': 'CREATE EDITIONS',
'Remove Piece': 'Remove Piece',
'Admin email': 'admin@bokk.io'
'Admin email': 'admin@bokk.io',
'Lang Label FR': 'FR',
'Lang Label EN': 'EN'
},
'de': {
'ID': 'ID',
@ -461,7 +463,9 @@ const languages = {
'Welcome to ascribe': 'Welcome to ascribe',
'CREATE EDITIONS': 'CREATE EDITIONS',
'Remove Piece': 'Remove Piece',
'Admin email': 'admin@bokk.io'
'Admin email': 'admin@bokk.io',
'Lang Label FR': 'FR',
'Lang Label EN': 'EN'
},
'fr': {
'ID': 'ID',
@ -692,7 +696,9 @@ const languages = {
'Welcome to ascribe': 'Welcome to ascribe',
'CREATE EDITIONS': 'CREATE EDITIONS',
'Remove Piece': 'Remove Piece',
'Admin email': 'admin@bokk.io'
'Admin email': 'admin@bokk.io',
'Lang Label FR': 'FR',
'Lang Label EN': 'EN'
}
};

View File

@ -8,8 +8,38 @@ import { formatText } from './general_utils';
export function getLang() {
// this is just for testing, as changing the navigator.language wasn't possible
// return 'fr';
return navigator.languages ? navigator.languages[0] :
(navigator.language || navigator.userLanguage);
//return navigator.languages ? navigator.languages[0] :
// (navigator.language || navigator.userLanguage);
var siteLang=getCookie("sitelang");
if (siteLang != "") {
return siteLang;
} else {
return 'fr';
}
}
export function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
export function setCookie(cname,cvalue,exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
location.reload();
}
/**