Client API
Constructor
create(options) async function
Fetch the metafile and create a new CDN client instance.
import { CdnClient } from '@localazy/cdn-client';
const cdn = await CdnClient.create({
metafile: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0.v2.json',
});
2
3
4
5
Parameters
Name | Type | Description |
---|---|---|
options | CdnClientOptions | CDN client options. |
Returns
Type | Description |
---|---|
Promise<CdnClient > | CDN client instance. |
NOTE
Metafile is fetched only once and then cached. If you want to refresh the metafile, use the metafile.refresh()
function.
Locales
metafile.locales(options?) function
Get all project locales.
import { CdnClient } from '@localazy/cdn-client';
const cdn = await CdnClient.create({
metafile: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0.v2.json',
});
const result = cdn.metafile.locales();
2
3
4
5
6
7
example result
const result = [
{
locale: 'en',
isBaseLocale: true,
language: 'en',
region: '',
script: '',
isRtl: false,
name: 'English',
localizedName: 'English',
},
{
locale: 'ms_BN',
isBaseLocale: false,
language: 'ms',
region: 'BN',
script: '',
isRtl: false,
name: 'Malay (Brunei)',
localizedName: 'Malay (Brunei)',
},
{
locale: 'ms#Arab',
isBaseLocale: false,
language: 'ms',
region: '',
script: 'Arab',
isRtl: false,
name: 'Malay (Arabic)',
localizedName: 'Malay (Arabic)',
},
{
locale: 'ms_ID#Latn',
isBaseLocale: false,
language: 'ms',
region: 'ID',
script: 'Latn',
isRtl: false,
name: 'Malay (Indonesia, Latin)',
localizedName: 'Malay (Indonesia, Latin)',
},
];
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
Parameters
Name | Type | Description |
---|---|---|
options optional | CdnLocalesOptions | Locales options. |
Returns
Type | Description |
---|---|
CdnLocale[] | Project locales. |
metafile.baseLocale accessor
Get the base locale of the project.
import { CdnClient } from '@localazy/cdn-client';
const cdn = await CdnClient.create({
metafile: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0.v2.json',
});
const result = cdn.metafile.baseLocale;
2
3
4
5
6
7
example result
const result = {
locale: 'en',
isBaseLocale: true,
language: 'en',
region: '',
script: '',
isRtl: false,
name: 'English',
localizedName: 'English',
};
2
3
4
5
6
7
8
9
10
Returns
Type | Description |
---|---|
CdnLocale | Base locale of the project. |
Files content
fetch(options?) async function
Get the content of the project files.
Optional parameter options.files
can be a single CdnFile
object or an array of CdnFile
objects. CdnFile
objects are returned by the metafile.files
accessor. Alternatively, it can be a single file ID or an array of file IDs. If not provided, all files are fetched.
Optional parameter options.locales
can be a single locale or an array of locales. If not provided, all locales are fetched.
import { CdnClient } from '@localazy/cdn-client';
const cdn = await CdnClient.create({
metafile: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0.v2.json',
});
const result = await cdn.fetch({
files: cdn.metafile.files[0],
locales: 'en',
});
2
3
4
5
6
7
8
9
10
example result
const result = {
cdn_info: 'With the CDN you can deliver the translation files instantly',
cdn_testing: "We're testing the CDN",
hello_localazy: 'Hello Localazy!',
using_javascript: 'In this project we decided to use JavaScript',
};
2
3
4
5
6
Parameters
Name | Type | Description |
---|---|---|
options optional | CdnFetchOptions | Options object containing selected files and locales. |
Returns
Type | Description |
---|---|
Promise<CdnResponse > | Object containing the content of the selected files and locales. |
Metafile content
metafile.files accessor
Get all project files.
import { CdnClient } from '@localazy/cdn-client';
const cdn = await CdnClient.create({
metafile: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0.v2.json',
});
const result = cdn.metafile.files;
2
3
4
5
6
7
example result
const result = [
{
id: 'dfe5b84c1598c8c56b6f1a11efcd483bb3f417ea',
file: 'file.json',
path: '',
library: '',
module: '',
buildType: '',
productFlavors: [],
locales: [
{
locale: 'en',
isBaseLocale: true,
uri: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0/dfe5b84c1598c8c56b6f1a11efcd483bb3f417ea/en/file.json',
},
{
locale: 'de',
isBaseLocale: false,
uri: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0/dfe5b84c1598c8c56b6f1a11efcd483bb3f417ea/de/file.json',
},
{
locale: 'es',
isBaseLocale: false,
uri: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0/dfe5b84c1598c8c56b6f1a11efcd483bb3f417ea/es/file.json',
},
{
locale: 'pt_PT',
isBaseLocale: false,
uri: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0/dfe5b84c1598c8c56b6f1a11efcd483bb3f417ea/pt-PT/file.json',
},
{
locale: 'vi',
isBaseLocale: false,
uri: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0/dfe5b84c1598c8c56b6f1a11efcd483bb3f417ea/vi/file.json',
},
],
},
];
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
Returns
Type | Description |
---|---|
CdnFile[] | All project files. |
metafile.url accessor
Get URL of current metafile.
import { CdnClient } from '@localazy/cdn-client';
const cdn = await CdnClient.create({
metafile: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0.v2.json',
});
const result = cdn.metafile.url;
2
3
4
5
6
7
example result
const result = 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0.v2.json';
Returns
Type | Description |
---|---|
string | Metafile URL. |
metafile.projectUrl accessor
Get URL of the project to which the metafile belongs.
import { CdnClient } from '@localazy/cdn-client';
const cdn = await CdnClient.create({
metafile: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0.v2.json',
});
const result = cdn.metafile.projectUrl;
2
3
4
5
6
7
example result
const result = 'https://localazy.com/p/cdnarticle';
Returns
Type | Description |
---|---|
string | Project URL. |
metafile.refresh() async function
Refresh the metafile.
import { CdnClient } from '@localazy/cdn-client';
const cdn = await CdnClient.create({
metafile: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0.v2.json',
});
await cdn.metafile.refresh();
2
3
4
5
6
7
Returns
Type |
---|
Promise<void > |
metafile.switch(options) async function
Switch to a different metafile.
import { CdnClient } from '@localazy/cdn-client';
const cdn = await CdnClient.create({
metafile: 'https://delivery.localazy.com/_a855374211039568660198b39c31/_e0.v2.json',
});
await cdn.metafile.switch({ metafile: 'different-metafile-url' });
2
3
4
5
6
7
Parameters
Name | Type | Description |
---|---|---|
options | CdnClientOptions | CDN client options. |
Type |
---|
Promise<void > |