-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I18n: changing to the same page on click - fixes #27
- Loading branch information
1 parent
b8f2888
commit b97fe6a
Showing
3 changed files
with
54 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module I18nHelpers | ||
# https://gist.github.com/johnnyshields/98a695df51b1e99f3593579d3c9a3fd1 | ||
|
||
def current_path_for_locale(loc = I18n.locale, is_link = true) | ||
return 'javascript: void(0);' if is_link && I18n.locale == loc | ||
|
||
url_regex = /\A\/(?:(#{I18n.available_locales.join('|')})\/)?/ | ||
current_page.url.gsub(url_regex, '').blank? ? | ||
home_for_locale(loc) : | ||
current_page.url.gsub(url_regex, root_for_locale(loc)) | ||
end | ||
|
||
def path_for_locale(path, loc = I18n.locale) | ||
root_for_locale(loc) + path | ||
end | ||
|
||
def home_for_locale(loc = I18n.locale) | ||
root_for_locale(loc) | ||
end | ||
|
||
def root_for_locale(loc = I18n.locale) | ||
loc == "en" ? '/' : "/#{loc}/" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
<nav class="main-nav"> | ||
<div class="lang-wrapper"> | ||
<a href="#lang" class="lang-trigger"><%= t(:activeLang) %></a> | ||
<ul id="lang" class="lang" role="menu"> | ||
<li role="menuitem"> | ||
<a href="/">English</a> | ||
</li> | ||
<li role="menuitem"> | ||
<a href="/es">Castellano</a> | ||
</li> | ||
<li role="menuitem"> | ||
<a href="/ca">Català</a> | ||
</li> | ||
</ul> | ||
</div> | ||
<div class="main-nav__links" id="nav-links"> | ||
<a href="<%= t(:path) %>/demo" class="main-nav__item"><%= t(:navDemo) %></a> | ||
<a href="<%= t(:path) %>/community" class="main-nav__item"><%= t(:navCommunity) %></a> | ||
<a href="<%= t(:path) %>/contract"class="main-nav__item"><%= t(:navContract) %></a> | ||
<a href="https://github.com/decidim/decidim" target="_blank" class="main-nav__item"> | ||
<%= t(:navCode) %> | ||
</a> | ||
</div> | ||
<a class="main-nav__trigger" href="#nav-links"> | ||
<span class="nav-icon"></span> | ||
<span class="visually-hidden"><%= t(:navText) %></span> | ||
</a> | ||
<div class="lang-wrapper"> | ||
<a href="#lang" class="lang-trigger"><%= t(:activeLang) %></a> | ||
<ul id="lang" class="lang" role="menu"> | ||
<li role="menuitem"> | ||
<%= link_to "English", current_path_for_locale("en") %> | ||
</li> | ||
<li role="menuitem"> | ||
<%= link_to "Castellano", current_path_for_locale("es") %> | ||
</li> | ||
<li role="menuitem"> | ||
<%= link_to "Català", current_path_for_locale("ca") %> | ||
</li> | ||
</ul> | ||
</div> | ||
<div class="main-nav__links" id="nav-links"> | ||
<a href="<%= t(:path) %>/demo" class="main-nav__item"><%= t(:navDemo) %></a> | ||
<a href="<%= t(:path) %>/community" class="main-nav__item"><%= t(:navCommunity) %></a> | ||
<a href="<%= t(:path) %>/contract"class="main-nav__item"><%= t(:navContract) %></a> | ||
<a href="https://github.com/decidim/decidim" target="_blank" class="main-nav__item"> | ||
<%= t(:navCode) %> | ||
</a> | ||
</div> | ||
<a class="main-nav__trigger" href="#nav-links"> | ||
<span class="nav-icon"></span> | ||
<span class="visually-hidden"><%= t(:navText) %></span> | ||
</a> | ||
</nav> |