1 | import type { Application } from "../application.js";
|
2 | import { ReflectionKind } from "../models/reflections/kind.js";
|
3 | import { ReflectionFlag } from "../models/index.js";
|
4 | import { type BuiltinTranslatableStringArgs } from "./translatable.js";
|
5 | /**
|
6 | * ### What is translatable?
|
7 | * TypeDoc includes a lot of literal strings. By convention, messages which are displayed
|
8 | * to the user at the INFO level or above should be present in this object to be available
|
9 | * for translation. Messages at the VERBOSE level need not be translated as they are primarily
|
10 | * intended for debugging. ERROR/WARNING deprecation messages related to TypeDoc's API, or
|
11 | * requesting users submit a bug report need not be translated.
|
12 | *
|
13 | * Errors thrown by TypeDoc are generally *not* considered translatable as they are not
|
14 | * displayed to the user. An exception to this is errors thrown by the `validate` method
|
15 | * on options, as option readers will use them to report errors to the user.
|
16 | *
|
17 | * ### Interface Keys
|
18 | * This object uses a similar convention as TypeScript, where the specified key should
|
19 | * indicate where placeholders are present by including a number in the name. This is
|
20 | * so that translations can easily tell that they are including the appropriate placeholders.
|
21 | * This will also be validated at runtime by the {@link Internationalization} class, but
|
22 | * it's better to have that hint when editing as well.
|
23 | *
|
24 | * This interface defines the available translatable strings, and the number of placeholders
|
25 | * that are required to use each string. Plugins may use declaration merging to add members
|
26 | * to this interface to use TypeDoc's internationalization module.
|
27 | *
|
28 | * @example
|
29 | * ```ts
|
30 | * declare module "typedoc" {
|
31 | * interface TranslatableStrings {
|
32 | * // Define a translatable string with no arguments
|
33 | * plugin_msg: [];
|
34 | * // Define a translatable string requiring one argument
|
35 | * plugin_msg_0: [string];
|
36 | * }
|
37 | * }
|
38 | * ```
|
39 | */
|
40 | export interface TranslatableStrings extends BuiltinTranslatableStringArgs {
|
41 | }
|
42 | declare const TranslatedString: unique symbol;
|
43 | export type TranslatedString = string & {
|
44 | [TranslatedString]: true;
|
45 | };
|
46 | /**
|
47 | * Dynamic proxy type built from {@link TranslatableStrings}
|
48 | */
|
49 | export type TranslationProxy = {
|
50 | [K in keyof TranslatableStrings]: (...args: TranslatableStrings[K]) => TranslatedString;
|
51 | };
|
52 | /**
|
53 | * Simple internationalization module which supports placeholders.
|
54 | * See {@link TranslatableStrings} for a description of how this module works and how
|
55 | * plugins should add translations.
|
56 | */
|
57 | export declare class Internationalization {
|
58 | private application;
|
59 | private allTranslations;
|
60 | /**
|
61 | * Proxy object which supports dynamically translating
|
62 | * all supported keys. This is generally used rather than the translate
|
63 | * method so that renaming a key on the `translatable` object that contains
|
64 | * all of the default translations will automatically update usage locations.
|
65 | */
|
66 | proxy: TranslationProxy;
|
67 | /**
|
68 | * If constructed without an application, will use the default language.
|
69 | * Intended for use in unit tests only.
|
70 | * @internal
|
71 | */
|
72 | constructor(application: Application | null);
|
73 | /**
|
74 | * Get the translation of the specified key, replacing placeholders
|
75 | * with the arguments specified.
|
76 | */
|
77 | translate<T extends keyof TranslatableStrings>(key: T, ...args: TranslatableStrings[T]): TranslatedString;
|
78 | kindSingularString(kind: ReflectionKind): TranslatedString;
|
79 | kindPluralString(kind: ReflectionKind): TranslatedString;
|
80 | flagString(flag: ReflectionFlag): TranslatedString;
|
81 | translateTagName(tag: `string}`): TranslatedString;
{ |
82 | /**
|
83 | * Add translations for a string which will be displayed to the user.
|
84 | */
|
85 | addTranslations(lang: string, translations: Partial<Record<keyof TranslatableStrings, string>>, override?: boolean): void;
|
86 | /**
|
87 | * Checks if we have any translations in the specified language.
|
88 | */
|
89 | hasTranslations(lang: string): boolean;
|
90 | /**
|
91 | * Gets a list of all languages with at least one translation.
|
92 | */
|
93 | getSupportedLanguages(): string[];
|
94 | }
|
95 | export {};
|