-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
base.ts
94 lines (79 loc) · 2.2 KB
/
base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { Gettext } from './gettext';
import { ITranslator, TranslationBundle } from './tokens';
/**
* A translator that loads a dummy language bundle that returns the same input
* strings.
*/
export class NullTranslator implements ITranslator {
constructor(bundle: TranslationBundle) {
this._languageBundle = bundle;
}
readonly languageCode: string = 'en';
load(domain: string): TranslationBundle {
return this._languageBundle;
}
private _languageBundle: TranslationBundle;
}
/**
* A language bundle that returns the same input strings.
*/
class NullLanguageBundle {
__(msgid: string, ...args: any[]): string {
return this.gettext(msgid, ...args);
}
_n(msgid: string, msgid_plural: string, n: number, ...args: any[]): string {
return this.ngettext(msgid, msgid_plural, n, ...args);
}
_p(msgctxt: string, msgid: string, ...args: any[]): string {
return this.pgettext(msgctxt, msgid, ...args);
}
_np(
msgctxt: string,
msgid: string,
msgid_plural: string,
n: number,
...args: any[]
): string {
return this.npgettext(msgctxt, msgid, msgid_plural, n, ...args);
}
gettext(msgid: string, ...args: any[]): string {
return Gettext.strfmt(msgid, ...args);
}
ngettext(
msgid: string,
msgid_plural: string,
n: number,
...args: any[]
): string {
return Gettext.strfmt(n == 1 ? msgid : msgid_plural, ...[n].concat(args));
}
pgettext(msgctxt: string, msgid: string, ...args: any[]): string {
return Gettext.strfmt(msgid, ...args);
}
npgettext(
msgctxt: string,
msgid: string,
msgid_plural: string,
n: number,
...args: any[]
): string {
return this.ngettext(msgid, msgid_plural, n, ...args);
}
dcnpgettext(
domain: string,
msgctxt: string,
msgid: string,
msgid_plural: string,
n: number,
...args: any[]
): string {
return this.ngettext(msgid, msgid_plural, n, ...args);
}
}
/**
* The application null translator instance that just returns the same text.
* Also provides interpolation.
*/
export const nullTranslator = new NullTranslator(new NullLanguageBundle());