Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
Mention links should be clicked on mobile devices (#2002)
Browse files Browse the repository at this point in the history
* Mention links should be clicked on mobile devices

Internationalize 404 pages

* Return
  • Loading branch information
sethvargo authored Apr 7, 2021
1 parent 96bff09 commit 54242ba
Show file tree
Hide file tree
Showing 20 changed files with 212 additions and 16 deletions.
11 changes: 5 additions & 6 deletions assets/enx-redirect/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@

<body>
<main role="main" class="container mt-5">
<h1>Not found.</h1>
<h1>{{t $.locale "static.not-found"}}</h1>
<p>
<code>{{.requestURI}}</code> was not found on this server.
</p>
<p>
If you are trying to submit your anonymous data for Exposure Notifications,
please contact the public health authority that issued your verification code.
{{t $.locale "static.redirect-not-found"}}
</p>
<div class="d-flex justify-content-center">
<a href="https://g.co/ens" class="small text-muted">{{t $.locale "login.about-exposure-notifications"}}</a>
</div>
</main>
</body>
</html>
Expand Down
4 changes: 2 additions & 2 deletions assets/enx-redirect/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
href="https://cdnjs.cloudflare.com/ajax/libs/open-iconic/1.1.1/font/css/open-iconic-bootstrap.min.css"
integrity="sha256-BJ/G+e+y7bQdrYkS2RBTyNfBHpA9IuGaPmf9htub5MQ=" crossorigin="anonymous">

<title>Exposure Notifications Express Redirect Service</title>
<title>{{if .title}}{{.title}}{{else}}Exposure Notifications Express Redirect Service{{end}}</title>

<style type="text/css">
nav.navbar {
Expand All @@ -36,4 +36,4 @@
}

</style>
{{end}}
{{end}}
10 changes: 5 additions & 5 deletions assets/server/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

<body id="not-found">
<main role="main" class="container mt-5">
<h1>Not found</h1>
<h1>{{t $.locale "static.not-found"}}</h1>
<p>
The resource you attempted to access does not exist.
</p>
<p>
<a href="#" onclick="history.go(-1); return false;">&larr; Go back</a>
{{t $.locale "static.resource-does-not-exist"}}
</p>
<div class="d-flex justify-content-center">
<a href="https://g.co/ens" class="small text-muted">{{t $.locale "login.about-exposure-notifications"}}</a>
</div>
</main>
</body>
</html>
Expand Down
14 changes: 14 additions & 0 deletions internal/i18n/locales/ar/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,17 @@ msgstr "يوجد عدد كبير جدًا من أخطاء التعليمات ا

msgid "codes.bulk-issue.too-many-success"
msgstr "تم إصدار عدد كبير جدًا من الرموز لعرض النتائج"


#
# static pages
# ----------

msgid "static.not-found"
msgstr "غير موجود"

msgid "static.resource-does-not-exist"
msgstr "هذا المورد غير موجود."

msgid "static.redirect-not-found"
msgstr "لاسترداد رمز Exposure Notifications ، قم بزيارة الرابط الموجود على جهازك المحمول."
14 changes: 14 additions & 0 deletions internal/i18n/locales/de/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,17 @@ msgstr "Zu viele Codefehler, um Ergebnisse anzuzeigen"

msgid "codes.bulk-issue.too-many-success"
msgstr "Es wurden zu viele Codes ausgegeben, um die Ergebnisse anzuzeigen"


#
# static pages
# ----------

msgid "static.not-found"
msgstr "Nicht gefunden"

msgid "static.resource-does-not-exist"
msgstr "Diese ressource existiert nicht."

msgid "static.redirect-not-found"
msgstr "Besuchen Sie den Link auf Ihrem Mobilgerät, um einen Exposure Notifications Code einzulösen."
14 changes: 14 additions & 0 deletions internal/i18n/locales/en/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,17 @@ msgstr "Too many code errors to display results"

msgid "codes.bulk-issue.too-many-success"
msgstr "Too many codes issued to display results"


#
# static pages
# ----------

msgid "static.not-found"
msgstr "Not found"

msgid "static.resource-does-not-exist"
msgstr "That resource does not exist."

msgid "static.redirect-not-found"
msgstr "To redeem an Exposure Notifications code, visit the link on your mobile device."
14 changes: 14 additions & 0 deletions internal/i18n/locales/es/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,17 @@ msgstr "Demasiados errores de código para mostrar resultados"

msgid "codes.bulk-issue.too-many-success"
msgstr "Se emitieron demasiados códigos para mostrar los resultados"


#
# static pages
# ----------

msgid "static.not-found"
msgstr "Extraviado"

msgid "static.resource-does-not-exist"
msgstr "Ese recurso no existe."

msgid "static.redirect-not-found"
msgstr "Para canjear un código Exposure Notifications, visite el vínculo en su dispositivo móvil."
14 changes: 14 additions & 0 deletions internal/i18n/locales/fil/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,17 @@ msgstr "Too many code errors to display results"

msgid "codes.bulk-issue.too-many-success"
msgstr "Too many codes issued to display results"


#
# static pages
# ----------

msgid "static.not-found"
msgstr "Hindi mahanap"

msgid "static.resource-does-not-exist"
msgstr "Wala ang mapagkukunang iyon."

msgid "static.redirect-not-found"
msgstr "Upang makuha ang isang Exposure Notifications code, bisitahin ang link sa iyong mobile device."
14 changes: 14 additions & 0 deletions internal/i18n/locales/fr/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,17 @@ msgstr "Too many code errors to display results"

msgid "codes.bulk-issue.too-many-success"
msgstr "Too many codes issued to display results"


#
# static pages
# ----------

msgid "static.not-found"
msgstr "Pas trouvé"

msgid "static.resource-does-not-exist"
msgstr "Cette ressource n'existe pas."

msgid "static.redirect-not-found"
msgstr "Pour utiliser un code Exposure Notifications, visitez le lien sur votre appareil mobile."
14 changes: 14 additions & 0 deletions internal/i18n/locales/id/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,17 @@ msgstr "Terlalu banyak kesalahan kode untuk menampilkan hasil"

msgid "codes.bulk-issue.too-many-success"
msgstr "Terlalu banyak kode yang diterbitkan untuk menampilkan hasil"


#
# static pages
# ----------

msgid "static.not-found"
msgstr "Tidak ditemukan"

msgid "static.resource-does-not-exist"
msgstr "Sumber daya itu tidak ada."

msgid "static.redirect-not-found"
msgstr "Untuk menukarkan kode Exposure Notifications, kunjungi tautan di perangkat seluler Anda."
14 changes: 14 additions & 0 deletions internal/i18n/locales/it/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,17 @@ msgstr "Too many code errors to display results"

msgid "codes.bulk-issue.too-many-success"
msgstr "Too many codes issued to display results"


#
# static pages
# ----------

msgid "static.not-found"
msgstr "Non trovato"

msgid "static.resource-does-not-exist"
msgstr "Quella risorsa non esiste."

msgid "static.redirect-not-found"
msgstr "Per riscattare un codice Exposure Notifications, visita il link sul tuo dispositivo mobile."
14 changes: 14 additions & 0 deletions internal/i18n/locales/ja/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,17 @@ msgstr "Too many code errors to display results"

msgid "codes.bulk-issue.too-many-success"
msgstr "Too many codes issued to display results"


#
# static pages
# ----------

msgid "static.not-found"
msgstr "見つかりません"

msgid "static.resource-does-not-exist"
msgstr "そのリソースは存在しません。"

msgid "static.redirect-not-found"
msgstr "Exposure Notifications コードを利用するには、モバイルデバイスのリンクにアクセスしてください。"
14 changes: 14 additions & 0 deletions internal/i18n/locales/mn/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,17 @@ msgstr "Үр дүнг харуулахын тулд кодын алдаа хэт

msgid "codes.bulk-issue.too-many-success"
msgstr "Үр дүнг харуулахын тулд хэтэрхий олон код гаргасан байна"


#
# static pages
# ----------

msgid "static.not-found"
msgstr "Олдсонгүй"

msgid "static.resource-does-not-exist"
msgstr "Тэр нөөц байхгүй."

msgid "static.redirect-not-found"
msgstr "Exposure Notifications кодыг зарцуулахын тулд мобайл төхөөрөмж дээрх холбоосоор зочилно уу."
14 changes: 14 additions & 0 deletions internal/i18n/locales/pt/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,17 @@ msgstr "Too many code errors to display results"

msgid "codes.bulk-issue.too-many-success"
msgstr "Too many codes issued to display results"


#
# static pages
# ----------

msgid "static.not-found"
msgstr "Não encontrado"

msgid "static.resource-does-not-exist"
msgstr "Esse recurso não existe."

msgid "static.redirect-not-found"
msgstr "Para resgatar um código Exposure Notifications, visite o link em seu dispositivo móvel."
14 changes: 14 additions & 0 deletions internal/i18n/locales/tr/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,17 @@ msgstr "Too many code errors to display results"

msgid "codes.bulk-issue.too-many-success"
msgstr "Too many codes issued to display results"


#
# static pages
# ----------

msgid "static.not-found"
msgstr "Bulunamadı"

msgid "static.resource-does-not-exist"
msgstr "Bu kaynak mevcut değil."

msgid "static.redirect-not-found"
msgstr "Exposure Notifications kodunu kullanmak için mobil cihazınızdaki bağlantıyı ziyaret edin."
17 changes: 17 additions & 0 deletions internal/routes/enx_redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/http"

"github.com/google/exposure-notifications-verification-server/assets"
"github.com/google/exposure-notifications-verification-server/internal/i18n"
"github.com/google/exposure-notifications-verification-server/pkg/cache"
"github.com/google/exposure-notifications-verification-server/pkg/config"
"github.com/google/exposure-notifications-verification-server/pkg/controller"
Expand Down Expand Up @@ -48,6 +49,16 @@ func ENXRedirect(
ctx, obs := middleware.WithObservability(ctx)
r.Use(obs)

// Load localization
locales, err := i18n.Load(i18n.WithReloading(cfg.DevMode))
if err != nil {
return nil, fmt.Errorf("failed to setup i18n: %w", err)
}

// Process localization parameters.
processLocale := middleware.ProcessLocale(locales)
r.Use(processLocale)

// Create the renderer
h, err := render.New(ctx, assets.ENXRedirectFS(), cfg.DevMode)
if err != nil {
Expand Down Expand Up @@ -108,6 +119,12 @@ func ENXRedirect(
}
r.PathPrefix("/").Handler(redirectController.HandleIndex()).Methods(http.MethodGet)

// Blanket handle any missing routes.
r.NotFoundHandler = processLocale(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
controller.NotFound(w, r, h)
return
}))

// Wrap the main router in the mutating middleware method. This cannot be
// inserted as middleware because gorilla processes the method before
// middleware.
Expand Down
6 changes: 6 additions & 0 deletions internal/routes/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ func Server(
systemAdminRoutes(sub, adminController)
}

// Blanket handle any missing routes.
sub.NotFoundHandler = populateTemplateVariables(processLocale(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
controller.NotFound(w, r, h)
return
})))

