mirror of
https://github.com/nunocoracao/blowfish.git
synced 2026-10-10 22:09:31 +00:00
feat: localize 404 page quotes (#3052)
* feat: localize 404 page quotes * 🐛 Fix 404 quote localization: build-time filtering and dub lines Filter quotes to the page language at build time (case-insensitive, with base-language and English fallbacks), fixing the double-encoded language variable that made every locale fall back to English, and correct several translations to their canonical dub lines. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Friday <friday@openclaw.local> Co-authored-by: Nuno Coração <nunocoracao@gmail.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
3 files changed
+1661
-10
No files matched your search
+1620
-9
File diff suppressed because it is too large.
Load diff
@@ -58,6 +58,27 @@ Blowfish was built so it would be easy to add visual support to your articles. I
|
||||
|
||||
Blowfish is optimised for full multilingual websites and theme assets are translated into several languages out of the box. The language configuration allows you to generate multiple versions of your content to provide a customised experience to your visitors in their native language.
|
||||
|
||||
### 404 page quotes
|
||||
|
||||
The 404 page displays a random movie quote in the active site language. You can replace the bundled quotes by adding a `data/quotes404.json` file to your site. Each item needs a `line` and `source`; use `lang` to target a language. Language codes may be full codes such as `pt-PT` or base codes such as `pt`. Quotes without `lang` are treated as English for backwards compatibility.
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"lang": "en",
|
||||
"line": "You shall not pass!",
|
||||
"source": "The Fellowship of the Ring (2001)"
|
||||
},
|
||||
{
|
||||
"lang": "pt-PT",
|
||||
"line": "Não passarás!",
|
||||
"source": "The Fellowship of the Ring (2001)"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
Blowfish tries an exact language match, then the base language, then English. If none are available, it selects from any configured quote.
|
||||
|
||||
The theme currently supports the following languages by default:
|
||||
|
||||
| Language | Code |
|
||||
|
||||
+20
-1
@@ -29,7 +29,26 @@
|
||||
</div>
|
||||
|
||||
{{ with hugo.Data.quotes404 }}
|
||||
{{ $json := . | jsonify }}
|
||||
{{/* Pick the current language's quotes at build time: exact locale
|
||||
first, then base language, then English. Quotes without a lang are
|
||||
treated as English to preserve existing custom overrides. */}}
|
||||
{{ $lang := lower site.Language.Lang }}
|
||||
{{ $base := index (split $lang "-") 0 }}
|
||||
{{ $localized := slice }}
|
||||
{{ $english := slice }}
|
||||
{{ range . }}
|
||||
{{ $qlang := lower (.lang | default "en") }}
|
||||
{{ if or (eq $qlang $lang) (eq $qlang $base) }}
|
||||
{{ $localized = $localized | append . }}
|
||||
{{ end }}
|
||||
{{ if eq $qlang "en" }}
|
||||
{{ $english = $english | append . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ $quotes := $localized }}
|
||||
{{ if not $quotes }}{{ $quotes = $english }}{{ end }}
|
||||
{{ if not $quotes }}{{ $quotes = . }}{{ end }}
|
||||
{{ $json := $quotes | jsonify }}
|
||||
<script>
|
||||
(function () {
|
||||
var quotes = JSON.parse({{ $json }});
|
||||
|
||||
Reference in new issue
Block a user