Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
totem
website
Commits
217fd3f4
Unverified
Commit
217fd3f4
authored
Dec 16, 2020
by
Maarten de Waard
🤘🏻
Browse files
set language cookie when language is changed, try to use language cookie in .htaccess
parent
005a8bba
Changes
3
Hide whitespace changes
Inline
Side-by-side
.htaccess
View file @
217fd3f4
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]
...
...
source/javascripts/index.js
View file @
217fd3f4
...
...
@@ -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
);
source/partials/_nav.html.erb
View file @
217fd3f4
...
...
@@ -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>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment