@docusaurus/utils 0.0.0-4796 → 0.0.0-4799
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/i18nUtils.d.ts +24 -1
- package/lib/i18nUtils.d.ts.map +1 -1
- package/lib/i18nUtils.js +21 -1
- package/lib/i18nUtils.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -2
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/i18nUtils.ts +49 -1
- package/src/index.ts +1 -0
package/lib/i18nUtils.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type { TranslationFileContent, TranslationFile } from '@docusaurus/types';
|
|
7
|
+
import type { TranslationFileContent, TranslationFile, I18n } from '@docusaurus/types';
|
|
8
8
|
/**
|
|
9
9
|
* Takes a list of translation file contents, and shallow-merges them into one.
|
|
10
10
|
*/
|
|
@@ -25,4 +25,27 @@ export declare function getPluginI18nPath({ siteDir, locale, pluginName, pluginI
|
|
|
25
25
|
pluginId?: string | undefined;
|
|
26
26
|
subPaths?: string[];
|
|
27
27
|
}): string;
|
|
28
|
+
/**
|
|
29
|
+
* Takes a path and returns a localized a version (which is basically `path +
|
|
30
|
+
* i18n.currentLocale`).
|
|
31
|
+
*/
|
|
32
|
+
export declare function localizePath({ pathType, path: originalPath, i18n, options, }: {
|
|
33
|
+
/**
|
|
34
|
+
* FS paths will treat Windows specially; URL paths will always have a
|
|
35
|
+
* trailing slash to make it a valid base URL.
|
|
36
|
+
*/
|
|
37
|
+
pathType: 'fs' | 'url';
|
|
38
|
+
/** The path, URL or file path, to be localized. */
|
|
39
|
+
path: string;
|
|
40
|
+
/** The current i18n context. */
|
|
41
|
+
i18n: I18n;
|
|
42
|
+
options?: {
|
|
43
|
+
/**
|
|
44
|
+
* By default, we don't localize the path of defaultLocale. This option
|
|
45
|
+
* would override that behavior. Setting `false` is useful for `yarn build
|
|
46
|
+
* -l zh-Hans` to always emit into the root build directory.
|
|
47
|
+
*/
|
|
48
|
+
localizePath?: boolean;
|
|
49
|
+
};
|
|
50
|
+
}): string;
|
|
28
51
|
//# sourceMappingURL=i18nUtils.d.ts.map
|
package/lib/i18nUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18nUtils.d.ts","sourceRoot":"","sources":["../src/i18nUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"i18nUtils.d.ts","sourceRoot":"","sources":["../src/i18nUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EACf,IAAI,EACL,MAAM,mBAAmB,CAAC;AAI3B;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,sBAAsB,EAAE,GACjC,sBAAsB,CAExB;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GACzC,eAAe,CAQjB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,MAAM,EACN,UAAU,EACV,QAA4B,EAC5B,QAAa,GACd,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,GAAG,MAAM,CAYT;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,IAAI,EAAE,YAAY,EAClB,IAAI,EACJ,OAAY,GACb,EAAE;IACD;;;OAGG;IACH,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC;IACvB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,CAAC,EAAE;QACR;;;;WAIG;QACH,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,CAAC;CACH,GAAG,MAAM,CAcT"}
|
package/lib/i18nUtils.js
CHANGED
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getPluginI18nPath = exports.updateTranslationFileMessages = exports.mergeTranslations = void 0;
|
|
9
|
+
exports.localizePath = exports.getPluginI18nPath = exports.updateTranslationFileMessages = exports.mergeTranslations = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
|
+
const urlUtils_1 = require("./urlUtils");
|
|
14
15
|
/**
|
|
15
16
|
* Takes a list of translation file contents, and shallow-merges them into one.
|
|
16
17
|
*/
|
|
@@ -46,4 +47,23 @@ function getPluginI18nPath({ siteDir, locale, pluginName, pluginId = constants_1
|
|
|
46
47
|
`${pluginName}${pluginId === constants_1.DEFAULT_PLUGIN_ID ? '' : `-${pluginId}`}`, ...subPaths);
|
|
47
48
|
}
|
|
48
49
|
exports.getPluginI18nPath = getPluginI18nPath;
|
|
50
|
+
/**
|
|
51
|
+
* Takes a path and returns a localized a version (which is basically `path +
|
|
52
|
+
* i18n.currentLocale`).
|
|
53
|
+
*/
|
|
54
|
+
function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
|
|
55
|
+
const shouldLocalizePath =
|
|
56
|
+
//
|
|
57
|
+
options.localizePath ?? i18n.currentLocale !== i18n.defaultLocale;
|
|
58
|
+
if (!shouldLocalizePath) {
|
|
59
|
+
return originalPath;
|
|
60
|
+
}
|
|
61
|
+
// FS paths need special care, for Windows support
|
|
62
|
+
if (pathType === 'fs') {
|
|
63
|
+
return path_1.default.join(originalPath, i18n.currentLocale);
|
|
64
|
+
}
|
|
65
|
+
// Url paths; add a trailing slash so it's a valid base URL
|
|
66
|
+
return (0, urlUtils_1.normalizeUrl)([originalPath, i18n.currentLocale, '/']);
|
|
67
|
+
}
|
|
68
|
+
exports.localizePath = localizePath;
|
|
49
69
|
//# sourceMappingURL=i18nUtils.js.map
|
package/lib/i18nUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18nUtils.js","sourceRoot":"","sources":["../src/i18nUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AACxB,4DAAuB;
|
|
1
|
+
{"version":3,"file":"i18nUtils.js","sourceRoot":"","sources":["../src/i18nUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AACxB,4DAAuB;AAMvB,2CAA6D;AAC7D,yCAAwC;AAExC;;GAEG;AACH,SAAgB,iBAAiB,CAC/B,QAAkC;IAElC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,GAAG,EAAE,GAAG,OAAO,EAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACvE,CAAC;AAJD,8CAIC;AAED;;;GAGG;AACH,SAAgB,6BAA6B,CAC3C,eAAgC,EAChC,aAA0C;IAE1C,OAAO;QACL,GAAG,eAAe;QAClB,OAAO,EAAE,gBAAC,CAAC,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAC9D,GAAG,WAAW;YACd,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC;SAC5C,CAAC,CAAC;KAC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AULT_STATIC_DIR_NAME, OUTPUT_STATIC_ASSETS_DIR_NAME, THEME_PATH, I18N_DIR_NAME, CODE_TRANSLATIONS_FILE_NAME, DEFAULT_PORT, DEFAULT_PLUGIN_ID, WEBPACK_URL_LOADER_LIMIT, } from './constants';
|
|
8
8
|
export { generate, genChunkName, readOutputHTMLFile } from './emitUtils';
|
|
9
9
|
export { getFileCommitDate, FileNotTrackedError, GitNotFoundError, } from './gitUtils';
|
|
10
|
-
export { mergeTranslations, updateTranslationFileMessages, getPluginI18nPath, } from './i18nUtils';
|
|
10
|
+
export { mergeTranslations, updateTranslationFileMessages, getPluginI18nPath, localizePath, } from './i18nUtils';
|
|
11
11
|
export { removeSuffix, removePrefix, mapAsyncSequential, findAsyncSequential, reportMessage, } from './jsUtils';
|
|
12
12
|
export { normalizeUrl, getEditUrl, fileToPath, encodePath, isValidPathname, resolvePathname, addLeadingSlash, addTrailingSlash, removeTrailingSlash, hasSSHProtocol, buildHttpsUrl, buildSshUrl, } from './urlUtils';
|
|
13
13
|
export { type Tag, type FrontMatterTag, normalizeFrontMatterTags, groupTaggedItems, } from './tags';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,YAAY,EACZ,uBAAuB,EACvB,6BAA6B,EAC7B,UAAU,EACV,aAAa,EACb,2BAA2B,EAC3B,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,QAAQ,EAAE,YAAY,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAC;AACvE,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iBAAiB,EACjB,6BAA6B,EAC7B,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,YAAY,EACZ,uBAAuB,EACvB,6BAA6B,EAC7B,UAAU,EACV,aAAa,EACb,2BAA2B,EAC3B,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,QAAQ,EAAE,YAAY,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAC;AACvE,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iBAAiB,EACjB,6BAA6B,EAC7B,iBAAiB,EACjB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,GACd,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,eAAe,EACf,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,GAAG,EACR,KAAK,cAAc,EACnB,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,gBAAgB,EAChB,yBAAyB,EACzB,mBAAmB,EACnB,sBAAsB,EACtB,KAAK,qBAAqB,GAC3B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,aAAa,EAAC,MAAM,WAAW,CAAC;AAC3E,OAAO,EACL,aAAa,EACb,SAAS,EACT,SAAS,EACT,yBAAyB,EACzB,eAAe,EACf,UAAU,EACV,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAC,MAAM,aAAa,CAAC;AAC1D,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,aAAa,EACb,6BAA6B,GAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAClD,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
10
|
-
exports.getFolderContainingFile = exports.findFolderContainingFile = exports.getContentPathList = exports.getDataFileData = exports.getDataFilePath = exports.getFileLoaderUtils = exports.createAbsoluteFilePathMatcher = exports.createMatcher = exports.GlobExcludeDefault = exports.Globby = exports.docuHash = exports.simpleHash = exports.md5Hash = exports.addTrailingPathSeparator = exports.escapePath = exports.aliasedSitePath = exports.toMessageRelativeFilePath = exports.posixPath = exports.shortName = exports.isNameTooLong = exports.createSlugger = void 0;
|
|
9
|
+
exports.writeMarkdownHeadingId = exports.parseMarkdownString = exports.parseMarkdownContentTitle = exports.parseFrontMatter = exports.createExcerpt = exports.parseMarkdownHeadingId = exports.groupTaggedItems = exports.normalizeFrontMatterTags = exports.buildSshUrl = exports.buildHttpsUrl = exports.hasSSHProtocol = exports.removeTrailingSlash = exports.addTrailingSlash = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.encodePath = exports.fileToPath = exports.getEditUrl = exports.normalizeUrl = exports.reportMessage = exports.findAsyncSequential = exports.mapAsyncSequential = exports.removePrefix = exports.removeSuffix = exports.localizePath = exports.getPluginI18nPath = exports.updateTranslationFileMessages = exports.mergeTranslations = exports.GitNotFoundError = exports.FileNotTrackedError = exports.getFileCommitDate = exports.readOutputHTMLFile = exports.genChunkName = exports.generate = exports.WEBPACK_URL_LOADER_LIMIT = exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.CODE_TRANSLATIONS_FILE_NAME = exports.I18N_DIR_NAME = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.DEFAULT_STATIC_DIR_NAME = exports.SRC_DIR_NAME = exports.GENERATED_FILES_DIR_NAME = exports.BABEL_CONFIG_FILE_NAME = exports.DEFAULT_CONFIG_FILE_NAME = exports.DEFAULT_BUILD_DIR_NAME = exports.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
|
|
10
|
+
exports.getFolderContainingFile = exports.findFolderContainingFile = exports.getContentPathList = exports.getDataFileData = exports.getDataFilePath = exports.getFileLoaderUtils = exports.createAbsoluteFilePathMatcher = exports.createMatcher = exports.GlobExcludeDefault = exports.Globby = exports.docuHash = exports.simpleHash = exports.md5Hash = exports.addTrailingPathSeparator = exports.escapePath = exports.aliasedSitePath = exports.toMessageRelativeFilePath = exports.posixPath = exports.shortName = exports.isNameTooLong = exports.createSlugger = exports.replaceMarkdownLinks = void 0;
|
|
11
11
|
var constants_1 = require("./constants");
|
|
12
12
|
Object.defineProperty(exports, "NODE_MAJOR_VERSION", { enumerable: true, get: function () { return constants_1.NODE_MAJOR_VERSION; } });
|
|
13
13
|
Object.defineProperty(exports, "NODE_MINOR_VERSION", { enumerable: true, get: function () { return constants_1.NODE_MINOR_VERSION; } });
|
|
@@ -36,6 +36,7 @@ var i18nUtils_1 = require("./i18nUtils");
|
|
|
36
36
|
Object.defineProperty(exports, "mergeTranslations", { enumerable: true, get: function () { return i18nUtils_1.mergeTranslations; } });
|
|
37
37
|
Object.defineProperty(exports, "updateTranslationFileMessages", { enumerable: true, get: function () { return i18nUtils_1.updateTranslationFileMessages; } });
|
|
38
38
|
Object.defineProperty(exports, "getPluginI18nPath", { enumerable: true, get: function () { return i18nUtils_1.getPluginI18nPath; } });
|
|
39
|
+
Object.defineProperty(exports, "localizePath", { enumerable: true, get: function () { return i18nUtils_1.localizePath; } });
|
|
39
40
|
var jsUtils_1 = require("./jsUtils");
|
|
40
41
|
Object.defineProperty(exports, "removeSuffix", { enumerable: true, get: function () { return jsUtils_1.removeSuffix; } });
|
|
41
42
|
Object.defineProperty(exports, "removePrefix", { enumerable: true, get: function () { return jsUtils_1.removePrefix; } });
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,yCAgBqB;AAfnB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA;AACtB,qHAAA,wBAAwB,OAAA;AACxB,mHAAA,sBAAsB,OAAA;AACtB,qHAAA,wBAAwB,OAAA;AACxB,yGAAA,YAAY,OAAA;AACZ,oHAAA,uBAAuB,OAAA;AACvB,0HAAA,6BAA6B,OAAA;AAC7B,uGAAA,UAAU,OAAA;AACV,0GAAA,aAAa,OAAA;AACb,wHAAA,2BAA2B,OAAA;AAC3B,yGAAA,YAAY,OAAA;AACZ,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AAE1B,yCAAuE;AAA/D,qGAAA,QAAQ,OAAA;AAAE,yGAAA,YAAY,OAAA;AAAE,+GAAA,kBAAkB,OAAA;AAClD,uCAIoB;AAHlB,6GAAA,iBAAiB,OAAA;AACjB,+GAAA,mBAAmB,OAAA;AACnB,4GAAA,gBAAgB,OAAA;AAElB,
|
|
1
|
+
{"version":3,"file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,aAAa,OAAA;AACb,uGAAA,WAAW,OAAA;AAEb,+BAKgB;AAFd,gHAAA,wBAAwB,OAAA;AACxB,wGAAA,gBAAgB,OAAA;AAElB,iDAQyB;AAPvB,uHAAA,sBAAsB,OAAA;AACtB,8GAAA,aAAa,OAAA;AACb,iHAAA,gBAAgB,OAAA;AAChB,0HAAA,yBAAyB,OAAA;AACzB,oHAAA,mBAAmB,OAAA;AACnB,uHAAA,sBAAsB,OAAA;AAGxB,iDAIyB;AADvB,qHAAA,oBAAoB,OAAA;AAEtB,qCAA2E;AAAhC,wGAAA,aAAa,OAAA;AACxD,yCAQqB;AAPnB,0GAAA,aAAa,OAAA;AACb,sGAAA,SAAS,OAAA;AACT,sGAAA,SAAS,OAAA;AACT,sHAAA,yBAAyB,OAAA;AACzB,4GAAA,eAAe,OAAA;AACf,uGAAA,UAAU,OAAA;AACV,qHAAA,wBAAwB,OAAA;AAE1B,yCAA0D;AAAlD,oGAAA,OAAO,OAAA;AAAE,uGAAA,UAAU,OAAA;AAAE,qGAAA,QAAQ,OAAA;AACrC,yCAKqB;AAJnB,mGAAA,MAAM,OAAA;AACN,+GAAA,kBAAkB,OAAA;AAClB,0GAAA,aAAa,OAAA;AACb,0HAAA,6BAA6B,OAAA;AAE/B,+CAAkD;AAA1C,kHAAA,kBAAkB,OAAA;AAC1B,iDAMyB;AALvB,gHAAA,eAAe,OAAA;AACf,gHAAA,eAAe,OAAA;AACf,mHAAA,kBAAkB,OAAA;AAClB,yHAAA,wBAAwB,OAAA;AACxB,wHAAA,uBAAuB,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4799",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "0.0.0-
|
|
21
|
+
"@docusaurus/logger": "0.0.0-4799",
|
|
22
22
|
"@svgr/webpack": "^6.2.1",
|
|
23
23
|
"file-loader": "^6.2.0",
|
|
24
24
|
"fs-extra": "^10.0.1",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"node": ">=14"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@docusaurus/types": "0.0.0-
|
|
41
|
+
"@docusaurus/types": "0.0.0-4799",
|
|
42
42
|
"@types/dedent": "^0.7.0",
|
|
43
43
|
"@types/github-slugger": "^1.3.0",
|
|
44
44
|
"@types/micromatch": "^4.0.2",
|
|
45
45
|
"@types/react-dom": "^17.0.14",
|
|
46
46
|
"dedent": "^0.7.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "f0feed7df346c16329386f13a7f8522660b97a51"
|
|
49
49
|
}
|
package/src/i18nUtils.ts
CHANGED
|
@@ -7,8 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import _ from 'lodash';
|
|
10
|
-
import type {
|
|
10
|
+
import type {
|
|
11
|
+
TranslationFileContent,
|
|
12
|
+
TranslationFile,
|
|
13
|
+
I18n,
|
|
14
|
+
} from '@docusaurus/types';
|
|
11
15
|
import {DEFAULT_PLUGIN_ID, I18N_DIR_NAME} from './constants';
|
|
16
|
+
import {normalizeUrl} from './urlUtils';
|
|
12
17
|
|
|
13
18
|
/**
|
|
14
19
|
* Takes a list of translation file contents, and shallow-merges them into one.
|
|
@@ -65,3 +70,46 @@ export function getPluginI18nPath({
|
|
|
65
70
|
...subPaths,
|
|
66
71
|
);
|
|
67
72
|
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Takes a path and returns a localized a version (which is basically `path +
|
|
76
|
+
* i18n.currentLocale`).
|
|
77
|
+
*/
|
|
78
|
+
export function localizePath({
|
|
79
|
+
pathType,
|
|
80
|
+
path: originalPath,
|
|
81
|
+
i18n,
|
|
82
|
+
options = {},
|
|
83
|
+
}: {
|
|
84
|
+
/**
|
|
85
|
+
* FS paths will treat Windows specially; URL paths will always have a
|
|
86
|
+
* trailing slash to make it a valid base URL.
|
|
87
|
+
*/
|
|
88
|
+
pathType: 'fs' | 'url';
|
|
89
|
+
/** The path, URL or file path, to be localized. */
|
|
90
|
+
path: string;
|
|
91
|
+
/** The current i18n context. */
|
|
92
|
+
i18n: I18n;
|
|
93
|
+
options?: {
|
|
94
|
+
/**
|
|
95
|
+
* By default, we don't localize the path of defaultLocale. This option
|
|
96
|
+
* would override that behavior. Setting `false` is useful for `yarn build
|
|
97
|
+
* -l zh-Hans` to always emit into the root build directory.
|
|
98
|
+
*/
|
|
99
|
+
localizePath?: boolean;
|
|
100
|
+
};
|
|
101
|
+
}): string {
|
|
102
|
+
const shouldLocalizePath: boolean =
|
|
103
|
+
//
|
|
104
|
+
options.localizePath ?? i18n.currentLocale !== i18n.defaultLocale;
|
|
105
|
+
|
|
106
|
+
if (!shouldLocalizePath) {
|
|
107
|
+
return originalPath;
|
|
108
|
+
}
|
|
109
|
+
// FS paths need special care, for Windows support
|
|
110
|
+
if (pathType === 'fs') {
|
|
111
|
+
return path.join(originalPath, i18n.currentLocale);
|
|
112
|
+
}
|
|
113
|
+
// Url paths; add a trailing slash so it's a valid base URL
|
|
114
|
+
return normalizeUrl([originalPath, i18n.currentLocale, '/']);
|
|
115
|
+
}
|