Skip to content

Commit ec4b798

Browse files
authored
Handle no Methodology translation (#3302)
1 parent e170176 commit ec4b798

5 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/server/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .helpers import (
55
get_view_args,
66
chapter_lang_exists,
7+
page_lang_exists,
78
featured_chapters_exists,
89
get_ebook_methodology,
910
add_footnote_links,
@@ -63,6 +64,7 @@ def add_header(response):
6364
# Make these functions available in templates.
6465
app.jinja_env.globals["get_view_args"] = get_view_args
6566
app.jinja_env.globals["chapter_lang_exists"] = chapter_lang_exists
67+
app.jinja_env.globals["page_lang_exists"] = page_lang_exists
6668
app.jinja_env.globals["featured_chapters_exists"] = featured_chapters_exists
6769
app.jinja_env.globals["HTTP_STATUS_CODES"] = HTTP_STATUS_CODES
6870
app.jinja_env.globals["get_ebook_methodology"] = get_ebook_methodology

src/server/helpers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ def chapter_lang_exists(lang, year, chapter):
133133
return False
134134

135135

136+
def page_lang_exists(lang, year, page):
137+
if os.path.isfile(
138+
TEMPLATES_DIR + "/%s/%s/%s.html" % (lang, year, page)
139+
):
140+
return True
141+
else:
142+
return False
143+
144+
136145
def featured_chapters_exists(lang, year):
137146
if os.path.isfile(TEMPLATES_DIR + "/%s/%s/featured_chapters.html" % (lang, year)):
138147
return True

src/server/tests/helpers_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
get_versioned_filename,
44
get_ebook_size_in_mb,
55
chapter_lang_exists,
6+
page_lang_exists,
67
featured_chapters_exists,
78
get_chapter_nextprev,
89
get_chapter_config,
@@ -158,6 +159,14 @@ def test_chapter_lang_not_exists():
158159
assert chapter_lang_exists("en", "2019", "random") is False
159160

160161

162+
def test_page_lang_exists():
163+
assert page_lang_exists("en", "2019", "methodology") is True
164+
165+
166+
def test_page_lang_not_exists():
167+
assert page_lang_exists("en", "2019", "random") is False
168+
169+
161170
def test_featured_chapters_exists():
162171
assert featured_chapters_exists("en", "2019") is True
163172

src/templates/base/base.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,11 @@
337337
</li>
338338
{% else %}
339339
<li class="nav-dropdown-list-chapter">
340+
{% if page_lang_exists(lang, year, 'methodology') %}
340341
<a href="{{ url_for('methodology', year=year, lang=lang) }}">{{ self.methodology_title() }}</a>
342+
{% else %}
343+
<a href="{{ url_for('methodology', year=year, lang='en') }}">{{ self.methodology_title() }} <span class="not-translated">({{ self.translation_not_available() }})</span></a>
344+
{% endif %}
341345
</li>
342346
{% endif %}
343347
{% if request.path.endswith("contributors") %}
@@ -346,7 +350,11 @@
346350
</li>
347351
{% else %}
348352
<li class="nav-dropdown-list-chapter">
353+
{% if page_lang_exists(lang, year, 'contributors') %}
349354
<a href="{{ url_for('contributors', year=year, lang=lang) }}">{{ self.contributors_title() }}</a>
355+
{% else %}
356+
<a href="{{ url_for('contributors', year=year, lang='en') }}">{{ self.contributors_title() }} <span class="not-translated">({{ self.translation_not_available() }})</span></a>
357+
{% endif %}
350358
</li>
351359
{% endif %}
352360

src/templates/base/table_of_contents.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,18 @@ <h2 id="part-{{ part_config.part_number }}" class="part-name"><a href="#part-{{
135135
<h2 id="appendices" class="part-name"><a href="#appendices" class="anchor-link">{{ self.appendices() }}</a></h2>
136136
<div class="chapters">
137137
<div class="chapter">
138+
{% if page_lang_exists(lang, year, 'methodology') %}
138139
<a href="{{ url_for('methodology', year=year, lang=lang) }}">{{ self.methodology_title() }}</a>
140+
{% else %}
141+
<a href="{{ url_for('methodology', year=year, lang='en') }}">{{ self.methodology_title() }} <span class="not-translated">({{ self.translation_not_available() }})</span></a>
142+
{% endif %}
139143
</div>
140144
<div class="chapter">
145+
{% if page_lang_exists(lang, year, 'contributors') %}
141146
<a href="{{ url_for('contributors', year=year, lang=lang) }}">{{ self.contributors_title() }}</a>
147+
{% else %}
148+
<a href="{{ url_for('contributors', year=year, lang='en') }}">{{ self.contributors_title() }} <span class="not-translated">({{ self.translation_not_available() }})</span></a>
149+
{% endif %}
142150
</div>
143151
</div>
144152
</section>

0 commit comments

Comments
 (0)