Skip to content

Commit

Permalink
(hopefully) final fix to language cookie problems
Browse files Browse the repository at this point in the history
  • Loading branch information
VascoRatoFCCN committed May 17, 2023
1 parent 8c2d26f commit eb57120
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 32 deletions.
30 changes: 8 additions & 22 deletions framed/static/js/arquivo.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ var ARQUIVO = ARQUIVO || (function(){
* Choose language and load corresponding Constants
*/
loadLanguage: function(){
var language = localStorage.language;
var language = $.cookie('i18n');
if(!!language){
language = language.split('_')[0].toUpperCase();
localStorage.language = language;
}
language = localStorage.language;
language = language == 'EN' ? 'EN' : 'PT';
_language = language.toLowerCase();
document.write('<script type="text/javascript" language="JavaScript" src="'+_static_path+'/properties/Constants'+language+'.js'+_buildUrlSuffix+'"><\/script>');
Expand Down Expand Up @@ -135,7 +140,6 @@ var ARQUIVO = ARQUIVO || (function(){
this.attachPrintModal();
this.iframeResize();
this.createSlideMenu();
this.attachLanguageChange();
this.attachShare();
this.attachTools();
this.attachMoreInfoModal();
Expand Down Expand Up @@ -326,7 +330,7 @@ var ARQUIVO = ARQUIVO || (function(){
'<h4>&nbsp;</h4>'+
'<button href="#" onclick="ARQUIVO.goToContent()" class="close-functions clean-button-no-fill">&#10005;</button>' +
'</div>'+
' <a id="changeLanguage" onclick="ARQUIVO.sendEventToAnalytics(\'ReplayBarFunctions\', \'ChangeLanguageTo'+Content.otherLanguage+'Click\');"><h4><i class="fa fa-flag right-6" aria-hidden="true"></i> '+Content.otherLanguageExtended+'</h4></a>'+
' <a id="changeLanguage" onclick="ARQUIVO.sendEventToAnalytics(\'ReplayBarFunctions\', \'ChangeLanguageTo'+Content.otherLanguage+'Click\');" href="/switchlang?l='+Content.language.toLowerCase()+'"><h4><i class="fa fa-flag right-6" aria-hidden="true"></i> '+Content.otherLanguageExtended+'</h4></a>'+
' <button class="clean-button" onclick="ARQUIVO.copyLink();"><h4><i class="fa fa-link padding-right-menu-icon" aria-hidden="true"></i> '+Content.copyLink+'</h4></button>' +
'<button class="clean-button" id="pagesMenu" onclick="ARQUIVO.pagesClick();"><h4><i class="fa fa-globe padding-right-menu-icon" aria-hidden="true"></i> '+Content.pages+'<i id="pagesCarret" class="fa fa-caret-down iCarret shareCarret pull-right" aria-hidden="true"></i></h4></button>'+
'<div id="pageOptions">'+
Expand Down Expand Up @@ -476,25 +480,7 @@ var ARQUIVO = ARQUIVO || (function(){
'-ms-transform': 'translate(-50%, -50%)'
});
},

attachLanguageChange: function(){
$('#changeLanguage').on('click', function(e){
ARQUIVO.setLang(Content.otherLanguage);
});
},
/*Choose language*/
setLang: function(lang) {
if(lang == 'EN')
{
localStorage.setItem('language', 'EN');
window.location.reload();
}
else //default language Portuguesez
{
localStorage.setItem('language', 'PT');
window.location.reload();
}
},

/**
* Returns current timestamp in short form such as '2 Nov 10:24, 2015'
*/
Expand Down
10 changes: 0 additions & 10 deletions framed/templates/frame_insert_mobile.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
{% set buildUrlSuffix = ( '?build=' + metadata.build ) if metadata.build is defined else '' %}
{# Language cookie must be read from the server since it's an HttpOnly cookie #}
{% set cookieLanguage = [] %}
{% for cookie in env.HTTP_COOKIE.split(';') %}
{% if cookie.split('=')[0].strip() == 'i18n' %}
{% if cookieLanguage.append(cookie.split('=')[1].strip().split('_')[0].upper()) %} {% endif %}
{% endif %}
{% endfor %}
<!DOCTYPE html>
<html>
<head>
Expand Down Expand Up @@ -79,9 +72,6 @@
<!-- Plugin for cookie to choose language-->
<link rel="shortcut icon" href="/img/logo-16.png" type="image/x-icon">
<!-- Arquivo.pt specific functions and js code, such as loading constants, cookies -->
{% if cookieLanguage|length > 0 %}
<script>localStorage.language = "{{ cookieLanguage[0] }}";</script>
{% endif %}
<script src="{{ static_prefix }}/js/arquivo.js{{ buildUrlSuffix }}"></script>
<script src="{{ static_prefix }}/js/replayLeftNav.js{{ buildUrlSuffix }}"></script>
<script type="text/javascript">
Expand Down

0 comments on commit eb57120

Please sign in to comment.