From fdb68d6d4385f83aa7e2e70cf05245f76412736b Mon Sep 17 00:00:00 2001 From: Razon Yang Date: Tue, 16 Jan 2024 19:49:20 +0800 Subject: [PATCH] feat: translate field labels via Hugo i18n (#81) --- i18n/en.toml | 38 +++++++++++++++++++ i18n/zh-hans.toml | 38 +++++++++++++++++++ i18n/zh-hant.toml | 38 +++++++++++++++++++ .../partials/decap-cms/functions/config.html | 2 + 4 files changed, 116 insertions(+) create mode 100644 i18n/en.toml create mode 100644 i18n/zh-hans.toml create mode 100644 i18n/zh-hant.toml diff --git a/i18n/en.toml b/i18n/en.toml new file mode 100644 index 0000000..6523c80 --- /dev/null +++ b/i18n/en.toml @@ -0,0 +1,38 @@ +[cms_field_label_body] +other = "Body" + +[cms_field_label_categories] +other = "Categories" + +[cms_field_label_date] +other = "Date" + +[cms_field_label_description] +other = "Description" + +[cms_field_label_draft] +other = "Draft" + +[cms_field_label_images] +other = "Images" + +[cms_field_label_keywords] +other = "Keywords" + +[cms_field_label_layout] +other = "Layout" + +[cms_field_label_series] +other = "Series" + +[cms_field_label_slug] +other = "Slug" + +[cms_field_label_tags] +other = "Tags" + +[cms_field_label_title] +other = "Title" + +[cms_field_label_type] +other = "Type" diff --git a/i18n/zh-hans.toml b/i18n/zh-hans.toml new file mode 100644 index 0000000..4e9cda7 --- /dev/null +++ b/i18n/zh-hans.toml @@ -0,0 +1,38 @@ +[cms_field_label_body] +other = "正文" + +[cms_field_label_categories] +other = "分类" + +[cms_field_label_date] +other = "日期" + +[cms_field_label_description] +other = "描述" + +[cms_field_label_draft] +other = "草稿" + +[cms_field_label_images] +other = "图片" + +[cms_field_label_keywords] +other = "关键词" + +[cms_field_label_layout] +other = "布局" + +[cms_field_label_series] +other = "专栏" + +[cms_field_label_slug] +other = "Slug" + +[cms_field_label_tags] +other = "标签" + +[cms_field_label_title] +other = "标题" + +[cms_field_label_type] +other = "类型" diff --git a/i18n/zh-hant.toml b/i18n/zh-hant.toml new file mode 100644 index 0000000..17dc2d2 --- /dev/null +++ b/i18n/zh-hant.toml @@ -0,0 +1,38 @@ +[cms_field_label_body] +other = "正文" + +[cms_field_label_categories] +other = "分類" + +[cms_field_label_date] +other = "日期" + +[cms_field_label_description] +other = "描述" + +[cms_field_label_draft] +other = "草稿" + +[cms_field_label_images] +other = "圖片" + +[cms_field_label_keywords] +other = "關鍵詞" + +[cms_field_label_layout] +other = "佈局" + +[cms_field_label_series] +other = "專欄" + +[cms_field_label_slug] +other = "Slug" + +[cms_field_label_tags] +other = "標籤" + +[cms_field_label_title] +other = "標題" + +[cms_field_label_type] +other = "類型" diff --git a/layouts/partials/decap-cms/functions/config.html b/layouts/partials/decap-cms/functions/config.html index 179e056..991e97e 100644 --- a/layouts/partials/decap-cms/functions/config.html +++ b/layouts/partials/decap-cms/functions/config.html @@ -69,6 +69,8 @@ {{- $tmp := newScratch }} {{- $tmp.Set "field" . }} {{- $tmp.DeleteInMap "field" "_weight" }} + {{- $label := default .label (printf "cms_field_label_%s" (replace (lower .label) " " "_") | i18n) }} + {{- $tmp.SetInMap "field" "label" $label }} {{- $collection.Add "fields" (slice ($tmp.Get "field")) }} {{- end }} {{- end -}}