2022-03-02 16:15:25 +01:00
|
|
|
import { LokaliseApi } from '@lokalise/node-api'
|
|
|
|
import AdmZip from 'adm-zip'
|
2022-12-26 18:00:00 +01:00
|
|
|
import dotenv from 'dotenv'
|
|
|
|
import https from 'https'
|
2022-03-02 16:15:25 +01:00
|
|
|
|
|
|
|
dotenv.config()
|
|
|
|
|
2023-05-14 13:52:47 +02:00
|
|
|
function exit(msg) {
|
|
|
|
console.error(msg)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
2022-03-02 16:15:25 +01:00
|
|
|
const apiKey = process.env.LOKALISE_API_KEY
|
|
|
|
const project_id = process.env.LOKALISE_PROJECT
|
2023-05-14 13:52:47 +02:00
|
|
|
if (!apiKey) exit('No API Key set for Lokalize! Set with "LOKALISE_API_KEY"')
|
|
|
|
if (!project_id) exit('No project id set for Lokalize! Set with "LOKALISE_PROJECT"')
|
2022-03-02 16:15:25 +01:00
|
|
|
const client = new LokaliseApi({ apiKey })
|
|
|
|
|
|
|
|
const WGet = (url) =>
|
|
|
|
new Promise((done) => {
|
|
|
|
https
|
|
|
|
.get(url, (res) => {
|
|
|
|
const data = []
|
|
|
|
res
|
|
|
|
.on('data', (chunk) => {
|
|
|
|
data.push(chunk)
|
|
|
|
})
|
|
|
|
.on('end', () => {
|
|
|
|
let buffer = Buffer.concat(data)
|
|
|
|
done(buffer)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.on('error', (err) => {
|
|
|
|
console.log('download error:', err)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
async function download() {
|
|
|
|
// For details see: https://app.lokalise.com/api2docs/curl/#transition-download-files-post
|
|
|
|
const download = await client.files().download(project_id, {
|
|
|
|
format: 'json',
|
|
|
|
indentation: 'tab',
|
|
|
|
json_unescaped_slashes: true,
|
|
|
|
original_filenames: false,
|
|
|
|
bundle_structure: '%LANG_ISO%.%FORMAT%',
|
|
|
|
export_sort: 'first_added',
|
|
|
|
export_empty_as: 'skip',
|
|
|
|
add_newline_eof: true,
|
|
|
|
replace_breaks: false,
|
|
|
|
})
|
|
|
|
const buffered = await WGet(download.bundle_url)
|
|
|
|
const zip = new AdmZip(buffered)
|
|
|
|
zip.extractAllTo('./locales', true)
|
|
|
|
}
|
|
|
|
|
|
|
|
download().catch((e) => {
|
|
|
|
console.error(e)
|
|
|
|
process.exit(1)
|
|
|
|
})
|