Unverified Commit 217fd3f4 authored by Maarten de Waard's avatar Maarten de Waard 🤘🏻
Browse files

set language cookie when language is changed, try to use language cookie in .htaccess

parent 005a8bba
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^/[^aef].*$ [NC]
# Don't rewrite if English has been chosen
RewriteCond %{HTTP_COOKIE} ^openedx-language-preference=en$ [NC]
RewriteRule ^(.*)$ $1 [L]
RewriteCond %{REQUEST_URI} ^/[^aef].*$ [NC]
# Rewrite to language from cookie
RewriteCond %{HTTP_COOKIE} ^openedx-language-preference=(ar|es|fa|fr)$ [NC]
RewriteRule ^(.*)$ /%1/$1 [L]
# Simple way to exclude /ar, /es, /fa and /fr for now
RewriteCond %{REQUEST_URI} ^/[^aef].*$ [NC]
# Don't rewrite if language has been chosen already
RewriteCond %{HTTP_COOKIE} !^openedx-language-preference.*$ [NC]
# Rewrite non-English supported languages
RewriteCond %{HTTP:Accept-Language} ^.*(ar|es|fa|fr).*$ [NC]
RewriteRule ^(.*)$ /%1/$1 [L]
......
......@@ -55,7 +55,7 @@
});
// Add target="_blank" to external links so they open in new tabs
var siteUrlPattern = "^https?:\/\/(www\.)?(workstation...\.lan:4567|localhost:4567|totem-project\.org)";
var siteUrlPattern = "^https?:\/\/(www\.)?(www-staging.)?(workstation...\.lan:4567|localhost:4567|totem-project\.org)";
var siteUrlMatch = RegExp(siteUrlPattern, "i");
var excludeMatch = /(^mailto:|^tel:|^#|^javascript:)/;
$("a").each(function() {
......@@ -65,7 +65,17 @@
}
});
});
document.setLangCookie = function(lang) {
console.log("Setting lang to " + lang);
var expiryDate = new Date();
expiryDate = expiryDate.setMonth(expiryDate.getMonth() + 12);
var domain = window.location.hostname;
cookieParams = "domain=." + domain + ";path=/;";
if (window.location.protocol == "https") {
cookieParams += "secure=true;"
}
document.cookie = "openedx-language-preference=" + lang + ";expires=" + expiryDate + "; + ";secure=true;path=/";
};
})(jQuery, window, document);
......@@ -35,7 +35,7 @@ end
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<% I18n.available_locales.select{|l| l != ::I18n.locale}.each do |loc| %>
<li class="dropdown-item">
<%= link_to(config[:locales][loc][:name], "/index.html", :locale => loc, :class => "nav-link") %>
<%= link_to(config[:locales][loc][:name], "/index.html", :locale => loc, :class => "nav-link", :onclick => "setLangCookie('#{loc}')") %>
</li>
<% end %>
</ul>
......
Supports Markdown
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