0

List all translations

by
Published Oct 17, 2025

List translations for the given project. If you want to download all translations for one locale we recommend to use the locales#download endpoint.

Script phrase Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Phrase = {
3
	token: string
4
	baseUrl: string
5
}
6
/**
7
 * List all translations
8
 * List translations for the given project. If you want to download all translations for one locale we recommend to use the locales#download endpoint.
9
 */
10
export async function main(
11
	auth: Phrase,
12
	project_id: string,
13
	page: string | undefined,
14
	per_page: string | undefined,
15
	branch: string | undefined,
16
	sort: string | undefined,
17
	order: string | undefined,
18
	q: string | undefined,
19
	If_Modified_Since: string,
20
	If_None_Match: string
21
) {
22
	const url = new URL(`${auth.baseUrl}/projects/${project_id}/translations`)
23
	for (const [k, v] of [
24
		['page', page],
25
		['per_page', per_page],
26
		['branch', branch],
27
		['sort', sort],
28
		['order', order],
29
		['q', q]
30
	]) {
31
		if (v !== undefined && v !== '' && k !== undefined) {
32
			url.searchParams.append(k, v)
33
		}
34
	}
35
	const response = await fetch(url, {
36
		method: 'GET',
37
		headers: {
38
			'If-Modified-Since': If_Modified_Since,
39
			'If-None-Match': If_None_Match,
40
			Authorization: 'ApiToken ' + auth.token
41
		},
42
		body: undefined
43
	})
44
	if (!response.ok) {
45
		const text = await response.text()
46
		throw new Error(`${response.status} ${text}`)
47
	}
48
	return await response.json()
49
}
50