Skip to content

Commit

Permalink
Merge pull request #1022 from NatLibFi/issue1019-fix-change-content-l…
Browse files Browse the repository at this point in the history
…anguage-url

Update twig + fix #1019 change content language url
  • Loading branch information
osma committed Mar 11, 2021
2 parents b4ce95c + b0f4bfe commit c1a339b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 19 deletions.
1 change: 1 addition & 0 deletions controller/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public function invokeVocabularyConcept(Request $request)
echo $template->render(array(
'search_results' => $results,
'vocab' => $vocab,
'concept_uri' => $uri,
'languages' => $this->languages,
'explicit_langcodes' => $langcodes,
'bread_crumbs' => $crumbs['breadcrumbs'],
Expand Down
9 changes: 0 additions & 9 deletions resource/js/docready.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,6 @@ $(function() { // DOCUMENT READY

// Setting the language parameters according to the clang parameter or if that's not possible the cookie.
var search_lang = (content_lang !== '' && !getUrlParams().anylang && vocab !== '') ? content_lang : readCookie('SKOSMOS_SEARCH_LANG');
if (vocab === '' && readCookie('SKOSMOS_SEARCH_LANG') === 'anything') {
$('#all-languages-true').click();
}

var rest_url = rest_base_url;
if (rest_url.indexOf('..') === -1 && rest_url.indexOf('http') === -1) { rest_url = encodeURI(location.protocol + '//' + rest_url); }
Expand All @@ -585,10 +582,6 @@ $(function() { // DOCUMENT READY
if (!langPretty) { langPretty = $('.lang-button-all').html(); }
$('#lang-dropdown-toggle').html(langPretty + ' <span class="caret"></span>');
qlang = lang;
} else {
langPretty = $('a[hreflang=' + search_lang + ']').html();
if (!langPretty) { langPretty = $('a[hreflang=""]').html(); }
$('#lang-dropdown-toggle').html(langPretty + ' <span class="caret"></span>');
}

var search_lang_possible = false;
Expand All @@ -605,11 +598,9 @@ $(function() { // DOCUMENT READY

$('.lang-button').click(function() {
qlang = $(this)[0].attributes.hreflang ? $(this)[0].attributes.hreflang.value : 'anything';
var any = (qlang === 'anything') ? '1' : '0';
$('#lang-dropdown-toggle').html($(this).html() + ' <span class="caret"></span>');
$('#lang-input').val(qlang);
createCookie('SKOSMOS_SEARCH_LANG', qlang, 365);
createCookie('SKOSMOS_ANYLANG', any, 365);
if (concepts) { concepts.clear(); }
});

Expand Down
52 changes: 44 additions & 8 deletions view/headerbar.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,58 @@
<div class="input-group">
<div class="input-group-btn">
<label class="sr-only" for="lang-dropdown-toggle">{% trans "Content and search language" %}</label>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" id="lang-dropdown-toggle">{{ request.lang | lang_name(request.lang) }}</button>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" id="lang-dropdown-toggle">{{ (request.contentLang ? request.contentLang : request.lang) | lang_name(request.lang) }} <span class="caret"></span></button>
<ul class="dropdown-menu">
{% if request.vocab %}
{% for langcode in request.vocab.config.languages %}
<li><a href="{{ request.uri | link_url(request.vocabid,request.lang,request.page,langcode,term,letter) }}" class="lang-button" hreflang="{{ langcode }}">{{ langcode | lang_name(request.lang) }}</a></li>
<li><a href="{{ concept_uri | link_url(request.vocabid,request.lang,request.page,langcode,term,letter) }}" class="lang-button" hreflang="{{ langcode }}">{{ langcode | lang_name(request.lang) }}</a></li>
{% endfor %}
{% else %}
{% for langcode in lang_list %}
<li><a href="{{ request.lang }}/{{ request.page }}?clang={{langcode}}{% if term %}&q={{ term }}{% endif %}{% if vocabs %}&vocabs={{ vocabs }}{% endif %}" class="lang-button" hreflang="{{ langcode }}">{{ langcode | lang_name(request.lang) }}</a></li>
<li><a href="{{ request.lang }}/{{ request.page -}}
{%- if langcode != request.lang -%}
?clang={{langcode}}
{%- set paramSeparator = '&' -%}
{%- endif %}
{%- if term %}{{ paramSeparator }}q={{ term }}{% set paramSeparor = '&' %}{% endif -%}
{%- if vocabs %}{{ paramSepartor }}vocabs={{ vocabs }}{% endif -%}
" class="lang-button" hreflang="{{ langcode }}">{{ langcode | lang_name(request.lang) }}</a></li>
{% endfor %}
{% endif %}
<li><a href="{% if not request.vocab %}{{ request.lang }}/{% endif %}{% if request.vocabid %}{{ request.vocabid }}/{{ request.lang }}/{% endif %}{% if request.page and request.page != 'vocab' %}{{ request.page }}/{% endif%}?{% if request.uri %}uri={{ request.uri }}&{% endif %}clang={% if request.contentLang %}{{ request.contentLang }}{% else %}{{ request.lang }}{% endif %}&anylang=on{% if term %}&q={{ term }}{% endif %}{% if vocabs %}&vocabs={{ vocabs }}{% endif %}" class="lang-button lang-button-all">{% trans "Search language: any" %}</a><input name="anylang" type="checkbox"{% if request.queryparam('anylang') %} checked{% endif%}></li>
<li>
<a href="
{%- if not request.vocab -%}
{{ request.lang }}/
{%- endif -%}
{%- if request.vocabid -%}
{{ request.vocabid }}/{{ request.lang }}/
{%- endif -%}
{%- set paramSeparator = '?' -%}
{%- set uriSet = false -%}
{%- if request.page and request.page != 'vocab' -%}
{{ request.page }}/
{%- if request.page == 'page' and request.uri != concept_uri -%}
{{- request.uri -}}
{%- set uriSet = true -%}
{% endif %}
{%- endif -%}
{%- if not uriSet and request.uri -%}
?uri={{ request.uri }}
{%- set paramSeparator = '&' -%}
{%- endif -%}
{{- paramSeparator }}clang={{ request.contentLang ? request.contentLang : request.lang -}}
{%- set paramSeparator = '&' -%}
{{- paramSeparator }}anylang=on
{%- if term %}&q={{ term }}{% endif -%}
{%- if vocabs %}&vocabs={{ vocabs }}{% endif -%}
"
class="lang-button lang-button-all">
{%- trans "Search language: any" -%}
</a>
<input name="anylang" type="checkbox"
{%- if request.queryparam('anylang') or (not request.vocab and 'SKOSMOS_SEARCH_LANG=anything' in request.serverConstant('HTTP_COOKIE')) %} checked{% endif -%}
>
</li>
</ul>
</div><!-- /btn-group -->
<label class="sr-only" for="search-field">{% trans "Enter search term" %}</label>
Expand All @@ -44,10 +84,6 @@
<button id="search-all-button" type="submit" class="btn btn-primary">{% trans "Search" %}</button>
</div>
</div>
<div id="search-from-all-vocabularies-radio-buttons">
<input type="radio" id="all-languages-true" name="anylang" value="on"
onClick="createCookie('SKOSMOS_SEARCH_ALL', this.value , 365);" />
</div>
{% if request.page == '' or request.page == 'search' %}<input id="selected-vocabs" type="text" name="vocabs">{% endif %}
</form>
{% endif %}
Expand Down
18 changes: 17 additions & 1 deletion view/topbar.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
<div id="topbar-service-helper">
<a {% if request.vocabid == '' and request.page != 'feedback' and request.page != 'about' %}id="service-logo"{% endif %} {% if request.vocabid != '' or request.page == 'feedback' or request.page == 'about' %}class="service-{{ request.lang }}" {% endif %}href="{{ request.lang }}/{% if request.contentLang != request.lang %}?clang={{ request.contentLang }}{% endif %}{% if request.queryParam('anylang') == 'on' %}{% if request.contentLang == request.lang %}?{% else %}&{% endif %}anylang=on{% endif %}"><h1 id="service-name">{% if ServiceName is defined %}{{ ServiceName }}{% else %}Skosmos{% endif %}</h1></a>
<a
{% if request.vocabid == '' and request.page != 'feedback' and request.page != 'about' %}
id="service-logo"
{% endif %}
{% if request.vocabid != '' or request.page == 'feedback' or request.page == 'about' %}
class="service-{{ request.lang }}"
{% endif %}
href="{{ request.lang }}/
{%- set qClang = request.contentLang and request.contentLang != request.lang -%}
{%- if qClang -%}
?clang={{ request.contentLang }}
{%- endif -%}
{%- if request.queryParam('anylang') == 'on' %}
{{- qClang ? '&' : '?' -}}
anylang=on
{%- endif -%}
"><h1 id="service-name">{% if ServiceName is defined %}{{ ServiceName }}{% else %}Skosmos{% endif %}</h1></a>
</div>
<div id="topbar-language-navigation">
{% if LanguageDropdown %}
Expand Down
2 changes: 1 addition & 1 deletion view/vocabularylist.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<h3>{{ vocabClassName|upper }}</h3>
<ul>
{% for vocab in vocabArray %}
<li><a class="navigation-font" href="{{ vocab.id }}/{{ request.lang }}/{% if request.contentLang != request.lang and request.contentLang != '' %}?clang={{ request.contentLang }}{% endif %}">{{ vocab.title }}</a></li>
<li><a class="navigation-font" href="{{ vocab.id }}/{{ request.lang }}/{% if request.contentLang != request.lang and request.contentLang != '' and request.contentLang in vocab.config.languages %}?clang={{ request.contentLang }}{% endif %}">{{ vocab.title }}</a></li>
{% endfor %}
</ul>
</div>
Expand Down

0 comments on commit c1a339b

Please sign in to comment.