Get Content
Once you have initialized the CdnClient, you can get content of one or multiple files that are present in the metafile.
Selecting Data
You can select the data you want by specifying the files
and the locales
parameters in the fetch()
function.
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.
Single File
In following examples, a single file returned from metafile.files[0]
is used to demonstrate the usage of the fetch()
function.
Get Single Locale
Get the locale keys for single file and single locale.
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
Get Multiple Locales
Get the locale keys for single file and multiple locales.
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', 'de'],
});
2
3
4
5
6
7
8
9
10
example result
const result = {
en: {
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',
},
de: {
cdn_info: 'Mit dem CDN können Sie die Übersetzungsdateien sofort liefern',
cdn_testing: 'Wir testen das CDN',
hello_localazy: 'Hallo Localazy!',
using_javascript: 'In diesem Projekt haben wir uns für JavaScript entschieden',
},
};
2
3
4
5
6
7
8
9
10
11
12
13
14
Get All Locales
Get the locale keys for single file and all locales.
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],
});
2
3
4
5
6
7
8
9
example result
const result = {
en: {
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',
},
de: {
cdn_info: 'Mit dem CDN können Sie die Übersetzungsdateien sofort liefern',
cdn_testing: 'Wir testen das CDN',
hello_localazy: 'Hallo Localazy!',
using_javascript: 'In diesem Projekt haben wir uns für JavaScript entschieden',
},
es: {
cdn_info: 'Con la CDN puedes entregar los archivos de traducción al instante',
cdn_testing: 'Estamos probando la CDN',
hello_localazy: 'Hola, Localazy!',
using_javascript: 'En este proyecto hemos decidido utilizar JavaScript',
},
pt_PT: {
cdn_info: 'Com o CDN pode entregar os ficheiros de tradução instantaneamente',
cdn_testing: 'Estamos a testar o CDN',
hello_localazy: 'Olá Localazy!',
using_javascript: 'Neste projecto, decidimos utilizar JavaScript',
},
vi: {
cdn_info: 'Với CDN, bạn có thể cung cấp các tệp dịch ngay lập tức',
cdn_testing: 'Chúng tôi đang thử nghiệm CDN',
hello_localazy: 'Chào Localazy!',
using_javascript: 'Trong dự án này, chúng tôi quyết định sử dụng JavaScript',
},
};
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
Multiple Files
In following examples, all files returned from metafile.files
are used to demonstrate the usage of the fetch()
function.
Get Single Locale
Get the locale keys for multiple files and single locale.
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,
locales: 'en',
});
2
3
4
5
6
7
8
9
10
example result
const result = {
dfe5b84c1598c8c56b6f1a11efcd483bb3f417ea: {
en: {
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
7
8
9
10
Get Multiple Locales
Get the locale keys for multiple files and multiple locales.
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,
locales: ['en', 'de'],
});
2
3
4
5
6
7
8
9
10
example result
const result = {
dfe5b84c1598c8c56b6f1a11efcd483bb3f417ea: {
en: {
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',
},
de: {
cdn_info: 'Mit dem CDN können Sie die Übersetzungsdateien sofort liefern',
cdn_testing: 'Wir testen das CDN',
hello_localazy: 'Hallo Localazy!',
using_javascript: 'In diesem Projekt haben wir uns für JavaScript entschieden',
},
},
};
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Get All Locales
Get the locale keys for multiple files and all locales.
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,
});
2
3
4
5
6
7
8
9
example result
const result = {
dfe5b84c1598c8c56b6f1a11efcd483bb3f417ea: {
en: {
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',
},
de: {
cdn_info: 'Mit dem CDN können Sie die Übersetzungsdateien sofort liefern',
cdn_testing: 'Wir testen das CDN',
hello_localazy: 'Hallo Localazy!',
using_javascript: 'In diesem Projekt haben wir uns für JavaScript entschieden',
},
es: {
cdn_info: 'Con la CDN puedes entregar los archivos de traducción al instante',
cdn_testing: 'Estamos probando la CDN',
hello_localazy: 'Hola, Localazy!',
using_javascript: 'En este proyecto hemos decidido utilizar JavaScript',
},
pt_PT: {
cdn_info: 'Com o CDN pode entregar os ficheiros de tradução instantaneamente',
cdn_testing: 'Estamos a testar o CDN',
hello_localazy: 'Olá Localazy!',
using_javascript: 'Neste projecto, decidimos utilizar JavaScript',
},
vi: {
cdn_info: 'Với CDN, bạn có thể cung cấp các tệp dịch ngay lập tức',
cdn_testing: 'Chúng tôi đang thử nghiệm CDN',
hello_localazy: 'Chào Localazy!',
using_javascript: 'Trong dự án này, chúng tôi quyết định sử dụng JavaScript',
},
},
};
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
All Files Content
Get All Locales
Get the locale keys for all files and all locales.
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();
2
3
4
5
6
7
example result
const result = {
dfe5b84c1598c8c56b6f1a11efcd483bb3f417ea: {
en: {
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',
},
de: {
cdn_info: 'Mit dem CDN können Sie die Übersetzungsdateien sofort liefern',
cdn_testing: 'Wir testen das CDN',
hello_localazy: 'Hallo Localazy!',
using_javascript: 'In diesem Projekt haben wir uns für JavaScript entschieden',
},
es: {
cdn_info: 'Con la CDN puedes entregar los archivos de traducción al instante',
cdn_testing: 'Estamos probando la CDN',
hello_localazy: 'Hola, Localazy!',
using_javascript: 'En este proyecto hemos decidido utilizar JavaScript',
},
pt_PT: {
cdn_info: 'Com o CDN pode entregar os ficheiros de tradução instantaneamente',
cdn_testing: 'Estamos a testar o CDN',
hello_localazy: 'Olá Localazy!',
using_javascript: 'Neste projecto, decidimos utilizar JavaScript',
},
vi: {
cdn_info: 'Với CDN, bạn có thể cung cấp các tệp dịch ngay lập tức',
cdn_testing: 'Chúng tôi đang thử nghiệm CDN',
hello_localazy: 'Chào Localazy!',
using_javascript: 'Trong dự án này, chúng tôi quyết định sử dụng JavaScript',
},
},
};
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