diff --git a/sample.cv.json b/sample.cv.json index 92939b3..f6cf70d 100644 --- a/sample.cv.json +++ b/sample.cv.json @@ -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" diff --git a/schema/jsoncv.schema.json b/schema/jsoncv.schema.json index 5fe30dd..afda1b9 100644 --- a/schema/jsoncv.schema.json +++ b/schema/jsoncv.schema.json @@ -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", diff --git a/src/editor/main.js b/src/editor/main.js index 02511c1..ead12dd 100644 --- a/src/editor/main.js +++ b/src/editor/main.js @@ -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 diff --git a/src/themes/index.js b/src/themes/index.js index 2259e26..12402bf 100644 --- a/src/themes/index.js +++ b/src/themes/index.js @@ -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)