// Wrap the main router in the mutating middleware method. This cannot be
// inserted as middleware because gorilla processes the method before
// middleware.
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (m TemplateMap) Title(f string, args ...interface{}) {
s = fmt.Sprintf(f, args...)
}

if current := m["title"]; current != "" {
if current := m["title"]; current != nil && current != "" {
m["title"] = fmt.Sprintf("%s | %s", s, current)
return
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func NotFound(w http.ResponseWriter, r *http.Request, h *render.Renderer) {

switch {
case prefixInList(accept, ContentTypeHTML):
h.RenderHTMLStatus(w, http.StatusNotFound, "404", nil)
m := TemplateMapFromContext(r.Context())
m.Title(http.StatusText(http.StatusNotFound))
h.RenderHTMLStatus(w, http.StatusNotFound, "404", m)
case prefixInList(accept, ContentTypeJSON):
h.RenderJSON(w, http.StatusNotFound, http.StatusText(http.StatusNotFound))
default:
Expand Down Expand Up @@ -127,7 +129,9 @@ func Unauthorized(w http.ResponseWriter, r *http.Request, h *render.Renderer) {

switch {
case prefixInList(accept, ContentTypeHTML):
h.RenderHTMLStatus(w, http.StatusUnauthorized, "401", nil)
m := TemplateMapFromContext(r.Context())
m.Title(http.StatusText(http.StatusUnauthorized))
h.RenderHTMLStatus(w, http.StatusUnauthorized, "401", m)
case prefixInList(accept, ContentTypeJSON):
h.RenderJSON(w, http.StatusUnauthorized, apiErrorUnauthorized)
default:
Expand Down
2 changes: 2 additions & 0 deletions pkg/render/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ func (r *Renderer) RenderHTML500(w http.ResponseWriter, err error) {

if r.debug {
r.RenderHTMLStatus(w, code, "500", map[string]string{
"title": http.StatusText(http.StatusInternalServerError),
"error": err.Error(),
})
return
}

r.RenderHTMLStatus(w, code, "500", map[string]string{
"title": http.StatusText(http.StatusInternalServerError),
"error": http.StatusText(code),
})
}
Expand Down

0 comments on commit 54242ba

Please sign in to comment.