@mr-hope/vuepress-shared
Advanced tools
Comparing version 1.13.3 to 1.14.0
@@ -1,5 +0,5 @@ | ||
import type { HopeThemeLocaleConfigItem, LangPaths, Langs } from "./types"; | ||
export declare const langs: Langs[]; | ||
export declare const lang2PathConfig: Record<Langs, LangPaths>; | ||
export declare const path2langConfig: Record<LangPaths, Langs>; | ||
export declare const localesConfig: Record<Langs, HopeThemeLocaleConfigItem>; | ||
import type { HopeThemeLocaleConfigItem, HopeLangPath, HopeLang } from "./types"; | ||
export declare const langs: HopeLang[]; | ||
export declare const lang2PathConfig: Record<HopeLang, HopeLangPath>; | ||
export declare const path2langConfig: Record<HopeLangPath, HopeLang>; | ||
export declare const localesConfig: Record<HopeLang, HopeThemeLocaleConfigItem>; |
@@ -1,8 +0,14 @@ | ||
import type { Langs, LangPaths, HopeThemeLocaleConfigItem } from "./types"; | ||
import { Context } from "@mr-hope/vuepress-types"; | ||
import type { HopeLang, HopeLangPath, HopeThemeLocaleConfigItem } from "./types"; | ||
export declare const showLangError: (lang: string) => void; | ||
/** Check if the lang is supported */ | ||
export declare const checkLang: (lang: Langs) => boolean; | ||
export declare const checkLang: (lang: string | undefined) => boolean; | ||
/** Get language of root directory */ | ||
export declare const getRootLang: (context: Context) => HopeLang; | ||
/** Get the infer language path from root directory language */ | ||
export declare const getRootLangPath: (context: Context) => HopeLangPath; | ||
/** Get path from language */ | ||
export declare const lang2Path: (lang?: string) => LangPaths | "/"; | ||
export declare const lang2Path: (lang?: string) => HopeLangPath | "/"; | ||
/** Get language from path */ | ||
export declare const path2Lang: (path?: string) => Langs; | ||
export declare const path2Lang: (path?: string) => HopeLang; | ||
/** Get locate of certain language */ | ||
@@ -9,0 +15,0 @@ export declare const getLocale: (lang: string) => HopeThemeLocaleConfigItem; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getDefaultLocale = exports.getLocale = exports.path2Lang = exports.lang2Path = exports.checkLang = void 0; | ||
exports.getDefaultLocale = exports.getLocale = exports.path2Lang = exports.lang2Path = exports.getRootLangPath = exports.getRootLang = exports.checkLang = exports.showLangError = void 0; | ||
const config_1 = require("./config"); | ||
const reportStatus = {}; | ||
const showLangError = (lang) => { | ||
if (!reportStatus[lang]) { | ||
console.warn(`${lang} locates config is missing, and will return 'en-US' instead. | ||
You can contribute to https://github.com/vuepress-theme-hope/vuepress-theme-hope/blob/v1/packages/shared/src/i18n/config.ts and other 'i18n.ts' in this repository. | ||
Note: This warning will be shown only once.`); | ||
reportStatus[lang] = true; | ||
} | ||
}; | ||
exports.showLangError = showLangError; | ||
/** Check if the lang is supported */ | ||
const checkLang = (lang) => config_1.langs.includes(lang); | ||
const checkLang = (lang) => { | ||
const result = config_1.langs.includes(lang); | ||
return result; | ||
}; | ||
exports.checkLang = checkLang; | ||
/** Get language of root directory */ | ||
const getRootLang = (context) => { | ||
// infer from siteLocale | ||
const siteLocales = context.siteConfig.locales; | ||
if (siteLocales?.["/"] && exports.checkLang(siteLocales["/"]?.lang)) | ||
return siteLocales["/"].lang; | ||
// infer from themeLocale | ||
const themeLocales = context.themeConfig.locales; | ||
if (themeLocales?.["/"] && exports.checkLang(themeLocales["/"]?.lang)) | ||
return themeLocales["/"].lang; | ||
exports.showLangError("root"); | ||
return "en-US"; | ||
}; | ||
exports.getRootLang = getRootLang; | ||
/** Get the infer language path from root directory language */ | ||
const getRootLangPath = (context) => config_1.lang2PathConfig[exports.getRootLang(context)]; | ||
exports.getRootLangPath = getRootLangPath; | ||
/** Get path from language */ | ||
@@ -29,8 +58,3 @@ const lang2Path = (lang = "") => { | ||
return config_1.localesConfig[lang]; | ||
if (!reportStatus[lang]) { | ||
console.warn(`${lang} locates config is missing, and will return 'en-US' instead. | ||
You can contribute to https://github.com/vuepress-theme-hope/vuepress-theme-hope/blob/master/packages/shared/shared/i18n.json. | ||
Note: This warning will be shown only once.`); | ||
reportStatus[lang] = true; | ||
} | ||
exports.showLangError(lang); | ||
return config_1.localesConfig["en-US"]; | ||
@@ -37,0 +61,0 @@ }; |
/** Types for supported lang codes */ | ||
export declare type Langs = "zh-CN" | "en-US" | "vi-VN" | "de-AT"; | ||
export declare type HopeLang = "zh-CN" | "en-US" | "vi-VN" | "de-AT"; | ||
/** Types for supported lang paths */ | ||
export declare type LangPaths = "/zh/" | "/en/" | "/vi/" | "/de/"; | ||
export declare type HopeLangPath = "/zh/" | "/en/" | "/vi/" | "/de/"; | ||
export interface HopeThemeLocaleConfigItem { | ||
@@ -70,4 +70,4 @@ /** 当前语言代码 */ | ||
} | ||
export declare type PluginI18nConvert<T> = Record<LangPaths, T> & { | ||
export declare type PluginI18nConvert<T> = Record<HopeLangPath, T> & { | ||
"/"?: T; | ||
}; |
@@ -19,5 +19,3 @@ /** Deep merge objects to the first one */ | ||
else | ||
originObject[property] = { | ||
...assignObject[property], | ||
}; | ||
originObject[property] = Object.assign({}, assignObject[property]); | ||
else | ||
@@ -42,5 +40,3 @@ originObject[property] = assignObject[property]; | ||
else | ||
assignObject[property] = { | ||
...originObject[property], | ||
}; | ||
assignObject[property] = Object.assign({}, originObject[property]); | ||
else | ||
@@ -47,0 +43,0 @@ assignObject[property] = originObject[property]; |
@@ -1,5 +0,5 @@ | ||
import type { HopeThemeLocaleConfigItem, LangPaths, Langs } from "./types"; | ||
export declare const langs: Langs[]; | ||
export declare const lang2PathConfig: Record<Langs, LangPaths>; | ||
export declare const path2langConfig: Record<LangPaths, Langs>; | ||
export declare const localesConfig: Record<Langs, HopeThemeLocaleConfigItem>; | ||
import type { HopeThemeLocaleConfigItem, HopeLangPath, HopeLang } from "./types"; | ||
export declare const langs: HopeLang[]; | ||
export declare const lang2PathConfig: Record<HopeLang, HopeLangPath>; | ||
export declare const path2langConfig: Record<HopeLangPath, HopeLang>; | ||
export declare const localesConfig: Record<HopeLang, HopeThemeLocaleConfigItem>; |
@@ -1,8 +0,14 @@ | ||
import type { Langs, LangPaths, HopeThemeLocaleConfigItem } from "./types"; | ||
import { Context } from "@mr-hope/vuepress-types"; | ||
import type { HopeLang, HopeLangPath, HopeThemeLocaleConfigItem } from "./types"; | ||
export declare const showLangError: (lang: string) => void; | ||
/** Check if the lang is supported */ | ||
export declare const checkLang: (lang: Langs) => boolean; | ||
export declare const checkLang: (lang: string | undefined) => boolean; | ||
/** Get language of root directory */ | ||
export declare const getRootLang: (context: Context) => HopeLang; | ||
/** Get the infer language path from root directory language */ | ||
export declare const getRootLangPath: (context: Context) => HopeLangPath; | ||
/** Get path from language */ | ||
export declare const lang2Path: (lang?: string) => LangPaths | "/"; | ||
export declare const lang2Path: (lang?: string) => HopeLangPath | "/"; | ||
/** Get language from path */ | ||
export declare const path2Lang: (path?: string) => Langs; | ||
export declare const path2Lang: (path?: string) => HopeLang; | ||
/** Get locate of certain language */ | ||
@@ -9,0 +15,0 @@ export declare const getLocale: (lang: string) => HopeThemeLocaleConfigItem; |
import { langs, lang2PathConfig, path2langConfig, localesConfig, } from "./config"; | ||
const reportStatus = {}; | ||
export const showLangError = (lang) => { | ||
if (!reportStatus[lang]) { | ||
console.warn(`${lang} locates config is missing, and will return 'en-US' instead. | ||
You can contribute to https://github.com/vuepress-theme-hope/vuepress-theme-hope/blob/v1/packages/shared/src/i18n/config.ts and other 'i18n.ts' in this repository. | ||
Note: This warning will be shown only once.`); | ||
reportStatus[lang] = true; | ||
} | ||
}; | ||
/** Check if the lang is supported */ | ||
export const checkLang = (lang) => langs.includes(lang); | ||
export const checkLang = (lang) => { | ||
const result = langs.includes(lang); | ||
return result; | ||
}; | ||
/** Get language of root directory */ | ||
export const getRootLang = (context) => { | ||
var _a, _b; | ||
// infer from siteLocale | ||
const siteLocales = context.siteConfig.locales; | ||
if ((siteLocales === null || siteLocales === void 0 ? void 0 : siteLocales["/"]) && checkLang((_a = siteLocales["/"]) === null || _a === void 0 ? void 0 : _a.lang)) | ||
return siteLocales["/"].lang; | ||
// infer from themeLocale | ||
const themeLocales = context.themeConfig.locales; | ||
if ((themeLocales === null || themeLocales === void 0 ? void 0 : themeLocales["/"]) && checkLang((_b = themeLocales["/"]) === null || _b === void 0 ? void 0 : _b.lang)) | ||
return themeLocales["/"].lang; | ||
showLangError("root"); | ||
return "en-US"; | ||
}; | ||
/** Get the infer language path from root directory language */ | ||
export const getRootLangPath = (context) => lang2PathConfig[getRootLang(context)]; | ||
/** Get path from language */ | ||
@@ -23,8 +50,3 @@ export const lang2Path = (lang = "") => { | ||
return localesConfig[lang]; | ||
if (!reportStatus[lang]) { | ||
console.warn(`${lang} locates config is missing, and will return 'en-US' instead. | ||
You can contribute to https://github.com/vuepress-theme-hope/vuepress-theme-hope/blob/master/packages/shared/shared/i18n.json. | ||
Note: This warning will be shown only once.`); | ||
reportStatus[lang] = true; | ||
} | ||
showLangError(lang); | ||
return localesConfig["en-US"]; | ||
@@ -31,0 +53,0 @@ }; |
/** Types for supported lang codes */ | ||
export declare type Langs = "zh-CN" | "en-US" | "vi-VN" | "de-AT"; | ||
export declare type HopeLang = "zh-CN" | "en-US" | "vi-VN" | "de-AT"; | ||
/** Types for supported lang paths */ | ||
export declare type LangPaths = "/zh/" | "/en/" | "/vi/" | "/de/"; | ||
export declare type HopeLangPath = "/zh/" | "/en/" | "/vi/" | "/de/"; | ||
export interface HopeThemeLocaleConfigItem { | ||
@@ -70,4 +70,4 @@ /** 当前语言代码 */ | ||
} | ||
export declare type PluginI18nConvert<T> = Record<LangPaths, T> & { | ||
export declare type PluginI18nConvert<T> = Record<HopeLangPath, T> & { | ||
"/"?: T; | ||
}; |
@@ -1,5 +0,5 @@ | ||
import type { HopeThemeLocaleConfigItem, LangPaths, Langs } from "./types"; | ||
export declare const langs: Langs[]; | ||
export declare const lang2PathConfig: Record<Langs, LangPaths>; | ||
export declare const path2langConfig: Record<LangPaths, Langs>; | ||
export declare const localesConfig: Record<Langs, HopeThemeLocaleConfigItem>; | ||
import type { HopeThemeLocaleConfigItem, HopeLangPath, HopeLang } from "./types"; | ||
export declare const langs: HopeLang[]; | ||
export declare const lang2PathConfig: Record<HopeLang, HopeLangPath>; | ||
export declare const path2langConfig: Record<HopeLangPath, HopeLang>; | ||
export declare const localesConfig: Record<HopeLang, HopeThemeLocaleConfigItem>; |
@@ -1,8 +0,14 @@ | ||
import type { Langs, LangPaths, HopeThemeLocaleConfigItem } from "./types"; | ||
import { Context } from "@mr-hope/vuepress-types"; | ||
import type { HopeLang, HopeLangPath, HopeThemeLocaleConfigItem } from "./types"; | ||
export declare const showLangError: (lang: string) => void; | ||
/** Check if the lang is supported */ | ||
export declare const checkLang: (lang: Langs) => boolean; | ||
export declare const checkLang: (lang: string | undefined) => boolean; | ||
/** Get language of root directory */ | ||
export declare const getRootLang: (context: Context) => HopeLang; | ||
/** Get the infer language path from root directory language */ | ||
export declare const getRootLangPath: (context: Context) => HopeLangPath; | ||
/** Get path from language */ | ||
export declare const lang2Path: (lang?: string) => LangPaths | "/"; | ||
export declare const lang2Path: (lang?: string) => HopeLangPath | "/"; | ||
/** Get language from path */ | ||
export declare const path2Lang: (path?: string) => Langs; | ||
export declare const path2Lang: (path?: string) => HopeLang; | ||
/** Get locate of certain language */ | ||
@@ -9,0 +15,0 @@ export declare const getLocale: (lang: string) => HopeThemeLocaleConfigItem; |
/** Types for supported lang codes */ | ||
export declare type Langs = "zh-CN" | "en-US" | "vi-VN" | "de-AT"; | ||
export declare type HopeLang = "zh-CN" | "en-US" | "vi-VN" | "de-AT"; | ||
/** Types for supported lang paths */ | ||
export declare type LangPaths = "/zh/" | "/en/" | "/vi/" | "/de/"; | ||
export declare type HopeLangPath = "/zh/" | "/en/" | "/vi/" | "/de/"; | ||
export interface HopeThemeLocaleConfigItem { | ||
@@ -70,4 +70,4 @@ /** 当前语言代码 */ | ||
} | ||
export declare type PluginI18nConvert<T> = Record<LangPaths, T> & { | ||
export declare type PluginI18nConvert<T> = Record<HopeLangPath, T> & { | ||
"/"?: T; | ||
}; |
{ | ||
"name": "@mr-hope/vuepress-shared", | ||
"version": "1.13.3", | ||
"version": "1.14.0", | ||
"description": "Shared for vuepress-theme-hope", | ||
@@ -36,3 +36,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "c86af678f2b486ae88e2d15728f725ef25f3bcd1" | ||
"gitHead": "5d1e490ca12e8d0202449acb670301184200b473" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
120747
954