Commit 6ee5b423 authored by alexandre's avatar alexandre

Proto langage switching working

parent b251bd7b
;
window.W = window.W || {};
W.lang = W.lang || {};
W.lang.fr = {
}
......@@ -6,6 +6,12 @@ window.W = window.W || {};
(function(undefined) {
'use strict';
function setCookie(key, value) {
var expires = new Date();
expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000));
document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
}
// This is for Django to allow POSTing forms
// using jQuery
function getCookie(name) {
......@@ -44,5 +50,17 @@ window.W = window.W || {};
Backbone.Relational.store.addModelScope(W);
W.config = W.config || {};
var lang = getCookie("lang");
if (!lang) {
lang = window.navigator.userLanguage || window.navigator.language;
lang = lang.substring(0,2)
}
W.config.lang = lang;
var scoreApp = W.ScoreApp.start();
})();
......@@ -33,40 +33,14 @@ window.W = window.W || {};
}
});
// // Dictionnaires
// window.W = window.W || {};
// W.lang = W.lang || {};
// W.lang = {
// "fr": {
// "Bienvenue": "Bienvenue",
// "Axe": "axe",
// "Condition": "condition",
// "Terme": "terme",
// "Adresse": "adresse",
// },
// "en": {
// "Bienvenue": "Welcome",
// "Axe": "axis",
// "Condition": "condition",
// "Terme": "term",
// "Adresse": "address"
// },
// };
// Récupérer la langue du navigateur
var userLanguage = navigator.language;
// var userLanguage = "en";
W.translate = window.t = function (string) {
if (!(userLanguage in W.lang)) {
console.log(userLanguage + " n'est pas une langue defini. On passe en anglais");
userLanguage = "en"
console.log("translating");
if (!(W.config.lang in W.lang)) {
console.log(W.config.lang + " n'est pas une langue defini. On passe en anglais");
W.config.lang = "fr"
};
var entries = W.lang[userLanguage];
var entries = W.lang[W.config.lang];
if (string in entries) {
return entries[string];
......@@ -1726,6 +1700,7 @@ window.W = window.W || {};
'login': '.btn-login',
'logout': '.btn-logout',
'register': '.btn-register',
'lang': '.btn-lang',
},
triggers: {
......@@ -1735,6 +1710,7 @@ window.W = window.W || {};
'click @ui.login': 'show:login',
'click @ui.logout': 'show:logout',
'click @ui.register': 'show:register',
'click @ui.lang': 'switch:language',
},
initialize: function () {
......@@ -1787,7 +1763,8 @@ window.W = window.W || {};
'show:login': 'showLogin',
'show:register': 'showRegister',
'show:logout': 'showLogout',
'hide:modal': 'hideModal'
'hide:modal': 'hideModal',
'switch:language': 'switchLanguage'
},
onRender: function () {
......@@ -1795,6 +1772,21 @@ window.W = window.W || {};
this.showChildView('help', new W.helpView());
},
switchLanguage: function (view, event) {
console.log("switching language");
W.config.lang = $(event.currentTarget).attr("data-lang");
console.log(this.getRegions());
_.each(this.getRegions(), function(element, index, list) {
console.log(element);
var currentView = element.currentView;
if (currentView) { currentView.render(); }
});
// Backbone.history.navigate(Backbone.history.fragment, true);
// Backbone.history.stop();
// Backbone.history.start();
},
showLogin: function(event) {
this.showChildView('modal', new W.LoginView({model: this.model}));
},
......
......@@ -127,6 +127,7 @@
<script src="{% static 'playground/vendors/jquery-ui.min.js' %}"></script>
<script src="{% static 'playground/vendors/jquery.mjs.nestedSortable.js' %}"></script>
<script src="{% static 'playground/js/fr.js' %}"></script>
<script src="{% static 'playground/js/en.js' %}"></script>
<script src="{% static 'playground/js/extendedTemplate.js' %}"></script>
<script src="{% static 'playground/js/models.js' %}"></script>
......
......@@ -23,6 +23,8 @@
<li><a href="#" class="btn-login"><%- t('Se connecter') %></a></li>
<li><a href="#" class="btn-register"><%- t('S\'inscrire') %></a></li>
<% } %>
<li><a href="#" class="btn-lang" data-lang="en">en</a></li>
<li><a href="#" class="btn-lang" data-lang="fr">fr</a></li>
</ul>
</nav>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment