@transifex/native 3.1.0 → 3.2.2

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/README.md CHANGED
@@ -1,4 +1,22 @@
1
- # Transifex Native for Javascript
1
+ <p align="center">
2
+ <a href="https://www.transifex.com">
3
+ <img src="https://raw.githubusercontent.com/transifex/transifex-javascript/master/media/transifex.png" height="60">
4
+ </a>
5
+ </p>
6
+ <p align="center">
7
+ <i>Transifex Native is a full end-to-end, cloud-based localization stack for moderns apps.</i>
8
+ </p>
9
+ <p align="center">
10
+ <img src="https://github.com/transifex/transifex-javascript/actions/workflows/npm-publish.yml/badge.svg">
11
+ <a href="https://www.npmjs.com/package/@transifex/native">
12
+ <img src="https://img.shields.io/npm/v/@transifex/native.svg">
13
+ </a>
14
+ <a href="https://developers.transifex.com/docs/native">
15
+ <img src="https://img.shields.io/badge/docs-transifex.com-blue">
16
+ </a>
17
+ </p>
18
+
19
+ # Transifex Native SDK: JavaScript i18n
2
20
 
3
21
  A general purpose Javascript library for localizing web apps using [Transifex Native](https://www.transifex.com/native/).
4
22
 
@@ -10,6 +28,24 @@ Related packages:
10
28
  * [@transifex/react](https://www.npmjs.com/package/@transifex/react)
11
29
  * [@transifex/cli](https://www.npmjs.com/package/@transifex/cli)
12
30
 
31
+ Learn more about Transifex Native in the [Transifex Developer Hub](https://developers.transifex.com/docs/native).
32
+
33
+ # How it works
34
+
35
+ **Step1**: Create a Transifex Native project in [Transifex](https://www.transifex.com).
36
+
37
+ **Step2**: Grab credentials.
38
+
39
+ **Step3**: Internationalize the code using the SDK.
40
+
41
+ **Step4**: Push source phrases using the `@transifex/cli` tool.
42
+
43
+ **Step5**: Translate the app using over-the-air updates.
44
+
45
+ No translation files required.
46
+
47
+ ![native](https://raw.githubusercontent.com/transifex/transifex-javascript/master/media/native.gif)
48
+
13
49
  # Upgrade to v2
14
50
 
15
51
  If you are upgrading from the `1.x.x` version, please read this [migration guide](https://github.com/transifex/transifex-javascript/blob/HEAD/UPGRADE_TO_V2.md), as there are breaking changes in place.
@@ -243,6 +279,87 @@ const html = t('<b>Hello {username}</b>', {
243
279
  });
244
280
  ```
245
281
 
282
+ ## Push source content
283
+
284
+ For server side integrations you can also push source content programmatically
285
+ without using the CLI.
286
+
287
+ ```js
288
+ tx.pushSource(payload, params): Promise
289
+ payload: Object({
290
+ key: {
291
+ string: String,
292
+ meta: {
293
+ context: String,
294
+ developer_comment: String,
295
+ character_limit: Number,
296
+ tags: Array(String),
297
+ occurrences: Array(String),
298
+ },
299
+ },
300
+ key: { .. }
301
+ })
302
+ params: Object({
303
+ // Replace the entire resource content with the pushed content of this request
304
+ purge: Boolean,
305
+
306
+ // Replace the existing string tags with the tags of this request
307
+ overrideTags: Boolean,
308
+
309
+ // If true, when wait for processing to be complete before
310
+ // resolving this promise
311
+ noWait: Boolean,
312
+ })
313
+ ```
314
+
315
+ For example:
316
+
317
+ ```js
318
+ const { createNativeInstance } = require('@transifex/native');
319
+
320
+ const tx = createNativeInstance({
321
+ token: 'token',
322
+ secret: 'secret',
323
+ });
324
+
325
+ await tx.pushSource({
326
+ 'mykey': {
327
+ string: 'My string',
328
+ meta: {
329
+ context: 'content', // optional
330
+ developer_comment: 'developer comment', // optional
331
+ character_limit: 10, // optional
332
+ tags: ['tag1', 'tag2'], // optional
333
+ occurrences: ['file.jsx', 'file2.js'], // optional
334
+ },
335
+ }
336
+ });
337
+ ```
338
+
339
+ ## Invalidate CDS cache
340
+
341
+ Server side integrations can also invalidate the CDS cache programmatically.
342
+
343
+ ```js
344
+ tx.invalidateCDS({
345
+ // if true, then purge the cache entirely (not recommended)
346
+ purge: Boolean,
347
+ }): Promise
348
+ ```
349
+
350
+ For example:
351
+
352
+ ```js
353
+ const { createNativeInstance } = require('@transifex/native');
354
+
355
+ const tx = createNativeInstance({
356
+ token: 'token',
357
+ secret: 'secret',
358
+ });
359
+
360
+ await tx.invalidateCDS();
361
+ ```
362
+
246
363
  ## Events
247
364
 
248
365
  Library for listening to various async events.