From 3518ca9e2a04f326eda25ada2393a4bbfde10738 Mon Sep 17 00:00:00 2001 From: Alq Date: Sun, 11 Feb 2024 21:43:08 +0300 Subject: [PATCH] feat(i18n): localize the min read string (#838) * feat(i18n): localize the min read string fixes #825 * chore: format --- quartz/components/ContentMeta.tsx | 8 ++++++-- quartz/i18n/locales/ar-SA.ts | 8 ++++++++ quartz/i18n/locales/de-DE.ts | 3 +++ quartz/i18n/locales/definition.ts | 3 +++ quartz/i18n/locales/en-US.ts | 3 +++ quartz/i18n/locales/es-ES.ts | 3 +++ quartz/i18n/locales/fr-FR.ts | 3 +++ quartz/i18n/locales/ja-JP.ts | 3 +++ quartz/i18n/locales/nl-NL.ts | 3 +++ quartz/i18n/locales/ro-RO.ts | 3 +++ quartz/i18n/locales/uk-UA.ts | 3 +++ 11 files changed, 41 insertions(+), 2 deletions(-) diff --git a/quartz/components/ContentMeta.tsx b/quartz/components/ContentMeta.tsx index 6cd083e69..bcbe4285d 100644 --- a/quartz/components/ContentMeta.tsx +++ b/quartz/components/ContentMeta.tsx @@ -2,6 +2,7 @@ import { formatDate, getDate } from "./Date" import { QuartzComponentConstructor, QuartzComponentProps } from "./types" import readingTime from "reading-time" import { classNames } from "../util/lang" +import { i18n } from "../i18n" interface ContentMetaOptions { /** @@ -30,8 +31,11 @@ export default ((opts?: Partial) => { // Display reading time if enabled if (options.showReadingTime) { - const { text: timeTaken, words: _words } = readingTime(text) - segments.push(timeTaken) + const { minutes, words: _words } = readingTime(text) + const displayedTime = i18n(cfg.locale).components.contentMeta.readingTime({ + minutes: Math.ceil(minutes), + }) + segments.push(displayedTime) } return

{segments.join(", ")}

diff --git a/quartz/i18n/locales/ar-SA.ts b/quartz/i18n/locales/ar-SA.ts index d8efeffef..f7048103f 100644 --- a/quartz/i18n/locales/ar-SA.ts +++ b/quartz/i18n/locales/ar-SA.ts @@ -53,6 +53,14 @@ export default { tableOfContents: { title: "فهرس المحتويات", }, + contentMeta: { + readingTime: ({ minutes }) => + minutes == 1 + ? `دقيقة أو أقل للقراءة` + : minutes == 2 + ? `دقيقتان للقراءة` + : `${minutes} دقائق للقراءة`, + }, }, pages: { rss: { diff --git a/quartz/i18n/locales/de-DE.ts b/quartz/i18n/locales/de-DE.ts index f2125bf60..e3821944b 100644 --- a/quartz/i18n/locales/de-DE.ts +++ b/quartz/i18n/locales/de-DE.ts @@ -53,6 +53,9 @@ export default { tableOfContents: { title: "Inhaltsverzeichnis", }, + contentMeta: { + readingTime: ({ minutes }) => `${minutes} min read`, + }, }, pages: { rss: { diff --git a/quartz/i18n/locales/definition.ts b/quartz/i18n/locales/definition.ts index baf2a5875..1d5d3dda6 100644 --- a/quartz/i18n/locales/definition.ts +++ b/quartz/i18n/locales/definition.ts @@ -55,6 +55,9 @@ export interface Translation { tableOfContents: { title: string } + contentMeta: { + readingTime: (variables: { minutes: number }) => string + } } pages: { rss: { diff --git a/quartz/i18n/locales/en-US.ts b/quartz/i18n/locales/en-US.ts index 3ba28a0d5..4a308d79a 100644 --- a/quartz/i18n/locales/en-US.ts +++ b/quartz/i18n/locales/en-US.ts @@ -53,6 +53,9 @@ export default { tableOfContents: { title: "Table of Contents", }, + contentMeta: { + readingTime: ({ minutes }) => `${minutes} min read`, + }, }, pages: { rss: { diff --git a/quartz/i18n/locales/es-ES.ts b/quartz/i18n/locales/es-ES.ts index 92a74a03c..f59d201a3 100644 --- a/quartz/i18n/locales/es-ES.ts +++ b/quartz/i18n/locales/es-ES.ts @@ -53,6 +53,9 @@ export default { tableOfContents: { title: "Tabla de Contenidos", }, + contentMeta: { + readingTime: ({ minutes }) => `${minutes} min read`, + }, }, pages: { rss: { diff --git a/quartz/i18n/locales/fr-FR.ts b/quartz/i18n/locales/fr-FR.ts index fee1ad921..8b7229201 100644 --- a/quartz/i18n/locales/fr-FR.ts +++ b/quartz/i18n/locales/fr-FR.ts @@ -53,6 +53,9 @@ export default { tableOfContents: { title: "Table des Matières", }, + contentMeta: { + readingTime: ({ minutes }) => `${minutes} min read`, + }, }, pages: { rss: { diff --git a/quartz/i18n/locales/ja-JP.ts b/quartz/i18n/locales/ja-JP.ts index f684c36b3..d429db411 100644 --- a/quartz/i18n/locales/ja-JP.ts +++ b/quartz/i18n/locales/ja-JP.ts @@ -53,6 +53,9 @@ export default { tableOfContents: { title: "目次", }, + contentMeta: { + readingTime: ({ minutes }) => `${minutes} min read`, + }, }, pages: { rss: { diff --git a/quartz/i18n/locales/nl-NL.ts b/quartz/i18n/locales/nl-NL.ts index b40362355..3ff3e8cd9 100644 --- a/quartz/i18n/locales/nl-NL.ts +++ b/quartz/i18n/locales/nl-NL.ts @@ -53,6 +53,9 @@ export default { tableOfContents: { title: "Inhoudsopgave", }, + contentMeta: { + readingTime: ({ minutes }) => `${minutes} min read`, + }, }, pages: { rss: { diff --git a/quartz/i18n/locales/ro-RO.ts b/quartz/i18n/locales/ro-RO.ts index 39f1344be..a1c216ded 100644 --- a/quartz/i18n/locales/ro-RO.ts +++ b/quartz/i18n/locales/ro-RO.ts @@ -53,6 +53,9 @@ export default { tableOfContents: { title: "Cuprins", }, + contentMeta: { + readingTime: ({ minutes }) => `${minutes} min read`, + }, }, pages: { rss: { diff --git a/quartz/i18n/locales/uk-UA.ts b/quartz/i18n/locales/uk-UA.ts index d60b1f8cf..c997a6972 100644 --- a/quartz/i18n/locales/uk-UA.ts +++ b/quartz/i18n/locales/uk-UA.ts @@ -53,6 +53,9 @@ export default { tableOfContents: { title: "Зміст", }, + contentMeta: { + readingTime: ({ minutes }) => `${minutes} min read`, + }, }, pages: { rss: {