Skip to content

Commit d5bd57b

Browse files
committed
Add link function, adjust sprint translation
1 parent f969d5e commit d5bd57b

3 files changed

Lines changed: 31 additions & 28 deletions

File tree

databags/translate.ini

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ past_events = Past events
7979
upcoming_events = Upcoming events
8080
running_sprint = BeeWare will be running a sprint at
8181
what_is_a_sprint = What is a Sprint?
82-
sprint_description = Code sprints are events held normally after a conference where attendees can use the conference venue to work in small groups on various projects. Learn more about how sprints work with the
83-
sprint_pycon_video = PyCon US 'What is a sprint?' video
82+
sprint_description = Code sprints are events held normally after a conference where attendees can use the conference venue to work in small groups on various projects. Learn more about how sprints work with the {{ pycon_link("PyCon US 'What is a sprint?' video") }}.
8483
challenge_coin = Challenge Coin
8584
date = Date
8685
speakers = Speakers
@@ -209,9 +208,8 @@ past_events = الأحداث السابقة
209208
upcoming_events = الأحداث القادمة
210209
running_sprint = BeeWare سيقوم بتشغيل سبرينت في
211210
what_is_a_sprint = ما هو سبرينت؟
212-
sprint_description = كود سبرينت هي أحداث تعقد عادة بعد مؤتمر حيث يمكن للحاضرين استخدام مكان المؤتمر للعمل في مجموعات صغيرة في مشاريع مختلفة. اعرف المزيد عن كيفية عمل سبرينت مع
213-
sprint_pycon_video = PyCon US 'ما هو سبرينت?' فيديو
214-
challenge_coin = عملة التحدي
211+
sprint_description = كود سبرينت هي أحداث تعقد عادة بعد مؤتمر حيث يمكن للحاضرين استخدام مكان المؤتمر للعمل في مجموعات صغيرة في مشاريع مختلفة. اعرف المزيد عن كيفية عمل سبرينت مع {{ pycon_link("PyCon US 'ما هو سبرينت?' فيديو") }}
212+
challenge_coin =
215213
date = تاريخ
216214
speakers = المتحدثون
217215
sprinters = سبرينترز
@@ -321,8 +319,7 @@ past_events = Eventos anteriores
321319
upcoming_events = Próximos eventos
322320
running_sprint = BeeWare fará um sprint em
323321
what_is_a_sprint = O que é um Sprint?
324-
sprint_description = Sprints de código são eventos, realizados normalmente após conferências, onde os participantes podem usar o local da conferência para trabalhar em grupos pequenos em vários projetos. Saiba mais como funcionam os sprints com o
325-
sprint_pycon_video = vídeo da PyCon US 'What is a sprint?'
322+
sprint_description = Sprints de código são eventos, realizados normalmente após conferências, onde os participantes podem usar o local da conferência para trabalhar em grupos pequenos em vários projetos. Saiba mais como funcionam os sprints com o {{ pycon_link("vídeo da PyCon US 'What is a sprint?'" }}.
326323
challenge_coin = Challenge Coin
327324
date = Data
328325
speakers = Palestrantes
@@ -433,8 +430,7 @@ past_events = Past events
433430
upcoming_events = Upcoming events
434431
running_sprint = BeeWare will be running a sprint at
435432
what_is_a_sprint = What is a Sprint?
436-
sprint_description = Code sprints are events held normally after a conference where attendees can use the conference venue to work in small groups on various projects. Learn more about how sprints work with the
437-
sprint_pycon_video = PyCon US 'What is a sprint?' video
433+
sprint_description = Code sprints are events held normally after a conference where attendees can use the conference venue to work in small groups on various projects. Learn more about how sprints work with the {{ pycon_link("PyCon US 'What is a sprint?' video") }}.
438434
challenge_coin = Challenge Coin
439435
date = Date
440436
speakers = Speakers
@@ -545,8 +541,7 @@ past_events = Eventos pasados
545541
upcoming_events = Eventos futuros
546542
running_sprint = BeeWare va a realizar un sprint en
547543
what_is_a_sprint = ¿Qué es un sprint?
548-
sprint_description = Los sprints de código son eventos que se llevan a cabo normalmente después de una conferencia donde los asistentes pueden usar el lugar de la conferencia para trabajar en grupos pequeños en varios proyectos. Para obtener más información sobre cómo funcionan los sprints mira
549-
sprint_pycon_video = el video de PyCon USA 'What is a sprint?'
544+
sprint_description = Los sprints de código son eventos que se llevan a cabo normalmente después de una conferencia donde los asistentes pueden usar el lugar de la conferencia para trabajar en grupos pequeños en varios proyectos. Para obtener más información sobre cómo funcionan los sprints mira {{ pycon_link("el video de PyCon USA 'What is a sprint?'" }}.
550545
challenge_coin = Moneda de desafío
551546
date = Fecha
552547
speakers = Conferencistas
@@ -657,8 +652,7 @@ past_events = Evénements passés
657652
upcoming_events = Evénements à venir
658653
running_sprint = BeeWare will be running a sprint at
659654
what_is_a_sprint = What is a Sprint?
660-
sprint_description = Code sprints are events held normally after a conference where attendees can use the conference venue to work in small groups on various projects. Learn more about how sprints work with the
661-
sprint_pycon_video = PyCon US 'What is a sprint?' video
655+
sprint_description = Code sprints are events held normally after a conference where attendees can use the conference venue to work in small groups on various projects. Learn more about how sprints work with the {{ pycon_link("PyCon US 'What is a sprint?' video") }}.
662656
challenge_coin = Challenge Coin
663657
date = Date
664658
speakers = Speakers
@@ -769,8 +763,7 @@ past_events = Eventi passati
769763
upcoming_events = Prossimi eventi
770764
running_sprint = BeeWare eseguirà uno sprint a
771765
what_is_a_sprint = Cos'è uno sprint?
772-
sprint_description = Gli sprint in codice sono eventi che si tengono normalmente dopo una conferenza, dove i partecipanti possono utilizzare la sede della conferenza per lavorare in piccoli gruppi su vari progetti. Per saperne di più su come funzionano gli sprint con il
773-
sprint_pycon_video = Video PyCon US 'Cos'è uno sprint?
766+
sprint_description = Gli sprint in codice sono eventi che si tengono normalmente dopo una conferenza, dove i partecipanti possono utilizzare la sede della conferenza per lavorare in piccoli gruppi su vari progetti. Per saperne di più su come funzionano gli sprint con il {{ pycon_link("Video PyCon US 'Cos'è uno sprint?" }}.
774767
challenge_coin = Challenge coin (moneta sfida)
775768
data = Data
776769
speakers = Relatori
@@ -881,8 +874,7 @@ past_events = Poprzednie wydarzenia
881874
upcoming_events = Nadchodzące wydarzenia
882875
running_sprint = BeeWare poprowadzi sprint na
883876
what_is_a_sprint = Co to jest sprint?
884-
sprint_description = Sprint to wydarzenie odbywające się zwykle po konferencji, na którym uczestnicy mogą popracować w małych grupach nad różnymi projektami. Dowiedz się więcej z
885-
sprint_pycon_video = nagrania z PyCon US "Co to jest sprint?"
877+
sprint_description = Sprint to wydarzenie odbywające się zwykle po konferencji, na którym uczestnicy mogą popracować w małych grupach nad różnymi projektami. Dowiedz się więcej z {{ pycon_link('nagrania z PyCon US "Co to jest sprint?"') }}.
886878
challenge_coin = odznakę
887879
date = Data
888880
speakers = Prowadzący
@@ -1001,10 +993,7 @@ past_events = 过去的活动
1001993
upcoming_events = 即将到来的活动
1002994
running_sprint = BeeWare 将会举行一场冲刺
1003995
what_is_a_sprint = 什么是冲刺
1004-
sprint_description = 代码冲刺是通常在会议结束后举行的活动,与会者可以使用会议场地分组处理各种项目。用
1005-
sprint_pycon_video = PyCon US 什么是冲刺视频
1006-
; chinese-specific
1007-
post_sprint_pycon_video = 了解更多关于冲刺是如何工作的。
996+
sprint_description = 代码冲刺是通常在会议结束后举行的活动,与会者可以使用会议场地分组处理各种项目。用{{ pycon_link("PyCon US 什么是冲刺视频") }}了解更多关于冲刺是如何工作的。
1008997
challenge_coin = 挑战币
1009998
date = 日期
1010999
speakers = 演讲者

packages/lektor_beeware_plugin/lektor_beeware_plugin.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,33 @@
44
from datetime import date
55

66
from lektor.pluginsystem import Plugin
7-
from jinja2 import pass_context
7+
from jinja2 import pass_context, Template
8+
from markupsafe import Markup
89

910

1011
@pass_context
1112
def translate(context, string, bag_name="translate"):
1213
# Make sure that any macros which need to call this are imported with context.
1314
alt = context["this"].alt
1415
bag = context["bag"]
16+
result = ""
1517
if trans := bag(f"{bag_name}.{alt}.{string}"):
16-
return trans
18+
result = trans
1719

18-
if en := bag(f"{bag_name}.en.{string}"):
19-
return en
20+
if not result and (en := bag(f"{bag_name}.en.{string}")):
21+
result = en
2022

21-
return ""
23+
template = Template(result)
24+
25+
# Wrapping it in Markup() marks it as safe, so it won't be escaped.
26+
return Markup(template.render(context))
27+
28+
29+
def link_to(address):
30+
def link_maker(text):
31+
return f'<a href="{address}">{text}</a>'
32+
33+
return link_maker
2234

2335

2436
class BeeWarePlugin(Plugin):
@@ -27,4 +39,5 @@ class BeeWarePlugin(Plugin):
2739

2840
def on_setup_env(self, **extra):
2941
self.env.jinja_env.globals["today"] = date.today()
42+
self.env.jinja_env.globals["link_to"] = link_to
3043
self.env.jinja_env.filters["trans"] = translate

templates/event.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
}
2020
%}
2121

22+
{# Note: for some reason this has to be defined outside of the block it's needed in. #}
23+
{% set pycon_link = link_to("https://www.youtube.com/watch?v=hOtKgFaFcz0") %}
2224
{% set member_slugs = this.speaker %}
2325
{% set members = site.query("/about/team") %}
2426
{% set speaker_names = {} %}
@@ -54,8 +56,7 @@ <h1>{{ this.title }} ({{ this.event_type|title }})</h1>
5456
</p>
5557
<p>{{ "event_more_info"|trans }} <a href="{{ this.url }}">{{ this.title }} {{ "website"|trans }}</a>.</p>
5658
<h3>{{ "what_is_a_sprint"|trans }}</h3>
57-
{%- set post = "post_sprint_pycon_video"|trans %}
58-
<p>{{ "sprint_description"|trans }} <a href="https://www.youtube.com/watch?v=hOtKgFaFcz0">{{ "sprint_pycon_video"|trans }}</a>{% if post %} {% endif %}{{ post }}.</p>
59+
<p>{{ "sprint_description"|trans }}</p>
5960
{% endif %}
6061
<p><em>{{ this.description }}</em></p>
6162
{% endblock %}

0 commit comments

Comments
 (0)