@transifex/native 5.0.7 → 5.1.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transifex/native",
3
- "version": "5.0.7",
3
+ "version": "5.1.1",
4
4
  "description": "i18n framework using Transifex Native",
5
5
  "keywords": [
6
6
  "transifex",
package/src/index.d.ts CHANGED
@@ -1,32 +1,197 @@
1
1
  declare module '@transifex/native' {
2
- export const tx: any;
3
- export const t: any;
4
- export const PseudoTranslationPolicy: any;
5
- export const SourceStringPolicy: any;
6
- export const SourceErrorPolicy: any;
7
- export const ThrowErrorPolicy: any;
8
- export const MessageFormatRenderer: any;
9
- export const createNativeInstance: any;
10
-
11
- // Events
2
+ export interface ITranslateParams {
3
+ [key: string]: unknown;
4
+ _charlimit?: number;
5
+ _comment?: string;
6
+ _context?: string;
7
+ _escapeVars?: boolean;
8
+ _key?: string;
9
+ _tags?: string;
10
+ }
11
+
12
+ export interface ITranslationConfig {
13
+ cache?: IMemoryCache;
14
+ cdsHost?: string;
15
+ currentLocale?: string;
16
+ errorPolicy?: IErrorPolicy;
17
+ fetchInterval?: number;
18
+ fetchTimeout?: number;
19
+ filterStatus?: string;
20
+ filterTags?: string;
21
+ missingPolicy?: ITranslationPolicy;
22
+ secret?: string;
23
+ stringRenderer?: IMessageFormatRenderer;
24
+ token?: string;
25
+ }
26
+
27
+ type Plurals = [string, Record<string, string>];
28
+
29
+ interface ILanguage {
30
+ code: string;
31
+ localized_name: string;
32
+ name: string;
33
+ rtl: boolean;
34
+ }
35
+
36
+ interface IMemoryCache {
37
+ get(key: string, localeCode: string): Record<string, string>;
38
+ getTranslations(localeCode: string): Record<string, string>;
39
+ hasTranslations(localeCode: string): boolean;
40
+ isStale(localeCode: string): boolean;
41
+ update(localeCode: string, translations: Record<string, string>): void;
42
+ }
43
+
44
+ interface IMessageFormatRenderer {
45
+ render(sourceString: string, localeCode: string, params: ITranslateParams): string;
46
+ }
47
+
48
+ interface ITranslationPolicy {
49
+ handle(sourceString: string, localeCode: string): string;
50
+ }
51
+
52
+ interface IErrorPolicy {
53
+ handle(error: Error, sourceString: string, localeCode: string, params: ITranslateParams): string;
54
+ }
55
+
56
+ export class TxNative implements ITranslationConfig {
57
+ cache: IMemoryCache;
58
+ cdsHost: string;
59
+ childInstances: TxNative[];
60
+ currentLocale: string;
61
+ errorPolicy: IErrorPolicy;
62
+ fetchedTags?: Record<string, string[]>;
63
+ fetchInterval: number;
64
+ fetchTimeout: number;
65
+ filterStatus: string;
66
+ filterTags: string;
67
+ languages: ILanguage[];
68
+ locales: string[];
69
+ missingPolicy: ITranslationPolicy;
70
+ secret: string;
71
+ stringRenderer: IMessageFormatRenderer;
72
+ token: string;
73
+
74
+ controllerOf(instance: TxNative): Promise<TxNative>;
75
+
76
+ fetchTranslations(localeCode: string, config?: { filterTags?: string; refresh?: boolean }): Promise<void>;
77
+
78
+ getCurrentLocale(): string;
79
+
80
+ getLanguages(config?: { refresh?: boolean }): Promise<ILanguage[]>;
81
+
82
+ getLocales(config?: { refresh?: boolean }): Promise<string[]>;
83
+
84
+ init(config: ITranslationConfig): void;
85
+
86
+ invalidateCDS(config?: { purge?: boolean }): Promise<{ count: number; status: number; token: number }>;
87
+
88
+ isCurrent(localeCode: string): boolean;
89
+
90
+ pushSource(
91
+ payload: Record<string, {
92
+ meta: {
93
+ character_limit: number;
94
+ context: string;
95
+ developer_comment: string;
96
+ occurrences: string[];
97
+ tags: string[];
98
+ };
99
+ string: string;
100
+ }>,
101
+ config?: { noWait: boolean; overrideTags: boolean; purge: boolean }
102
+ ): Promise<{
103
+ created: number;
104
+ deleted: number;
105
+ errors: string[];
106
+ failed: number;
107
+ jobUrl: string;
108
+ skipped: number;
109
+ status: string;
110
+ updated: number;
111
+ }>;
112
+
113
+ setCurrentLocale(localeCode: string): Promise<void>;
114
+
115
+ translate(sourceString: string, params?: ITranslateParams): string;
116
+
117
+ translateLocale(localeCode: string, sourceString: string, params?: ITranslateParams): string;
118
+ }
119
+
120
+ export class MessageFormatRenderer implements IMessageFormatRenderer {
121
+ render(sourceString: string, localeCode: string, params: ITranslateParams): string;
122
+ }
123
+
124
+ export class PseudoTranslationPolicy implements ITranslationPolicy {
125
+ handle(sourceString: string, _localeCode: string): string;
126
+ }
127
+
128
+ export class SourceErrorPolicy implements IErrorPolicy {
129
+ handle(_error: Error, sourceString: string, _localeCode: string, _params: ITranslateParams): string;
130
+ }
131
+
132
+ export class SourceStringPolicy implements ITranslationPolicy {
133
+ handle(sourceString: string, _localeCode: string): string;
134
+ }
135
+
136
+ export class ThrowErrorPolicy implements IErrorPolicy {
137
+ handle(error: Error, sourceString: string, _localeCode: string, _params: ITranslateParams): never;
138
+ }
139
+
12
140
  export const FETCHING_TRANSLATIONS = 'FETCHING_TRANSLATIONS';
141
+
13
142
  export const TRANSLATIONS_FETCHED = 'TRANSLATIONS_FETCHED';
143
+
14
144
  export const TRANSLATIONS_FETCH_FAILED = 'TRANSLATIONS_FETCH_FAILED';
145
+
15
146
  export const LOCALE_CHANGED = 'LOCALE_CHANGED';
147
+
16
148
  export const FETCHING_LOCALES = 'FETCHING_LOCALES';
149
+
17
150
  export const LOCALES_FETCHED = 'LOCALES_FETCHED';
151
+
18
152
  export const LOCALES_FETCH_FAILED = 'LOCALES_FETCH_FAILED';
19
- export const onEvent: any;
20
- export const offEvent: any;
21
- export const sendEvent: any;
22
-
23
- // Utils
24
- export const escape: any;
25
- export const isString: any;
26
- export const generateHashedKey: any;
27
- export const generateKey: any;
28
- export const isPluralized: any;
29
- export const explodePlurals: any;
30
- export const implodePlurals: any;
31
- export const normalizeLocale: any;
153
+
154
+ type EventTypes =
155
+ | typeof FETCHING_LOCALES
156
+ | typeof FETCHING_TRANSLATIONS
157
+ | typeof LOCALE_CHANGED
158
+ | typeof LOCALES_FETCH_FAILED
159
+ | typeof LOCALES_FETCHED
160
+ | typeof TRANSLATIONS_FETCH_FAILED
161
+ | typeof TRANSLATIONS_FETCHED;
162
+
163
+ interface EventPayload {
164
+ filterTags: string;
165
+ localeCode: string;
166
+ }
167
+
168
+ export function createNativeInstance(initOptions: ITranslationConfig): TxNative;
169
+
170
+ export function escape(unsafe: string): string;
171
+
172
+ export function explodePlurals(str: string): Plurals;
173
+
174
+ export function generateHashedKey(str: string, options?: { _context?: string; _key?: string }): string;
175
+
176
+ export function generateKey(str: string, options?: { _context?: string; _key?: string }): string;
177
+
178
+ export function implodePlurals(plurals: Plurals, count: string): string;
179
+
180
+ export function isPluralized(str: string): boolean;
181
+
182
+ export function isString(obj: unknown): boolean;
183
+
184
+ export function normalizeLocale(locale: string): string;
185
+
186
+ export function offEvent(eventType: EventTypes, fn: (payload: EventPayload | null, caller: TxNative) => void): void;
187
+
188
+ export function onEvent(eventType: EventTypes, fn: (payload: EventPayload | null, caller: TxNative) => void): void;
189
+
190
+ export function sendEvent(eventType: EventTypes, payload: EventPayload | null, caller: TxNative): void;
191
+
192
+ export function sleep(msec: number): Promise<void>;
193
+
194
+ export function t(str: string, params?: ITranslateParams): string;
195
+
196
+ export const tx: TxNative;
32
197
  }