Skip to content

Commit

Permalink
Drop separate download fallback (#3395)
Browse files Browse the repository at this point in the history
* Drop separate download fallback

* Document the overview of the bulk download process

* Get rid of rate-limiting that's not needed anymore
  • Loading branch information
dhruvkb authored Nov 27, 2023
1 parent 520d4d9 commit 0e470b2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 92 deletions.
5 changes: 3 additions & 2 deletions documentation/frontend/reference/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ processed and loaded into Nuxt via the Nuxt i18n module.
JED 1.x (derived from the flattened POT files) files are converted back into
the nested JSON as expected by Nuxt i18n.

This script uses the `wp-locales.json` file for the list of locales, if
downloading each locale separately and in parallel.
This script downloads all available translations in bulk as a ZIP file and
then extracts JSON files from the ZIP file. This prevents excessive calls to
GlotPress, which can be throttled and cause some locales to be missed.

**Script:** `i18n:get-translations`

Expand Down
1 change: 0 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
"@vue/test-utils": "^1.1.3",
"adm-zip": "^0.5.10",
"autoprefixer": "^10.4.16",
"axios-rate-limit": "^1.3.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^26.6.3",
"babel-loader": "8.2.5",
Expand Down
12 changes: 3 additions & 9 deletions frontend/src/locales/scripts/axios.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
const axios = require("axios")
const rateLimit = require("axios-rate-limit")

const { userAgent } = require("../../constants/user-agent")

module.exports = rateLimit(
axios.create({
headers: { "User-Agent": userAgent },
}),
{
maxRPS: 50, // limit GlotPress calls to 50 requests per second
}
)
module.exports = module.exports = axios.create({
headers: { "User-Agent": userAgent },
})
20 changes: 7 additions & 13 deletions frontend/src/locales/scripts/get-translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const chokidar = require("chokidar")
const { parseJson } = require("./read-i18n")

const bulkDownload = require("./bulk-download")
const separateDownload = require("./separate-download")

/**
* Write `en.json` from `en.json5`.
Expand All @@ -37,16 +36,11 @@ if (process.argv.includes("--watch")) {
}

if (!process.argv.includes("--en-only")) {
bulkDownload()
.catch((err) => {
console.error(err)
return separateDownload()
})
.catch((err) => {
console.error(err)
console.error(":'-( Downloading translations failed.")
if (process.argv.includes("--require-complete")) {
process.exitCode = 1
}
})
bulkDownload().catch((err) => {
console.error(err)
console.error(":'-( Downloading translations failed.")
if (process.argv.includes("--require-complete")) {
process.exitCode = 1
}
})
}
57 changes: 0 additions & 57 deletions frontend/src/locales/scripts/separate-download.js

This file was deleted.

14 changes: 4 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0e470b2

Please sign in to comment.