From f4eda4278579ae366accc2dcc1baea554c1505c8 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Fri, 3 Nov 2023 14:19:06 +0800 Subject: [PATCH] feat(i18n): add translations for the new languages (de, es, fr, it, CJK) --- assets/scss/_core/_typography.scss | 2 +- assets/ts/desktop/stageNav.ts | 23 ++++++++++++----------- assets/ts/mobile/gallery.ts | 13 +++++++++++-- exampleSite/config/_default/hugo.toml | 4 ++++ i18n/de.toml | 9 +++++++++ i18n/en.toml | 9 +++++++++ i18n/es.toml | 9 +++++++++ i18n/fr.toml | 9 +++++++++ i18n/it.toml | 9 +++++++++ i18n/ja.toml | 8 ++++++++ i18n/ko.toml | 8 ++++++++ i18n/zh-cn.toml | 8 ++++++++ i18n/zh-hk.toml | 8 ++++++++ i18n/zh-mo.toml | 8 ++++++++ i18n/zh-sg.toml | 8 ++++++++ i18n/zh-tw.toml | 8 ++++++++ layouts/_default/single.html | 7 ++++++- layouts/partials/head/link.html | 2 +- layouts/partials/nav.html | 2 +- 19 files changed, 137 insertions(+), 17 deletions(-) create mode 100644 i18n/de.toml create mode 100644 i18n/en.toml create mode 100644 i18n/es.toml create mode 100644 i18n/fr.toml create mode 100644 i18n/it.toml create mode 100644 i18n/ja.toml create mode 100644 i18n/ko.toml create mode 100644 i18n/zh-cn.toml create mode 100644 i18n/zh-hk.toml create mode 100644 i18n/zh-mo.toml create mode 100644 i18n/zh-sg.toml create mode 100644 i18n/zh-tw.toml diff --git a/assets/scss/_core/_typography.scss b/assets/scss/_core/_typography.scss index bed33ff..9e6a3f2 100644 --- a/assets/scss/_core/_typography.scss +++ b/assets/scss/_core/_typography.scss @@ -17,7 +17,7 @@ body { } } -body:lang(en) { +body:lang(en, de, es, fr, it) { font-family: 'Geist', sans-serif; } diff --git a/assets/ts/desktop/stageNav.ts b/assets/ts/desktop/stageNav.ts index fe164d1..931becb 100644 --- a/assets/ts/desktop/stageNav.ts +++ b/assets/ts/desktop/stageNav.ts @@ -15,23 +15,24 @@ type NavItem = (typeof navItems)[number] * variables */ -const navItems = ['prev', 'close', 'next'] as const +const mainDiv = document.getElementById('main') as HTMLDivElement +const navItems = [ + mainDiv.getAttribute('prevText') as string, + mainDiv.getAttribute('closeText') as string, + mainDiv.getAttribute('nextText') as string +] as const /** * main functions */ function handleClick(type: NavItem): void { - switch (type) { - case 'prev': - prevImage() - break - case 'close': - minimizeImage() - break - case 'next': - nextImage() - break + if (type === navItems[0]) { + prevImage() + } else if (type === navItems[1]) { + minimizeImage() + } else { + nextImage() } } diff --git a/assets/ts/mobile/gallery.ts b/assets/ts/mobile/gallery.ts index 86ead48..0696512 100644 --- a/assets/ts/mobile/gallery.ts +++ b/assets/ts/mobile/gallery.ts @@ -4,7 +4,13 @@ import { type Swiper } from 'swiper' import { container } from '../container' import { type ImageJSON } from '../resources' import { setIndex, state } from '../state' -import { Watchable, expand, loadGsap, loadSwiper } from '../utils' +import { + Watchable, + capitalizeFirstLetter, + expand, + loadGsap, + loadSwiper +} from '../utils' import { mounted } from './mounted' import { scrollable } from './scroll' @@ -214,7 +220,10 @@ function createGallery(ijs: ImageJSON[]): void { ) // close const _close = document.createElement('div') - _close.innerText = 'Close' + const str: string = document + .getElementById('main') + ?.getAttribute('closeText') as string + _close.innerText = capitalizeFirstLetter(str) _close.addEventListener( 'click', () => { diff --git a/exampleSite/config/_default/hugo.toml b/exampleSite/config/_default/hugo.toml index 109cfc3..2ffe3f2 100644 --- a/exampleSite/config/_default/hugo.toml +++ b/exampleSite/config/_default/hugo.toml @@ -12,6 +12,10 @@ disableKinds = ["section", "taxonomy", "term", "home"] enableRobotsTXT = true # available options # * en (powered by Geist) +# * de (powered by Geist) +# * es (powered by Geist) +# * fr (powered by Geist) +# * it (powered by Geist) # * zh-sg zh-cn (powered by Noto Sans SC) # * zh-hk zh-tw zh-mo (powered by Noto Sans TC) # * ja (powered by Noto Sans JP) diff --git a/i18n/de.toml b/i18n/de.toml new file mode 100644 index 0000000..33c1c87 --- /dev/null +++ b/i18n/de.toml @@ -0,0 +1,9 @@ +[next] +other = "nächste" +[prev] +other = "vorher" +[close] +other = "schließen" +# capititalized for menu +[threshold] +other = "Schwelle" diff --git a/i18n/en.toml b/i18n/en.toml new file mode 100644 index 0000000..a2ae8a1 --- /dev/null +++ b/i18n/en.toml @@ -0,0 +1,9 @@ +[next] +other = "next" +[prev] +other = "prev" +[close] +other = "close" +# capitialize the first letter of the word +[threshold] +other = "Threshold" diff --git a/i18n/es.toml b/i18n/es.toml new file mode 100644 index 0000000..f89fa58 --- /dev/null +++ b/i18n/es.toml @@ -0,0 +1,9 @@ +[next] +other = "siguiente" +[prev] +other = "previo" +[close] +other = "cerrar" +# capititalized for menu +[threshold] +other = "Umbral" diff --git a/i18n/fr.toml b/i18n/fr.toml new file mode 100644 index 0000000..1f444fc --- /dev/null +++ b/i18n/fr.toml @@ -0,0 +1,9 @@ +[next] +other = "suivant" +[prev] +other = "précédent" +[close] +other = "fermer" +# capititalized for menu +[threshold] +other = "Seuil" diff --git a/i18n/it.toml b/i18n/it.toml new file mode 100644 index 0000000..bd47771 --- /dev/null +++ b/i18n/it.toml @@ -0,0 +1,9 @@ +[next] +other = "prossimo" +[prev] +other = "precedente" +[close] +other = "chiudi" +# capititalized for menu +[threshold] +other = "Soglia" diff --git a/i18n/ja.toml b/i18n/ja.toml new file mode 100644 index 0000000..0eff0b5 --- /dev/null +++ b/i18n/ja.toml @@ -0,0 +1,8 @@ +[next] +other = "進む" +[prev] +other = "後退" +[close] +other = "閉じる" +[threshold] +other = "しきい値" diff --git a/i18n/ko.toml b/i18n/ko.toml new file mode 100644 index 0000000..908bd1c --- /dev/null +++ b/i18n/ko.toml @@ -0,0 +1,8 @@ +[next] +other = "전진" +[prev] +other = "물러나세요" +[close] +other = "닫기" +[threshold] +other = "임계값" diff --git a/i18n/zh-cn.toml b/i18n/zh-cn.toml new file mode 100644 index 0000000..3649b93 --- /dev/null +++ b/i18n/zh-cn.toml @@ -0,0 +1,8 @@ +[next] +other = "前进" +[prev] +other = "后退" +[close] +other = "关闭" +[threshold] +other = "阈值" diff --git a/i18n/zh-hk.toml b/i18n/zh-hk.toml new file mode 100644 index 0000000..81d2188 --- /dev/null +++ b/i18n/zh-hk.toml @@ -0,0 +1,8 @@ +[next] +other = "前進" +[prev] +other = "後退" +[close] +other = "關閉" +[threshold] +other = "閾值" diff --git a/i18n/zh-mo.toml b/i18n/zh-mo.toml new file mode 100644 index 0000000..81d2188 --- /dev/null +++ b/i18n/zh-mo.toml @@ -0,0 +1,8 @@ +[next] +other = "前進" +[prev] +other = "後退" +[close] +other = "關閉" +[threshold] +other = "閾值" diff --git a/i18n/zh-sg.toml b/i18n/zh-sg.toml new file mode 100644 index 0000000..3649b93 --- /dev/null +++ b/i18n/zh-sg.toml @@ -0,0 +1,8 @@ +[next] +other = "前进" +[prev] +other = "后退" +[close] +other = "关闭" +[threshold] +other = "阈值" diff --git a/i18n/zh-tw.toml b/i18n/zh-tw.toml new file mode 100644 index 0000000..81d2188 --- /dev/null +++ b/i18n/zh-tw.toml @@ -0,0 +1,8 @@ +[next] +other = "前進" +[prev] +other = "後退" +[close] +other = "關閉" +[threshold] +other = "閾值" diff --git a/layouts/_default/single.html b/layouts/_default/single.html index ddc0d8d..704e561 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -3,7 +3,12 @@ {{- $currentPage := . -}} {{- with partial "function/currentMenuItem.html" . -}} {{- partial "resources/imageJSON.html" (dict "Path" .DirName "Page" $currentPage) -}} - + {{- end -}}
{{- partial "nav.html" . -}} diff --git a/layouts/partials/head/link.html b/layouts/partials/head/link.html index d19a8b5..335a59d 100644 --- a/layouts/partials/head/link.html +++ b/layouts/partials/head/link.html @@ -29,7 +29,7 @@ {{/* fonts */}} -{{- if (partial "function/langCode.html" (slice "en")) -}} +{{- if (partial "function/langCode.html" (slice "en" "de" "fr" "es" "it")) -}} {{- else if (partial "function/langCode.html" (slice "zh-cn" "zh-sg")) -}}
- Threshold: + {{- i18n "threshold" -}}: