diff --git a/opac/webapp/config/lang_names.py b/opac/webapp/config/lang_names.py index eb1a64c94..50ecb5b34 100644 --- a/opac/webapp/config/lang_names.py +++ b/opac/webapp/config/lang_names.py @@ -194,15 +194,178 @@ } +LANGS_FALLBACK = { + "pt_BR": { + "de": "Alemão", + "fr": "Francês", + "ru": "Russo", + "zh": "Chinês", + "zh-Hans": "Chinês", + "zh-Hant": "Chinês", + "it": "Italiano", + "en": "Inglês", + "pt": "Português", + "es": "Espanhol", + "af": "Afrikaans", # às vezes "Africâner" + "nso": "Lamnso", + "ar": "Árabe", + "eu": "Basco/Eusquera", + "bg": "Búlgaro", + "ca": "Catalão", + "cs": "Tcheco", + "da": "Dinamarquês", + "nl": "Neerlandês/Holandês", + "eo": "Esperanto", + "gl": "Galego", + "gr": "Grego", # considere usar "el" + "he": "Hebraico", + "hi": "Hindi", + "hu": "Húngaro", + "in": "Indonésio", # considere usar "id" + "ia": "Interlíngua", + "ie": "Interlíngue", + "ja": "Japonês", + "ko": "Coreano", + "la": "Latim", + "no": "Norueguês", + "pl": "Polonês", + "ro": "Romeno", + "sa": "Sânscrito", + "sh": "Servo-croata", + "sk": "Eslovaco", + "sn": "Esloveno", + "sv": "Sueco", + "tr": "Turco", + "uk": "Ucraniano", + "ur": "Urdu", + "zz": "Outro", + # opcionais ISO modernos (espelho de chaves alternativas) + "el": "Grego", # alternativo a "gr" + "id": "Indonésio", # alternativo a "in" + "nb": "Norueguês (Bokmål)", + "nn": "Norueguês (Nynorsk)", + "sr": "Sérvio", + "hr": "Croata", + "bs": "Bósnio", + }, + "en": { + "de": "German", + "fr": "French", + "ru": "Russian", + "zh": "Chinese", + "zh-Hans": "Chinese", + "zh-Hant": "Chinese", + "it": "Italian", + "en": "English", + "pt": "Portuguese", + "es": "Spanish", + "af": "Afrikaans", + "nso": "Lamnso", + "ar": "Arabic", + "eu": "Basque", + "bg": "Bulgarian", + "ca": "Catalan", + "cs": "Czech", + "da": "Danish", + "nl": "Dutch", + "eo": "Esperanto", + "gl": "Galician", + "gr": "Greek", # consider "el" + "he": "Hebrew", + "hi": "Hindi", + "hu": "Hungarian", + "in": "Indonesian", # consider "id" + "ia": "Interlingua", + "ie": "Interlingue", + "ja": "Japanese", + "ko": "Korean", + "la": "Latin", + "no": "Norwegian", + "pl": "Polish", + "ro": "Romanian", + "sa": "Sanskrit", + "sh": "Serbo-Croat", + "sk": "Slovak", + "sn": "Slovenian", + "sv": "Swedish", + "tr": "Turkish", + "uk": "Ukrainian", + "ur": "Urdu", + "zz": "Other", + "el": "Greek", # mirror for "gr" + "id": "Indonesian", # mirror for "in" + "nb": "Norwegian (Bokmål)", + "nn": "Norwegian (Nynorsk)", + "sr": "Serbian", + "hr": "Croatian", + "bs": "Bosnian", + }, + "es": { + "de": "Alemán", + "fr": "Francés", + "ru": "Ruso", + "zh": "Chino", + "zh-Hans": "Chino", + "zh-Hant": "Chino", + "it": "Italiano", + "en": "Inglés", + "pt": "Portugués", + "es": "Español", + "af": "Afrikaans", + "nso": "Lamnso", + "ar": "Árabe", + "eu": "Vasco/Euskera", + "bg": "Búlgaro", + "ca": "Catalán", + "cs": "Checo", + "da": "Danés", + "nl": "Neerlandés/Holandés", + "eo": "Esperanto", + "gl": "Gallego", + "gr": "Griego", # considere usar "el" + "he": "Hebreo", + "hi": "Hindi", + "hu": "Húngaro", + "in": "Indonesio", # considere "id" + "ia": "Interlingua", + "ie": "Interlingue", + "ja": "Japonés", + "ko": "Coreano", + "la": "Latín", + "no": "Noruego", + "pl": "Polaco", + "ro": "Rumano", + "sa": "Sánscrito", + "sh": "Serbocroata", + "sk": "Eslovaco", + "sn": "Esloveno", + "sv": "Sueco", + "tr": "Turco", + "uk": "Ucraniano", + "ur": "Urdu", + "zz": "Otro", + # espejos ISO modernos + "el": "Griego", # espejo de "gr" + "id": "Indonesio", # espejo de "in" + "nb": "Noruego (Bokmål)", + "nn": "Noruego (Nynorsk)", + "sr": "Serbio", + "hr": "Croata", + "bs": "Bosnio", + }, +} + + +LANGS_FALLBACK_NORMALIZED = { + str(locale).lower(): {str(k).lower(): v for k, v in mapping.items()} + for locale, mapping in LANGS_FALLBACK.items() +} + def get_original_lang_name(code): return LANG_NAMES.get(code, (None, code))[0] - -def display_original_lang_name(code): - name = get_original_lang_name(code) - if name is None: - return code - name = name.capitalize() - if "," in name: - return name.split(",")[0] - return name +def display_lang_name_fallback(locale, code): + locale_key = str(locale).lower() if locale is not None else "" + code_key = str(code).lower() if code is not None else "" + lang = LANGS_FALLBACK_NORMALIZED.get(locale_key, {}).get(code_key) + return lang or code diff --git a/opac/webapp/controllers.py b/opac/webapp/controllers.py index 481b397ad..74fb1137f 100644 --- a/opac/webapp/controllers.py +++ b/opac/webapp/controllers.py @@ -1748,6 +1748,12 @@ def get_page_by_slug_name(slug_name, lang=None, is_draft=False): return Pages.objects(language=lang, slug_name=slug_name, is_draft=is_draft).first() +def get_page_about_root(lang, is_draft=False): + return Pages.objects(language=lang, journal="", is_draft=is_draft, parent_page=None, page_type__ne="free") + +def get_free_page_by_slug(slug, lang, is_draft=False): + return Pages.objects(slug_name=slug, is_draft=is_draft, page_type="free", language=lang).first() + def related_links(article): expr = [] if article.title or article.section: diff --git a/opac/webapp/main/views.py b/opac/webapp/main/views.py index 022827a60..d17b85614 100644 --- a/opac/webapp/main/views.py +++ b/opac/webapp/main/views.py @@ -33,7 +33,7 @@ from webapp import babel, cache, controllers, forms from webapp.choices import STUDY_AREAS from webapp.controllers import create_press_release_record -from webapp.config.lang_names import display_original_lang_name +from webapp.config.lang_names import display_lang_name_fallback from webapp.utils import utils from webapp.utils.caching import cache_key_with_lang, cache_key_with_lang_with_qs from webapp.main.errors import page_not_found, internal_server_error @@ -323,28 +323,44 @@ def collection_list_feed(): return feed.get_response() + +@main.route("/about/", methods=["GET"]) +def page_about_detail(slug_name): + language = session.get("lang", get_locale()) + page = controllers.get_page_by_slug_name(slug_name, lang=language, is_draft=False) + + if not page: + abort(404, _("Página não encontrada")) + breadcrumbs = utils.build_breadcrumbs(page) + context = { + "breadcrumbs": breadcrumbs, + "page": page, + } + return render_template("collection/about_detail.html", **context) + + @main.route("/about/", methods=["GET"]) -@main.route("/about/", methods=["GET"]) @cache.cached(key_prefix=cache_key_with_lang_with_qs) -def about_collection(slug_name=None): +def about_collection(): language = session.get("lang", get_locale()) context = {} - page = None - if slug_name: - # caso seja uma página - page = controllers.get_page_by_slug_name(slug_name, language) - if not page: - abort(404, _("Página não encontrada")) - context["page"] = page - else: - # caso não seja uma página é uma lista - pages = controllers.get_pages_by_lang(language) - context["pages"] = pages + pages = controllers.get_page_about_root(language) + context["pages"] = pages.order_by("order") return render_template("collection/about.html", **context) +@main.route("/free/", methods=["GET"]) +def free_page(slug_name): + language = session.get("lang", get_locale()) + page = controllers.get_free_page_by_slug(slug_name, lang=language, is_draft=False) + + if not page: + abort(404, _("Página não encontrada")) + + return render_template("collection/about_detail.html", page=page) + # ###################################Journal##################################### @@ -1281,12 +1297,13 @@ def _handle_html(): logger.exception(exc) abort(500, _("Erro inesperado")) + language = session.get("lang", get_locale()) text_versions = sorted( [ ( lang, - display_original_lang_name(lang), + display_lang_name_fallback(locale=language, code=lang), url_for( "main.article_detail_v3", url_seg=article.journal.url_segment, diff --git a/opac/webapp/templates/article/includes/levelMenu_abstracts.html b/opac/webapp/templates/article/includes/levelMenu_abstracts.html index cf4f1c8b1..d6fbdc80f 100644 --- a/opac/webapp/templates/article/includes/levelMenu_abstracts.html +++ b/opac/webapp/templates/article/includes/levelMenu_abstracts.html @@ -12,7 +12,7 @@ {% elif abstract['language'] == 'pt' %} (PT) {% else %} - {{ abstract['language'] }} + ({{ abstract['language']|upper }}) {% endif %} {% endif %} {% endfor %} diff --git a/opac/webapp/templates/article/includes/levelMenu_pdf.html b/opac/webapp/templates/article/includes/levelMenu_pdf.html index 2f0e4b2ee..9e6d81a35 100644 --- a/opac/webapp/templates/article/includes/levelMenu_pdf.html +++ b/opac/webapp/templates/article/includes/levelMenu_pdf.html @@ -15,7 +15,7 @@ {% elif pdf.lang == 'pt' %} {% trans %}Download PDF (Português){% endtrans %} {% else %} - {{ pdf.lang }} + Download PDF ({{ pdf.lang }}) {% endif %} diff --git a/opac/webapp/templates/article/includes/levelMenu_texts.html b/opac/webapp/templates/article/includes/levelMenu_texts.html index 68450220a..143775495 100644 --- a/opac/webapp/templates/article/includes/levelMenu_texts.html +++ b/opac/webapp/templates/article/includes/levelMenu_texts.html @@ -13,7 +13,7 @@ {% elif lang == 'pt' %} (PT) {% else %} - ({{ text_lang }}) + ({{ text_lang|upper }}) {% endif %} {% endif %} {% endfor %} diff --git a/opac/webapp/templates/collection/about.html b/opac/webapp/templates/collection/about.html index 6e83a29d1..55bf36c1a 100644 --- a/opac/webapp/templates/collection/about.html +++ b/opac/webapp/templates/collection/about.html @@ -6,59 +6,21 @@
- {% if pages %} -

{% trans %}Sobre o SciELO{% endtrans %} {{ coll_macro.get_collection_name() }}

- + {% set nodes = pages %} + {% set ul_class = "networkList" %} + {% include "collection/includes/_page_tree.html" %}
- {% endif %} - - {% if page %} -
-
-

{{ page }}

- - {%- if page.content -%} - {{ page.content|safe }} - {%- else -%} - {% trans %} Conteúdo não cadastrado {% endtrans %} - {%- endif -%} -
-
- - {% with page_updated_at=page.updated_at %} -
-
- {% include "includes/page_updated_at_info.html" %} -
-
- {% endwith %} - - {% endif %} - - {% if page %} - - {% endif %} - + {% endif %}
diff --git a/opac/webapp/templates/collection/about_detail.html b/opac/webapp/templates/collection/about_detail.html new file mode 100644 index 000000000..343ba5b16 --- /dev/null +++ b/opac/webapp/templates/collection/about_detail.html @@ -0,0 +1,60 @@ +{% extends "collection/base.html" %} +{% block level_menu %} + {% include "collection/includes/levelMenu.html" %} +{% endblock %} +{% block main_content %} + +
+
+ + {% if page %} +
+
+

{{ page }}

+ + {%- if page.content -%} + {{ page.content|safe }} + {%- else -%} + {% trans %} Conteúdo não cadastrado {% endtrans %} + {%- endif -%} +
+
+ + {% with page_updated_at=page.updated_at %} +
+
+ {% include "includes/page_updated_at_info.html" %} +
+
+ {% endwith %} + {% if page.get_descendants() or page.get_ancestors() %} +
+

{% trans %} Páginas relacionadas {% endtrans %}

+
    + {% if page.parent_page %} + {% for ancestor in page.get_ancestors() %} +
  • + + {{ ancestor.name }} + +
  • + {% endfor %} + {% endif %} + {% if page.get_descendants() %} + {% for descendant in page.get_descendants() %} +
  • + + {{ descendant.name }} + +
  • + {% endfor %} + {% endif %} +
+
+ {% endif %} + {% endif %} + +
+
+ +{% endblock %} diff --git a/opac/webapp/templates/collection/includes/_page_tree.html b/opac/webapp/templates/collection/includes/_page_tree.html new file mode 100644 index 000000000..a785defba --- /dev/null +++ b/opac/webapp/templates/collection/includes/_page_tree.html @@ -0,0 +1,15 @@ +
    + {% for node in nodes %} +
  • + + {{ node }} + + {% set child_nodes = node.get_children() %} + {% if child_nodes %} + {% set nodes = child_nodes %} + {% set ul_class = "networkList--children" %} + {% include "collection/includes/_page_tree.html" %} + {% endif %} +
  • + {% endfor %} +
\ No newline at end of file diff --git a/opac/webapp/templates/collection/includes/levelMenu.html b/opac/webapp/templates/collection/includes/levelMenu.html index 3531bfbeb..8d1ba9db6 100644 --- a/opac/webapp/templates/collection/includes/levelMenu.html +++ b/opac/webapp/templates/collection/includes/levelMenu.html @@ -12,6 +12,11 @@ @@ -65,6 +70,11 @@ diff --git a/opac/webapp/templates/journal/includes/levelMenu.html b/opac/webapp/templates/journal/includes/levelMenu.html index d133dca6f..bf0c1370f 100644 --- a/opac/webapp/templates/journal/includes/levelMenu.html +++ b/opac/webapp/templates/journal/includes/levelMenu.html @@ -46,11 +46,11 @@ {# Atual #} {% if not next_item and last_issue %} - + {% trans %}Número atual{% endtrans %} {% else %} - + {% trans %}Número atual{% endtrans %} {% endif %} @@ -140,7 +140,7 @@ {# Atual #} {% if last_issue %} - + {% trans %}Atual{% endtrans %} {% endif %} diff --git a/opac/webapp/utils/utils.py b/opac/webapp/utils/utils.py index 830d614d8..af425460d 100644 --- a/opac/webapp/utils/utils.py +++ b/opac/webapp/utils/utils.py @@ -790,3 +790,15 @@ def fetch_and_extract_section(collection_acronym, journal_acronym, language): return extract_section(content, class_name) + +def get_children_in_order(page): + return sorted(page.child_pages or [], key=lambda p: (p.order, p.name.lower())) + + +def build_breadcrumbs(page): + crumbs = [] + current = page + while current.parent_page: + crumbs.insert(0, current.parent_page) + current = current.parent_page + return crumbs