snapshot of https://github.com/tldraw/tldraw.git (main, 2026-09-23; blobs > 131072B omitted)
Some checks failed
Deploy analytics worker / Deploy analytics worker to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
i18n upload strings / Upload latest strings (push) Failing after 1s
Deploy bemo / Deploy bemo to ${{ (github.ref == 'refs/heads/bemo-production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
Deploy grafana resources / ${{ github.event_name == 'push' && 'Deploy grafana resources' || 'Validate grafana resources (dry run)' }} (push) Failing after 0s
End to end tests (dotcom) / Check for relevant changes (push) Failing after 0s
End to end tests (examples) / Check for relevant changes (push) Failing after 0s
End to end tests (mermaid readability) / Check for relevant changes (push) Failing after 1s
End to end tests (perf) / Check for relevant changes (push) Failing after 0s
Publish editor extensions / Publish editor extensions (push) Failing after 1s
Publish SDK packages / Remove the publish-packages label (push) Has been skipped
Checks / Tests & checks (push) Has been cancelled
Checks / Build all projects (push) Has been cancelled
Deploy templates / Deploy templates (push) Has been cancelled
End to end tests (dotcom) / End to end tests (dotcom) (push) Has been cancelled
End to end tests (mermaid readability) / End to end tests (mermaid readability) (push) Has been cancelled
End to end tests (perf) / End to end tests (perf) (push) Has been cancelled
Deploy .com / Deploy dotcom to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Has been cancelled
End to end tests (examples) / End to end tests (examples) (push) Has been cancelled
Publish SDK packages / Publish SDK packages (push) Has been cancelled
Publish SDK packages / Tell user released version (push) Has been cancelled
Publish SDK packages / Publishes code templates to separate repositories (push) Has been cancelled
Publish SDK packages / Deploys the template demos with the new SDK version (push) Has been cancelled
Some checks failed
Deploy analytics worker / Deploy analytics worker to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
i18n upload strings / Upload latest strings (push) Failing after 1s
Deploy bemo / Deploy bemo to ${{ (github.ref == 'refs/heads/bemo-production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
Deploy grafana resources / ${{ github.event_name == 'push' && 'Deploy grafana resources' || 'Validate grafana resources (dry run)' }} (push) Failing after 0s
End to end tests (dotcom) / Check for relevant changes (push) Failing after 0s
End to end tests (examples) / Check for relevant changes (push) Failing after 0s
End to end tests (mermaid readability) / Check for relevant changes (push) Failing after 1s
End to end tests (perf) / Check for relevant changes (push) Failing after 0s
Publish editor extensions / Publish editor extensions (push) Failing after 1s
Publish SDK packages / Remove the publish-packages label (push) Has been skipped
Checks / Tests & checks (push) Has been cancelled
Checks / Build all projects (push) Has been cancelled
Deploy templates / Deploy templates (push) Has been cancelled
End to end tests (dotcom) / End to end tests (dotcom) (push) Has been cancelled
End to end tests (mermaid readability) / End to end tests (mermaid readability) (push) Has been cancelled
End to end tests (perf) / End to end tests (perf) (push) Has been cancelled
Deploy .com / Deploy dotcom to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Has been cancelled
End to end tests (examples) / End to end tests (examples) (push) Has been cancelled
Publish SDK packages / Publish SDK packages (push) Has been cancelled
Publish SDK packages / Tell user released version (push) Has been cancelled
Publish SDK packages / Publishes code templates to separate repositories (push) Has been cancelled
Publish SDK packages / Deploys the template demos with the new SDK version (push) Has been cancelled
This commit is contained in:
219
internal/scripts/i18n-download-strings.ts
Normal file
219
internal/scripts/i18n-download-strings.ts
Normal file
@@ -0,0 +1,219 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import JSZip from 'jszip'
|
||||
|
||||
const LOKALISE_API_BASE = 'https://api.lokalise.com/api2'
|
||||
const ASYNC_EXPORT_POLL_INTERVAL_MS = 2000
|
||||
const ASYNC_EXPORT_MAX_POLLS = 120
|
||||
|
||||
function formatError(error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return error.stack ?? error.message
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.stringify(error, null, 2)
|
||||
} catch {
|
||||
return String(error)
|
||||
}
|
||||
}
|
||||
|
||||
function sleep(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
function getEnv(name: string) {
|
||||
const value = process.env[name]
|
||||
if (!value) throw new Error(`Missing required env var: ${name}`)
|
||||
return value
|
||||
}
|
||||
|
||||
async function lokaliseRequest<T>(path: string, init: RequestInit, apiKey: string): Promise<T> {
|
||||
const response = await fetch(`${LOKALISE_API_BASE}${path}`, {
|
||||
...init,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Api-Token': apiKey,
|
||||
...(init.headers ?? {}),
|
||||
},
|
||||
})
|
||||
|
||||
const body = (await response.json()) as unknown
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Lokalise request failed (${response.status}): ${JSON.stringify(body, null, 2)}`
|
||||
)
|
||||
}
|
||||
|
||||
return body as T
|
||||
}
|
||||
|
||||
async function getAsyncBundleUrl(
|
||||
projectId: string,
|
||||
options: Record<string, unknown>,
|
||||
apiKey: string
|
||||
) {
|
||||
const start = await lokaliseRequest<{ process_id?: string }>(
|
||||
`/projects/${projectId}/files/async-download`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify(options),
|
||||
},
|
||||
apiKey
|
||||
)
|
||||
|
||||
if (!start.process_id) {
|
||||
throw new Error(`Async export did not return process_id: ${JSON.stringify(start, null, 2)}`)
|
||||
}
|
||||
|
||||
for (let i = 0; i < ASYNC_EXPORT_MAX_POLLS; i++) {
|
||||
const processResult = await lokaliseRequest<{
|
||||
process?: {
|
||||
status?: string
|
||||
message?: string
|
||||
details?: { download_url?: string; bundle_url?: string }
|
||||
}
|
||||
}>(`/projects/${projectId}/processes/${start.process_id}`, { method: 'GET' }, apiKey)
|
||||
|
||||
const status = processResult.process?.status
|
||||
const details = processResult.process?.details
|
||||
const bundleUrl = details?.download_url ?? details?.bundle_url
|
||||
|
||||
if (status === 'finished') {
|
||||
if (!bundleUrl) {
|
||||
throw new Error(
|
||||
`Async export finished but no bundle URL was returned: ${JSON.stringify(processResult, null, 2)}`
|
||||
)
|
||||
}
|
||||
return bundleUrl
|
||||
}
|
||||
|
||||
if (status === 'failed' || status === 'cancelled') {
|
||||
throw new Error(
|
||||
`Async export ${status}: ${processResult.process?.message ?? 'No message'}\n${JSON.stringify(processResult, null, 2)}`
|
||||
)
|
||||
}
|
||||
|
||||
await sleep(ASYNC_EXPORT_POLL_INTERVAL_MS)
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Async export timed out after ${ASYNC_EXPORT_MAX_POLLS} polls for project ${projectId}`
|
||||
)
|
||||
}
|
||||
|
||||
async function fetchAndSave(
|
||||
url: string,
|
||||
dirPath: string,
|
||||
sortJson: boolean,
|
||||
fileResolver: (fileName: string) => string,
|
||||
space: string | number,
|
||||
skipEnglish = false
|
||||
) {
|
||||
const bundleZip = await fetch(url)
|
||||
// Need to unzip the bundle
|
||||
const zipData = await bundleZip.arrayBuffer()
|
||||
const zip = new JSZip()
|
||||
const bundle = await zip.loadAsync(zipData)
|
||||
const locales = Object.keys(bundle.files)
|
||||
for (const locale of locales) {
|
||||
if (bundle.files[locale].dir) {
|
||||
continue
|
||||
}
|
||||
const fileName = fileResolver(bundle.files[locale].name)
|
||||
if (skipEnglish && fileName === 'en.json') {
|
||||
continue
|
||||
}
|
||||
const filePath = path.resolve(dirPath, fileName)
|
||||
const file = await bundle.files[locale].async('text')
|
||||
const json = JSON.parse(file)
|
||||
|
||||
let finalJson = json
|
||||
if (sortJson) {
|
||||
// Sort of annoying, the property order is not guaranteed, so we need to alphabetize the keys.
|
||||
const sortedJson: { [key: string]: Record<string, string> } = {}
|
||||
// We have to go into the subobject to sort the keys.
|
||||
for (const key of Object.keys(json)) {
|
||||
const subJson = json[key]
|
||||
const sortedSubJson: Record<string, string> = {}
|
||||
for (const subKey of Object.keys(subJson).sort()) {
|
||||
sortedSubJson[subKey] = subJson[subKey]
|
||||
}
|
||||
sortedJson[key] = sortedSubJson
|
||||
}
|
||||
finalJson = sortedJson
|
||||
}
|
||||
fs.writeFileSync(filePath, JSON.stringify(finalJson, null, space) + '\n')
|
||||
console.log(`Wrote ${filePath}`)
|
||||
}
|
||||
}
|
||||
|
||||
async function i18nDownloadStrings() {
|
||||
await i18nDownloadTldrawStrings()
|
||||
await i18nDownloadDotcomStrings()
|
||||
}
|
||||
|
||||
async function i18nDownloadTldrawStrings() {
|
||||
const projectId = getEnv('LOKALISE_TLDRAW_PROJECT_ID')
|
||||
const apiKey = getEnv('LOKALISE_API_TOKEN')
|
||||
const dirPath = path.resolve(__dirname, '../../assets/translations')
|
||||
console.log('Downloading tldraw project files...')
|
||||
|
||||
const bundleUrl = await getAsyncBundleUrl(
|
||||
projectId,
|
||||
{
|
||||
format: 'json',
|
||||
original_filenames: true,
|
||||
export_empty_as: 'skip',
|
||||
},
|
||||
apiKey
|
||||
)
|
||||
|
||||
await fetchAndSave(
|
||||
bundleUrl,
|
||||
dirPath,
|
||||
false /* sort json */,
|
||||
(fileName) => fileName.split('/')[0].replace('_', '-').toLowerCase() + '.json',
|
||||
'\t',
|
||||
true /* skip english */
|
||||
)
|
||||
|
||||
console.log('Downloaded files successfully!')
|
||||
}
|
||||
|
||||
async function i18nDownloadDotcomStrings() {
|
||||
const projectId = getEnv('LOKALISE_PROJECT_ID')
|
||||
const apiKey = getEnv('LOKALISE_API_TOKEN')
|
||||
const dirPath = path.resolve(__dirname, '../../apps/dotcom/client/public/tla/locales')
|
||||
console.log('Downloading dotcom project files...')
|
||||
|
||||
const bundleUrl = await getAsyncBundleUrl(
|
||||
projectId,
|
||||
{
|
||||
format: 'json_structured',
|
||||
original_filenames: true,
|
||||
include_comments: true,
|
||||
include_description: true,
|
||||
export_empty_as: 'skip',
|
||||
plural_format: 'icu',
|
||||
placeholder_format: 'icu',
|
||||
},
|
||||
apiKey
|
||||
)
|
||||
|
||||
await fetchAndSave(
|
||||
bundleUrl,
|
||||
dirPath,
|
||||
true /* sort json */,
|
||||
(fileName) => fileName.split('/')[1].replace('_', '-').toLowerCase(),
|
||||
2
|
||||
)
|
||||
|
||||
console.log('Downloaded files successfully!')
|
||||
}
|
||||
|
||||
i18nDownloadStrings().catch((error) => {
|
||||
console.error('Failed to download i18n strings:')
|
||||
console.error(formatError(error))
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user