add meta.locale in jsoncv schema, use it when rendering the theme

This commit is contained in:
Reorx 2023-12-08 21:00:46 +08:00
parent 44808bf31e
commit 911df68cd1
4 changed files with 16 additions and 4 deletions

View File

@ -280,6 +280,8 @@
}
],
"meta": {
"name": "JSONCV Sample Resume",
"locale": "en",
"canonical": "https://raw.githubusercontent.com/reorx/jsoncv/master/schema/jsoncv.schema.json",
"version": "v2.0.0",
"lastModified": "2023-02-12T22:26:00"

View File

@ -509,6 +509,10 @@
"type": "string",
"description": "The name of this JSONCV data, will be used as part of the filename when downloading."
},
"locale": {
"type": "string",
"description": "Locale of the CV, used by the theme to localize the CV. The value must be a valid IETF language tag. Default to 'en' if not specified. A full list of locale tag can be found at: https://cdn.jsdelivr.net/npm/dayjs@1/locale.json"
},
"canonical": {
"type": "string",
"description": "URL (as per RFC 3986) to latest version of this document",

View File

@ -25,7 +25,7 @@ import { getCVTitle } from '../themes/data';
import { registerIconLib } from './je-iconlib';
import { registerTheme } from './je-theme';
const propertiesInOrder = ['basics', 'education', 'work', 'projects', 'sideProjects', 'skills', 'languages', 'interests', 'references', 'awards', 'publications', 'volunteer', 'certificates', 'meta']
const propertiesInOrder = ['meta', 'basics', 'education', 'work', 'projects', 'sideProjects', 'skills', 'languages', 'interests', 'references', 'awards', 'publications', 'volunteer', 'certificates']
const basicsPropertiesInOrder = ['name', 'label', 'email', 'phone', 'url', 'summary', 'image', 'location', 'profiles']
// toc elements

View File

@ -40,9 +40,15 @@ export function getTheme(name) {
return themes[name]
}
export function renderTheme(theme, cvData, locale, options) {
export function renderTheme(theme, cvData, options) {
const locale = cvData.meta.locale || 'en'
const messages = theme.index.localeMessages[locale]
if (!messages) {
return `Error: locale '${locale}' is not supported, please use one of: ${theme.index.locales}`
}
const polyglot = new Polyglot({
phrases: theme.index.localeMessages[locale],
phrases: messages,
locale,
})
dayjs.locale(locale)
return ejs.render(theme.template, getRenderData(cvData, locale, polyglot), options)
@ -52,7 +58,7 @@ const cvStyleId = 'cv-style'
export function renderThemeOn(name, el, data, primaryColor) {
const theme = getTheme(name)
el.innerHTML = renderTheme(theme, data, 'zh-cn')
el.innerHTML = renderTheme(theme, data)
upsertStyleTag(cvStyleId, theme.style)