typedoc 0.25.12 → 0.26.0-beta.0
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/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/lib/application.d.ts +15 -3
- package/dist/lib/application.js +65 -23
- package/dist/lib/cli.js +1 -1
- package/dist/lib/converter/comments/blockLexer.d.ts +1 -1
- package/dist/lib/converter/comments/blockLexer.js +1 -2
- package/dist/lib/converter/comments/declarationReference.js +8 -8
- package/dist/lib/converter/comments/declarationReferenceResolver.d.ts +1 -1
- package/dist/lib/converter/comments/declarationReferenceResolver.js +15 -14
- package/dist/lib/converter/comments/discovery.d.ts +3 -3
- package/dist/lib/converter/comments/discovery.js +21 -19
- package/dist/lib/converter/comments/index.d.ts +1 -1
- package/dist/lib/converter/comments/index.js +35 -16
- package/dist/lib/converter/comments/lineLexer.d.ts +1 -1
- package/dist/lib/converter/comments/lineLexer.js +1 -2
- package/dist/lib/converter/comments/linkResolver.d.ts +2 -2
- package/dist/lib/converter/comments/linkResolver.js +5 -3
- package/dist/lib/converter/comments/parser.d.ts +14 -3
- package/dist/lib/converter/comments/parser.js +144 -39
- package/dist/lib/converter/comments/rawLexer.d.ts +7 -1
- package/dist/lib/converter/comments/rawLexer.js +21 -70
- package/dist/lib/converter/comments/tagName.js +1 -2
- package/dist/lib/converter/context.d.ts +7 -2
- package/dist/lib/converter/context.js +7 -2
- package/dist/lib/converter/convert-expression.js +2 -3
- package/dist/lib/converter/converter.d.ts +8 -3
- package/dist/lib/converter/converter.js +16 -13
- package/dist/lib/converter/factories/index-signature.d.ts +1 -1
- package/dist/lib/converter/factories/index-signature.js +9 -12
- package/dist/lib/converter/factories/signature.d.ts +1 -1
- package/dist/lib/converter/factories/signature.js +11 -12
- package/dist/lib/converter/jsdoc.js +2 -3
- package/dist/lib/converter/plugins/CategoryPlugin.d.ts +3 -3
- package/dist/lib/converter/plugins/CategoryPlugin.js +22 -15
- package/dist/lib/converter/plugins/CommentPlugin.d.ts +1 -1
- package/dist/lib/converter/plugins/CommentPlugin.js +58 -67
- package/dist/lib/converter/plugins/GroupPlugin.d.ts +4 -4
- package/dist/lib/converter/plugins/GroupPlugin.js +52 -18
- package/dist/lib/converter/plugins/ImplementsPlugin.js +4 -3
- package/dist/lib/converter/plugins/InheritDocPlugin.d.ts +1 -1
- package/dist/lib/converter/plugins/InheritDocPlugin.js +5 -6
- package/dist/lib/converter/plugins/LinkResolverPlugin.d.ts +2 -2
- package/dist/lib/converter/plugins/PackagePlugin.d.ts +0 -2
- package/dist/lib/converter/plugins/PackagePlugin.js +8 -30
- package/dist/lib/converter/plugins/SourcePlugin.js +2 -2
- package/dist/lib/converter/symbols.js +31 -11
- package/dist/lib/converter/types.d.ts +1 -1
- package/dist/lib/converter/types.js +11 -6
- package/dist/lib/converter/utils/nodes.js +3 -4
- package/dist/lib/converter/utils/reflections.d.ts +1 -1
- package/dist/lib/converter/utils/reflections.js +1 -2
- package/dist/lib/converter/utils/repository.js +9 -7
- package/dist/lib/converter/utils/symbols.js +1 -2
- package/dist/lib/internationalization/index.d.ts +7 -0
- package/dist/lib/internationalization/index.js +11 -0
- package/dist/lib/internationalization/internationalization.d.ts +92 -0
- package/dist/lib/internationalization/internationalization.js +194 -0
- package/dist/lib/internationalization/locales/en.cjs +3 -0
- package/dist/lib/internationalization/locales/en.d.cts +2 -0
- package/dist/lib/internationalization/locales/test.cjs +8 -0
- package/dist/lib/internationalization/locales/test.d.cts +5 -0
- package/dist/lib/internationalization/translatable.d.ts +297 -0
- package/dist/lib/internationalization/translatable.js +322 -0
- package/dist/lib/models/ReflectionCategory.d.ts +2 -2
- package/dist/lib/models/ReflectionGroup.d.ts +2 -2
- package/dist/lib/models/comments/comment.d.ts +17 -3
- package/dist/lib/models/comments/comment.js +377 -298
- package/dist/lib/models/reflections/ReflectionSymbolId.js +2 -2
- package/dist/lib/models/reflections/abstract.d.ts +11 -8
- package/dist/lib/models/reflections/abstract.js +17 -11
- package/dist/lib/models/reflections/container.d.ts +25 -3
- package/dist/lib/models/reflections/container.js +64 -0
- package/dist/lib/models/reflections/declaration.d.ts +3 -15
- package/dist/lib/models/reflections/declaration.js +16 -21
- package/dist/lib/models/reflections/document.d.ts +27 -0
- package/dist/lib/models/reflections/document.js +43 -0
- package/dist/lib/models/reflections/index.d.ts +4 -3
- package/dist/lib/models/reflections/index.js +5 -4
- package/dist/lib/models/reflections/kind.d.ts +13 -1
- package/dist/lib/models/reflections/kind.js +12 -0
- package/dist/lib/models/reflections/parameter.d.ts +1 -1
- package/dist/lib/models/reflections/project.d.ts +2 -2
- package/dist/lib/models/reflections/project.js +8 -7
- package/dist/lib/models/reflections/signature.d.ts +2 -2
- package/dist/lib/models/reflections/type-parameter.d.ts +1 -1
- package/dist/lib/models/reflections/utils.js +1 -2
- package/dist/lib/models/reflections/variant.d.ts +2 -0
- package/dist/lib/models/types.d.ts +4 -4
- package/dist/lib/models/types.js +3 -3
- package/dist/lib/output/events.d.ts +5 -5
- package/dist/lib/output/events.js +2 -1
- package/dist/lib/output/index.d.ts +1 -1
- package/dist/lib/output/index.js +2 -1
- package/dist/lib/output/plugins/AssetsPlugin.js +1 -1
- package/dist/lib/output/plugins/JavascriptIndexPlugin.d.ts +3 -1
- package/dist/lib/output/plugins/JavascriptIndexPlugin.js +28 -8
- package/dist/lib/output/plugins/SitemapPlugin.d.ts +1 -1
- package/dist/lib/output/plugins/SitemapPlugin.js +24 -13
- package/dist/lib/output/renderer.d.ts +9 -1
- package/dist/lib/output/renderer.js +5 -7
- package/dist/lib/output/themes/MarkedPlugin.d.ts +13 -24
- package/dist/lib/output/themes/MarkedPlugin.js +75 -160
- package/dist/lib/output/themes/default/DefaultTheme.d.ts +16 -4
- package/dist/lib/output/themes/default/DefaultTheme.js +62 -16
- package/dist/lib/output/themes/default/DefaultThemeRenderContext.d.ts +44 -44
- package/dist/lib/output/themes/default/DefaultThemeRenderContext.js +10 -10
- package/dist/lib/output/themes/default/layouts/default.js +1 -1
- package/dist/lib/output/themes/default/partials/analytics.js +1 -2
- package/dist/lib/output/themes/default/partials/anchor-icon.js +2 -3
- package/dist/lib/output/themes/default/partials/comment.d.ts +1 -1
- package/dist/lib/output/themes/default/partials/comment.js +3 -4
- package/dist/lib/output/themes/default/partials/footer.js +22 -7
- package/dist/lib/output/themes/default/partials/header.d.ts +1 -1
- package/dist/lib/output/themes/default/partials/header.js +4 -3
- package/dist/lib/output/themes/default/partials/hierarchy.js +3 -4
- package/dist/lib/output/themes/default/partials/icon.js +7 -2
- package/dist/lib/output/themes/default/partials/index.js +4 -4
- package/dist/lib/output/themes/default/partials/member.d.ts +2 -2
- package/dist/lib/output/themes/default/partials/member.declaration.js +2 -3
- package/dist/lib/output/themes/default/partials/member.js +13 -2
- package/dist/lib/output/themes/default/partials/member.reference.d.ts +1 -1
- package/dist/lib/output/themes/default/partials/member.reference.js +9 -6
- package/dist/lib/output/themes/default/partials/member.signature.body.d.ts +1 -1
- package/dist/lib/output/themes/default/partials/member.signature.body.js +4 -4
- package/dist/lib/output/themes/default/partials/member.signature.title.d.ts +1 -1
- package/dist/lib/output/themes/default/partials/member.signature.title.js +1 -2
- package/dist/lib/output/themes/default/partials/member.sources.js +12 -6
- package/dist/lib/output/themes/default/partials/members.d.ts +1 -1
- package/dist/lib/output/themes/default/partials/members.group.js +1 -2
- package/dist/lib/output/themes/default/partials/members.js +1 -2
- package/dist/lib/output/themes/default/partials/navigation.d.ts +1 -1
- package/dist/lib/output/themes/default/partials/navigation.js +18 -15
- package/dist/lib/output/themes/default/partials/parameter.d.ts +1 -1
- package/dist/lib/output/themes/default/partials/parameter.js +15 -15
- package/dist/lib/output/themes/default/partials/reflectionPreview.js +1 -2
- package/dist/lib/output/themes/default/partials/toolbar.js +4 -4
- package/dist/lib/output/themes/default/partials/type.d.ts +1 -1
- package/dist/lib/output/themes/default/partials/type.js +14 -14
- package/dist/lib/output/themes/default/partials/typeAndParent.d.ts +1 -1
- package/dist/lib/output/themes/default/partials/typeParameters.js +2 -3
- package/dist/lib/output/themes/default/templates/document.d.ts +5 -0
- package/dist/lib/output/themes/default/templates/document.js +7 -0
- package/dist/lib/output/themes/default/templates/hierarchy.js +1 -2
- package/dist/lib/output/themes/default/templates/reflection.d.ts +1 -1
- package/dist/lib/output/themes/default/templates/reflection.js +21 -19
- package/dist/lib/output/themes/lib.d.ts +1 -1
- package/dist/lib/output/themes/lib.js +12 -16
- package/dist/lib/serialization/deserializer.d.ts +3 -3
- package/dist/lib/serialization/deserializer.js +7 -5
- package/dist/lib/serialization/schema.d.ts +10 -3
- package/dist/lib/utils/array.js +9 -10
- package/dist/lib/utils/component.d.ts +1 -1
- package/dist/lib/utils/component.js +2 -2
- package/dist/lib/utils/entry-point.d.ts +11 -0
- package/dist/lib/utils/entry-point.js +51 -24
- package/dist/lib/utils/enum.js +6 -7
- package/dist/lib/utils/fs.js +15 -16
- package/dist/lib/utils/general.d.ts +4 -3
- package/dist/lib/utils/general.js +4 -5
- package/dist/lib/utils/highlighter.d.ts +4 -2
- package/dist/lib/utils/highlighter.js +41 -40
- package/dist/lib/utils/html.js +2 -3
- package/dist/lib/utils/index.d.ts +1 -1
- package/dist/lib/utils/index.js +1 -2
- package/dist/lib/utils/jsx.elements.d.ts +12 -0
- package/dist/lib/utils/jsx.js +4 -4
- package/dist/lib/utils/loggers.d.ts +13 -7
- package/dist/lib/utils/loggers.js +13 -10
- package/dist/lib/utils/map.d.ts +1 -1
- package/dist/lib/utils/map.js +1 -1
- package/dist/lib/utils/options/declaration.d.ts +40 -21
- package/dist/lib/utils/options/declaration.js +36 -36
- package/dist/lib/utils/options/help.d.ts +2 -1
- package/dist/lib/utils/options/help.js +10 -10
- package/dist/lib/utils/options/index.d.ts +1 -1
- package/dist/lib/utils/options/index.js +1 -2
- package/dist/lib/utils/options/options.d.ts +5 -34
- package/dist/lib/utils/options/options.js +10 -23
- package/dist/lib/utils/options/readers/arguments.js +3 -5
- package/dist/lib/utils/options/readers/package-json.js +2 -2
- package/dist/lib/utils/options/readers/tsconfig.js +8 -12
- package/dist/lib/utils/options/readers/typedoc.js +7 -6
- package/dist/lib/utils/options/sources/typedoc.js +187 -178
- package/dist/lib/utils/options/tsdoc-defaults.d.ts +1 -1
- package/dist/lib/utils/options/tsdoc-defaults.js +2 -0
- package/dist/lib/utils/package-manifest.d.ts +1 -1
- package/dist/lib/utils/package-manifest.js +9 -11
- package/dist/lib/utils/paths.js +4 -5
- package/dist/lib/utils/perf.js +3 -4
- package/dist/lib/utils/plugins.js +4 -5
- package/dist/lib/utils/reflections.d.ts +1 -1
- package/dist/lib/utils/reflections.js +2 -3
- package/dist/lib/utils/sort.d.ts +3 -2
- package/dist/lib/utils/sort.js +37 -6
- package/dist/lib/utils/tsconfig.js +3 -4
- package/dist/lib/utils/tsutils.js +2 -3
- package/dist/lib/utils/validation.js +4 -4
- package/dist/lib/validation/documentation.d.ts +1 -1
- package/dist/lib/validation/documentation.js +9 -4
- package/dist/lib/validation/exports.js +3 -5
- package/dist/lib/validation/links.js +2 -3
- package/package.json +14 -13
- package/static/main.js +4 -4
- package/static/style.css +21 -16
- package/tsdoc.json +9 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GitRepository = exports.AssumedRepository = void 0;
|
|
4
|
+
exports.gitIsInstalled = gitIsInstalled;
|
|
5
|
+
exports.guessSourceUrlTemplate = guessSourceUrlTemplate;
|
|
4
6
|
const child_process_1 = require("child_process");
|
|
5
7
|
const base_path_1 = require("../utils/base-path");
|
|
6
8
|
const TEN_MEGABYTES = 1024 * 10000;
|
|
@@ -16,7 +18,6 @@ function gitIsInstalled() {
|
|
|
16
18
|
haveGit ??= git("--version").status === 0;
|
|
17
19
|
return haveGit;
|
|
18
20
|
}
|
|
19
|
-
exports.gitIsInstalled = gitIsInstalled;
|
|
20
21
|
class AssumedRepository {
|
|
21
22
|
constructor(path, gitRevision, sourceLinkTemplate) {
|
|
22
23
|
this.path = path;
|
|
@@ -26,10 +27,11 @@ class AssumedRepository {
|
|
|
26
27
|
getURL(fileName, line) {
|
|
27
28
|
const replacements = {
|
|
28
29
|
gitRevision: this.gitRevision,
|
|
30
|
+
"gitRevision:short": this.gitRevision.substring(0, 8),
|
|
29
31
|
path: fileName.substring(this.path.length + 1),
|
|
30
32
|
line,
|
|
31
33
|
};
|
|
32
|
-
return this.sourceLinkTemplate.replace(/\{(gitRevision|path|line)\}/g, (_, key) => replacements[key]);
|
|
34
|
+
return this.sourceLinkTemplate.replace(/\{(gitRevision|gitRevision:short|path|line)\}/g, (_, key) => replacements[key]);
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
exports.AssumedRepository = AssumedRepository;
|
|
@@ -71,10 +73,11 @@ class GitRepository {
|
|
|
71
73
|
}
|
|
72
74
|
const replacements = {
|
|
73
75
|
gitRevision: this.gitRevision,
|
|
76
|
+
"gitRevision:short": this.gitRevision.substring(0, 8),
|
|
74
77
|
path: fileName.substring(this.path.length + 1),
|
|
75
78
|
line,
|
|
76
79
|
};
|
|
77
|
-
return this.urlTemplate.replace(/\{(gitRevision|path|line)\}/g, (_, key) => replacements[key]);
|
|
80
|
+
return this.urlTemplate.replace(/\{(gitRevision|gitRevision:short|path|line)\}/g, (_, key) => replacements[key]);
|
|
78
81
|
}
|
|
79
82
|
/**
|
|
80
83
|
* Try to create a new repository instance.
|
|
@@ -89,7 +92,7 @@ class GitRepository {
|
|
|
89
92
|
const topLevel = git("-C", path, "rev-parse", "--show-toplevel");
|
|
90
93
|
if (topLevel.status !== 0)
|
|
91
94
|
return;
|
|
92
|
-
gitRevision ||= git("-C", path, "rev-parse", "
|
|
95
|
+
gitRevision ||= git("-C", path, "rev-parse", "HEAD").stdout.trim();
|
|
93
96
|
if (!gitRevision)
|
|
94
97
|
return; // Will only happen in a repo with no commits.
|
|
95
98
|
let urlTemplate;
|
|
@@ -102,7 +105,7 @@ class GitRepository {
|
|
|
102
105
|
urlTemplate = guessSourceUrlTemplate(remotesOut.stdout.split("\n"));
|
|
103
106
|
}
|
|
104
107
|
else {
|
|
105
|
-
logger.warn(
|
|
108
|
+
logger.warn(logger.i18n.git_remote_0_not_valid(gitRemote));
|
|
106
109
|
}
|
|
107
110
|
}
|
|
108
111
|
if (!urlTemplate)
|
|
@@ -154,4 +157,3 @@ function guessSourceUrlTemplate(remotes) {
|
|
|
154
157
|
}
|
|
155
158
|
return `https://${hostname}/${user}/${project}/${sourcePath}/{gitRevision}/{path}#${anchorPrefix}{line}`;
|
|
156
159
|
}
|
|
157
|
-
exports.guessSourceUrlTemplate = guessSourceUrlTemplate;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.resolveAliasedSymbol =
|
|
6
|
+
exports.resolveAliasedSymbol = resolveAliasedSymbol;
|
|
7
7
|
const typescript_1 = __importDefault(require("typescript"));
|
|
8
8
|
function resolveAliasedSymbol(symbol, checker) {
|
|
9
9
|
const seen = new Set();
|
|
@@ -16,4 +16,3 @@ function resolveAliasedSymbol(symbol, checker) {
|
|
|
16
16
|
}
|
|
17
17
|
return symbol;
|
|
18
18
|
}
|
|
19
|
-
exports.resolveAliasedSymbol = resolveAliasedSymbol;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internationalization module, see {@link "Adding Locales" | Adding Locales} for details on extending TypeDoc.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
* @document ../../../internal-docs/internationalization.md
|
|
6
|
+
*/
|
|
7
|
+
export { type TranslatableStrings, Internationalization, type TranslatedString, type TranslationProxy, } from "./internationalization";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Internationalization = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Internationalization module, see {@link "Adding Locales" | Adding Locales} for details on extending TypeDoc.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
* @document ../../../internal-docs/internationalization.md
|
|
9
|
+
*/
|
|
10
|
+
var internationalization_1 = require("./internationalization");
|
|
11
|
+
Object.defineProperty(exports, "Internationalization", { enumerable: true, get: function () { return internationalization_1.Internationalization; } });
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Application } from "../application";
|
|
2
|
+
import { type BuiltinTranslatableStringArgs } from "./translatable";
|
|
3
|
+
import { ReflectionKind } from "../models/reflections/kind";
|
|
4
|
+
/**
|
|
5
|
+
* ### What is translatable?
|
|
6
|
+
* TypeDoc includes a lot of literal strings. By convention, messages which are displayed
|
|
7
|
+
* to the user at the INFO level or above should be present in this object to be available
|
|
8
|
+
* for translation. Messages at the VERBOSE level need not be translated as they are primarily
|
|
9
|
+
* intended for debugging. ERROR/WARNING deprecation messages related to TypeDoc's API, or
|
|
10
|
+
* requesting users submit a bug report need not be translated.
|
|
11
|
+
*
|
|
12
|
+
* Errors thrown by TypeDoc are generally *not* considered translatable as they are not
|
|
13
|
+
* displayed to the user. An exception to this is errors thrown by the `validate` method
|
|
14
|
+
* on options, as option readers will use them to report errors to the user.
|
|
15
|
+
*
|
|
16
|
+
* ### Interface Keys
|
|
17
|
+
* This object uses a similar convention as TypeScript, where the specified key should
|
|
18
|
+
* indicate where placeholders are present by including a number in the name. This is
|
|
19
|
+
* so that translations can easily tell that they are including the appropriate placeholders.
|
|
20
|
+
* This will also be validated at runtime by the {@link Internationalization} class, but
|
|
21
|
+
* it's better to have that hint when editing as well.
|
|
22
|
+
*
|
|
23
|
+
* This interface defines the available translatable strings, and the number of placeholders
|
|
24
|
+
* that are required to use each string. Plugins may use declaration merging to add members
|
|
25
|
+
* to this interface to use TypeDoc's internationalization module.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* declare module "typedoc" {
|
|
30
|
+
* interface TranslatableStrings {
|
|
31
|
+
* // Define a translatable string with no arguments
|
|
32
|
+
* plugin_msg: [];
|
|
33
|
+
* // Define a translatable string requiring one argument
|
|
34
|
+
* plugin_msg_0: [string];
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export interface TranslatableStrings extends BuiltinTranslatableStringArgs {
|
|
40
|
+
}
|
|
41
|
+
declare const TranslatedString: unique symbol;
|
|
42
|
+
export type TranslatedString = string & {
|
|
43
|
+
[TranslatedString]: true;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Dynamic proxy type built from {@link TranslatableStrings}
|
|
47
|
+
*/
|
|
48
|
+
export type TranslationProxy = {
|
|
49
|
+
[K in keyof TranslatableStrings]: (...args: TranslatableStrings[K]) => TranslatedString;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Simple internationalization module which supports placeholders.
|
|
53
|
+
* See {@link TranslatableStrings} for a description of how this module works and how
|
|
54
|
+
* plugins should add translations.
|
|
55
|
+
*/
|
|
56
|
+
export declare class Internationalization {
|
|
57
|
+
private application;
|
|
58
|
+
private allTranslations;
|
|
59
|
+
/**
|
|
60
|
+
* Proxy object which supports dynamically translating
|
|
61
|
+
* all supported keys. This is generally used rather than the translate
|
|
62
|
+
* method so that renaming a key on the `translatable` object that contains
|
|
63
|
+
* all of the default translations will automatically update usage locations.
|
|
64
|
+
*/
|
|
65
|
+
proxy: TranslationProxy;
|
|
66
|
+
/**
|
|
67
|
+
* If constructed without an application, will use the default language.
|
|
68
|
+
* Intended for use in unit tests only.
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
constructor(application: Application | null);
|
|
72
|
+
/**
|
|
73
|
+
* Get the translation of the specified key, replacing placeholders
|
|
74
|
+
* with the arguments specified.
|
|
75
|
+
*/
|
|
76
|
+
translate<T extends keyof TranslatableStrings>(key: T, ...args: TranslatableStrings[T]): TranslatedString;
|
|
77
|
+
kindSingularString(kind: ReflectionKind): TranslatedString;
|
|
78
|
+
kindPluralString(kind: ReflectionKind): TranslatedString;
|
|
79
|
+
/**
|
|
80
|
+
* Add translations for a string which will be displayed to the user.
|
|
81
|
+
*/
|
|
82
|
+
addTranslations(lang: string, translations: Partial<Record<keyof TranslatableStrings, string>>, override?: boolean): void;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if we have any translations in the specified language.
|
|
85
|
+
*/
|
|
86
|
+
hasTranslations(lang: string): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Gets a list of all languages with at least one translation.
|
|
89
|
+
*/
|
|
90
|
+
getSupportedLanguages(): string[];
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Internationalization = void 0;
|
|
4
|
+
const assert_1 = require("assert");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const translatable_1 = require("./translatable");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const kind_1 = require("../models/reflections/kind");
|
|
10
|
+
// If we're running in ts-node, then we need the TS source rather than
|
|
11
|
+
// the compiled file.
|
|
12
|
+
const ext = process[Symbol.for("ts-node.register.instance")]
|
|
13
|
+
? "cts"
|
|
14
|
+
: "cjs";
|
|
15
|
+
/**
|
|
16
|
+
* Simple internationalization module which supports placeholders.
|
|
17
|
+
* See {@link TranslatableStrings} for a description of how this module works and how
|
|
18
|
+
* plugins should add translations.
|
|
19
|
+
*/
|
|
20
|
+
class Internationalization {
|
|
21
|
+
/**
|
|
22
|
+
* If constructed without an application, will use the default language.
|
|
23
|
+
* Intended for use in unit tests only.
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
constructor(application) {
|
|
27
|
+
this.application = application;
|
|
28
|
+
this.allTranslations = new utils_1.DefaultMap((lang) => {
|
|
29
|
+
// Make sure this isn't abused to load some random file by mistake
|
|
30
|
+
(0, assert_1.ok)(/^[A-Za-z-]+$/.test(lang), "Locale names may only contain letters and dashes");
|
|
31
|
+
try {
|
|
32
|
+
return new Map(
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
34
|
+
Object.entries(require(`./locales/${lang}.${ext}`)));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return new Map();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Proxy object which supports dynamically translating
|
|
42
|
+
* all supported keys. This is generally used rather than the translate
|
|
43
|
+
* method so that renaming a key on the `translatable` object that contains
|
|
44
|
+
* all of the default translations will automatically update usage locations.
|
|
45
|
+
*/
|
|
46
|
+
this.proxy = new Proxy(this, {
|
|
47
|
+
get(internationalization, key) {
|
|
48
|
+
return (...args) => internationalization.translate(key, ...args);
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get the translation of the specified key, replacing placeholders
|
|
54
|
+
* with the arguments specified.
|
|
55
|
+
*/
|
|
56
|
+
translate(key, ...args) {
|
|
57
|
+
return (this.allTranslations.get(this.application?.lang ?? "en").get(key) ??
|
|
58
|
+
translatable_1.translatable[key] ??
|
|
59
|
+
key).replace(/\{(\d+)\}/g, (_, index) => {
|
|
60
|
+
return args[+index] ?? "(no placeholder)";
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
kindSingularString(kind) {
|
|
64
|
+
switch (kind) {
|
|
65
|
+
case kind_1.ReflectionKind.Project:
|
|
66
|
+
return this.proxy.kind_project();
|
|
67
|
+
case kind_1.ReflectionKind.Module:
|
|
68
|
+
return this.proxy.kind_module();
|
|
69
|
+
case kind_1.ReflectionKind.Namespace:
|
|
70
|
+
return this.proxy.kind_namespace();
|
|
71
|
+
case kind_1.ReflectionKind.Enum:
|
|
72
|
+
return this.proxy.kind_enum();
|
|
73
|
+
case kind_1.ReflectionKind.EnumMember:
|
|
74
|
+
return this.proxy.kind_enum_member();
|
|
75
|
+
case kind_1.ReflectionKind.Variable:
|
|
76
|
+
return this.proxy.kind_variable();
|
|
77
|
+
case kind_1.ReflectionKind.Function:
|
|
78
|
+
return this.proxy.kind_function();
|
|
79
|
+
case kind_1.ReflectionKind.Class:
|
|
80
|
+
return this.proxy.kind_class();
|
|
81
|
+
case kind_1.ReflectionKind.Interface:
|
|
82
|
+
return this.proxy.kind_interface();
|
|
83
|
+
case kind_1.ReflectionKind.Constructor:
|
|
84
|
+
return this.proxy.kind_constructor();
|
|
85
|
+
case kind_1.ReflectionKind.Property:
|
|
86
|
+
return this.proxy.kind_property();
|
|
87
|
+
case kind_1.ReflectionKind.Method:
|
|
88
|
+
return this.proxy.kind_method();
|
|
89
|
+
case kind_1.ReflectionKind.CallSignature:
|
|
90
|
+
return this.proxy.kind_call_signature();
|
|
91
|
+
case kind_1.ReflectionKind.IndexSignature:
|
|
92
|
+
return this.proxy.kind_index_signature();
|
|
93
|
+
case kind_1.ReflectionKind.ConstructorSignature:
|
|
94
|
+
return this.proxy.kind_constructor_signature();
|
|
95
|
+
case kind_1.ReflectionKind.Parameter:
|
|
96
|
+
return this.proxy.kind_parameter();
|
|
97
|
+
case kind_1.ReflectionKind.TypeLiteral:
|
|
98
|
+
return this.proxy.kind_type_literal();
|
|
99
|
+
case kind_1.ReflectionKind.TypeParameter:
|
|
100
|
+
return this.proxy.kind_type_parameter();
|
|
101
|
+
case kind_1.ReflectionKind.Accessor:
|
|
102
|
+
return this.proxy.kind_accessor();
|
|
103
|
+
case kind_1.ReflectionKind.GetSignature:
|
|
104
|
+
return this.proxy.kind_get_signature();
|
|
105
|
+
case kind_1.ReflectionKind.SetSignature:
|
|
106
|
+
return this.proxy.kind_set_signature();
|
|
107
|
+
case kind_1.ReflectionKind.TypeAlias:
|
|
108
|
+
return this.proxy.kind_type_alias();
|
|
109
|
+
case kind_1.ReflectionKind.Reference:
|
|
110
|
+
return this.proxy.kind_reference();
|
|
111
|
+
case kind_1.ReflectionKind.Document:
|
|
112
|
+
return this.proxy.kind_document();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
kindPluralString(kind) {
|
|
116
|
+
switch (kind) {
|
|
117
|
+
case kind_1.ReflectionKind.Project:
|
|
118
|
+
return this.proxy.kind_plural_project();
|
|
119
|
+
case kind_1.ReflectionKind.Module:
|
|
120
|
+
return this.proxy.kind_plural_module();
|
|
121
|
+
case kind_1.ReflectionKind.Namespace:
|
|
122
|
+
return this.proxy.kind_plural_namespace();
|
|
123
|
+
case kind_1.ReflectionKind.Enum:
|
|
124
|
+
return this.proxy.kind_plural_enum();
|
|
125
|
+
case kind_1.ReflectionKind.EnumMember:
|
|
126
|
+
return this.proxy.kind_plural_enum_member();
|
|
127
|
+
case kind_1.ReflectionKind.Variable:
|
|
128
|
+
return this.proxy.kind_plural_variable();
|
|
129
|
+
case kind_1.ReflectionKind.Function:
|
|
130
|
+
return this.proxy.kind_plural_function();
|
|
131
|
+
case kind_1.ReflectionKind.Class:
|
|
132
|
+
return this.proxy.kind_plural_class();
|
|
133
|
+
case kind_1.ReflectionKind.Interface:
|
|
134
|
+
return this.proxy.kind_plural_interface();
|
|
135
|
+
case kind_1.ReflectionKind.Constructor:
|
|
136
|
+
return this.proxy.kind_plural_constructor();
|
|
137
|
+
case kind_1.ReflectionKind.Property:
|
|
138
|
+
return this.proxy.kind_plural_property();
|
|
139
|
+
case kind_1.ReflectionKind.Method:
|
|
140
|
+
return this.proxy.kind_plural_method();
|
|
141
|
+
case kind_1.ReflectionKind.CallSignature:
|
|
142
|
+
return this.proxy.kind_plural_call_signature();
|
|
143
|
+
case kind_1.ReflectionKind.IndexSignature:
|
|
144
|
+
return this.proxy.kind_plural_index_signature();
|
|
145
|
+
case kind_1.ReflectionKind.ConstructorSignature:
|
|
146
|
+
return this.proxy.kind_plural_constructor_signature();
|
|
147
|
+
case kind_1.ReflectionKind.Parameter:
|
|
148
|
+
return this.proxy.kind_plural_parameter();
|
|
149
|
+
case kind_1.ReflectionKind.TypeLiteral:
|
|
150
|
+
return this.proxy.kind_plural_type_literal();
|
|
151
|
+
case kind_1.ReflectionKind.TypeParameter:
|
|
152
|
+
return this.proxy.kind_plural_type_parameter();
|
|
153
|
+
case kind_1.ReflectionKind.Accessor:
|
|
154
|
+
return this.proxy.kind_plural_accessor();
|
|
155
|
+
case kind_1.ReflectionKind.GetSignature:
|
|
156
|
+
return this.proxy.kind_plural_get_signature();
|
|
157
|
+
case kind_1.ReflectionKind.SetSignature:
|
|
158
|
+
return this.proxy.kind_plural_set_signature();
|
|
159
|
+
case kind_1.ReflectionKind.TypeAlias:
|
|
160
|
+
return this.proxy.kind_plural_type_alias();
|
|
161
|
+
case kind_1.ReflectionKind.Reference:
|
|
162
|
+
return this.proxy.kind_plural_reference();
|
|
163
|
+
case kind_1.ReflectionKind.Document:
|
|
164
|
+
return this.proxy.kind_plural_document();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Add translations for a string which will be displayed to the user.
|
|
169
|
+
*/
|
|
170
|
+
addTranslations(lang, translations, override = false) {
|
|
171
|
+
const target = this.allTranslations.get(lang);
|
|
172
|
+
for (const [key, val] of Object.entries(translations)) {
|
|
173
|
+
if (!target.has(key) || override) {
|
|
174
|
+
target.set(key, val);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Checks if we have any translations in the specified language.
|
|
180
|
+
*/
|
|
181
|
+
hasTranslations(lang) {
|
|
182
|
+
return this.allTranslations.get(lang).size > 0;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Gets a list of all languages with at least one translation.
|
|
186
|
+
*/
|
|
187
|
+
getSupportedLanguages() {
|
|
188
|
+
return (0, utils_1.unique)([
|
|
189
|
+
...(0, fs_1.readdirSync)((0, path_1.join)(__dirname, "locales")).map((x) => x.substring(0, x.indexOf("."))),
|
|
190
|
+
...this.allTranslations.keys(),
|
|
191
|
+
]).sort();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.Internationalization = Internationalization;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This should go away once we have a second language in TypeDoc to use
|
|
3
|
+
// in unit tests. It's here for now so that we have *something* to test with.
|
|
4
|
+
const translatable_1 = require("../translatable");
|
|
5
|
+
module.exports = (0, translatable_1.buildIncompleteTranslation)({
|
|
6
|
+
no_entry_points_to_merge: "no_entry_points_to_merge",
|
|
7
|
+
docs_generated_at_0: "docs_generated_at_0 {0}",
|
|
8
|
+
});
|