Aaron Pham
2024-02-10 db5e701810f17aef70a2bea078de27f0e4386c06
feat(i18n): support parsing callouts (#834)

* feat(i18n): support parsing callouts

Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>

* chore: move callout into components

Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>

* chore: update arabic translation

Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>

* fix: make sure to use correct items

Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>

---------

Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com>
12 files modified
168 ■■■■■ changed files
quartz/i18n/index.ts 3 ●●●● patch | view | raw | blame | history
quartz/i18n/locales/ar-SA.ts 15 ●●●●● patch | view | raw | blame | history
quartz/i18n/locales/de-DE.ts 15 ●●●●● patch | view | raw | blame | history
quartz/i18n/locales/definition.ts 17 ●●●●● patch | view | raw | blame | history
quartz/i18n/locales/en-US.ts 15 ●●●●● patch | view | raw | blame | history
quartz/i18n/locales/es-ES.ts 15 ●●●●● patch | view | raw | blame | history
quartz/i18n/locales/fr-FR.ts 15 ●●●●● patch | view | raw | blame | history
quartz/i18n/locales/ja-JP.ts 15 ●●●●● patch | view | raw | blame | history
quartz/i18n/locales/nl-NL.ts 15 ●●●●● patch | view | raw | blame | history
quartz/i18n/locales/ro-RO.ts 15 ●●●●● patch | view | raw | blame | history
quartz/i18n/locales/uk-UA.ts 15 ●●●●● patch | view | raw | blame | history
quartz/plugins/transformers/ofm.ts 13 ●●●● patch | view | raw | blame | history
quartz/i18n/index.ts
@@ -1,4 +1,4 @@
import { Translation } from "./locales/definition"
import { Translation, CalloutTranslation } from "./locales/definition"
import en from "./locales/en-US"
import fr from "./locales/fr-FR"
import ja from "./locales/ja-JP"
@@ -44,3 +44,4 @@
export const defaultTranslation = "en-US"
export const i18n = (locale: ValidLocale): Translation => TRANSLATIONS[locale ?? defaultTranslation]
export type ValidLocale = keyof typeof TRANSLATIONS
export type ValidCallout = keyof CalloutTranslation
quartz/i18n/locales/ar-SA.ts
@@ -6,6 +6,21 @@
    description: "لم يتم تقديم أي وصف",
  },
  components: {
    callout: {
      note: "ملاحظة",
      abstract: "ملخص",
      info: "معلومات",
      todo: "للقيام",
      tip: "نصيحة",
      success: "نجاح",
      question: "سؤال",
      warning: "تحذير",
      failure: "فشل",
      danger: "خطر",
      bug: "خلل",
      example: "مثال",
      quote: "اقتباس",
    },
    backlinks: {
      title: "وصلات العودة",
      noBacklinksFound: "لا يوجد وصلات عودة",
quartz/i18n/locales/de-DE.ts
@@ -6,6 +6,21 @@
    description: "Keine Beschreibung angegeben",
  },
  components: {
    callout: {
      note: "Hinweis",
      abstract: "Zusammenfassung",
      info: "Info",
      todo: "Zu erledigen",
      tip: "Tipp",
      success: "Erfolg",
      question: "Frage",
      warning: "Warnung",
      failure: "Misserfolg",
      danger: "Gefahr",
      bug: "Fehler",
      example: "Beispiel",
      quote: "Zitat",
    },
    backlinks: {
      title: "Backlinks",
      noBacklinksFound: "Keine Backlinks gefunden",
quartz/i18n/locales/definition.ts
@@ -1,11 +1,28 @@
import { FullSlug } from "../../util/path"
export interface CalloutTranslation {
  note: string
  abstract: string
  info: string
  todo: string
  tip: string
  success: string
  question: string
  warning: string
  failure: string
  danger: string
  bug: string
  example: string
  quote: string
}
export interface Translation {
  propertyDefaults: {
    title: string
    description: string
  }
  components: {
    callout: CalloutTranslation
    backlinks: {
      title: string
      noBacklinksFound: string
quartz/i18n/locales/en-US.ts
@@ -6,6 +6,21 @@
    description: "No description provided",
  },
  components: {
    callout: {
      note: "Note",
      abstract: "Abstract",
      info: "Info",
      todo: "Todo",
      tip: "Tip",
      success: "Success",
      question: "Question",
      warning: "Warning",
      failure: "Failure",
      danger: "Danger",
      bug: "Bug",
      example: "Example",
      quote: "Quote",
    },
    backlinks: {
      title: "Backlinks",
      noBacklinksFound: "No backlinks found",
quartz/i18n/locales/es-ES.ts
@@ -6,6 +6,21 @@
    description: "Sin descripción",
  },
  components: {
    callout: {
      note: "Nota",
      abstract: "Resumen",
      info: "Información",
      todo: "Por hacer",
      tip: "Consejo",
      success: "Éxito",
      question: "Pregunta",
      warning: "Advertencia",
      failure: "Fallo",
      danger: "Peligro",
      bug: "Error",
      example: "Ejemplo",
      quote: "Cita",
    },
    backlinks: {
      title: "Enlaces de Retroceso",
      noBacklinksFound: "No se han encontrado enlaces traseros",
quartz/i18n/locales/fr-FR.ts
@@ -6,6 +6,21 @@
    description: "Aucune description fournie",
  },
  components: {
    callout: {
      note: "Note",
      abstract: "Résumé",
      info: "Info",
      todo: "À faire",
      tip: "Conseil",
      success: "Succès",
      question: "Question",
      warning: "Avertissement",
      failure: "Échec",
      danger: "Danger",
      bug: "Bogue",
      example: "Exemple",
      quote: "Citation",
    },
    backlinks: {
      title: "Liens retour",
      noBacklinksFound: "Aucun lien retour trouvé",
quartz/i18n/locales/ja-JP.ts
@@ -6,6 +6,21 @@
    description: "説明なし",
  },
  components: {
    callout: {
      note: "ノート",
      abstract: "抄録",
      info: "情報",
      todo: "やるべきこと",
      tip: "ヒント",
      success: "成功",
      question: "質問",
      warning: "警告",
      failure: "失敗",
      danger: "危険",
      bug: "バグ",
      example: "例",
      quote: "引用",
    },
    backlinks: {
      title: "バックリンク",
      noBacklinksFound: "バックリンクはありません",
quartz/i18n/locales/nl-NL.ts
@@ -6,6 +6,21 @@
    description: "Geen beschrijving gegeven.",
  },
  components: {
    callout: {
      note: "Notitie",
      abstract: "Samenvatting",
      info: "Info",
      todo: "Te doen",
      tip: "Tip",
      success: "Succes",
      question: "Vraag",
      warning: "Waarschuwing",
      failure: "Mislukking",
      danger: "Gevaar",
      bug: "Bug",
      example: "Voorbeeld",
      quote: "Citaat",
    },
    backlinks: {
      title: "Backlinks",
      noBacklinksFound: "Geen backlinks gevonden",
quartz/i18n/locales/ro-RO.ts
@@ -6,6 +6,21 @@
    description: "Nici o descriere furnizată",
  },
  components: {
    callout: {
      note: "Notă",
      abstract: "Rezumat",
      info: "Informație",
      todo: "De făcut",
      tip: "Sfat",
      success: "Succes",
      question: "Întrebare",
      warning: "Avertisment",
      failure: "Eșec",
      danger: "Pericol",
      bug: "Bug",
      example: "Exemplu",
      quote: "Citat",
    },
    backlinks: {
      title: "Legături înapoi",
      noBacklinksFound: "Nu s-au găsit legături înapoi",
quartz/i18n/locales/uk-UA.ts
@@ -6,6 +6,21 @@
    description: "Опис не надано",
  },
  components: {
    callout: {
      note: "Примітка",
      abstract: "Абстракт",
      info: "Інформація",
      todo: "Завдання",
      tip: "Порада",
      success: "Успіх",
      question: "Питання",
      warning: "Попередження",
      failure: "Невдача",
      danger: "Небезпека",
      bug: "Баг",
      example: "Приклад",
      quote: "Цитата",
    },
    backlinks: {
      title: "Зворотні посилання",
      noBacklinksFound: "Зворотних посилань не знайдено",
quartz/plugins/transformers/ofm.ts
@@ -1,5 +1,5 @@
import { QuartzTransformerPlugin } from "../types"
import { Root, Html, BlockContent, DefinitionContent, Paragraph, Code } from "mdast"
import { Blockquote, Root, Html, BlockContent, DefinitionContent, Paragraph, Code } from "mdast"
import { Element, Literal, Root as HtmlRoot } from "hast"
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
import { slug as slugAnchor } from "github-slugger"
@@ -17,6 +17,7 @@
import { PhrasingContent } from "mdast-util-find-and-replace/lib"
import { capitalize } from "../../util/lang"
import { PluggableList } from "unified"
import { ValidCallout, i18n } from "../../i18n"
export interface Options {
  comments: boolean
@@ -185,8 +186,9 @@
      return src
    },
    markdownPlugins() {
    markdownPlugins(ctx) {
      const plugins: PluggableList = []
      const cfg = ctx.cfg.configuration
      // regex replacements
      plugins.push(() => {
@@ -407,7 +409,12 @@
                  children: [
                    {
                      type: "text",
                      value: useDefaultTitle ? capitalize(calloutType) : titleContent + " ",
                      value: useDefaultTitle
                        ? capitalize(
                            i18n(cfg.locale).components.callout[calloutType as ValidCallout] ??
                              calloutType,
                          )
                        : titleContent + " ",
                    },
                    ...restOfTitle,
                  ],