feat(i18n): localize pt-BR exercise names
This commit is contained in:
1 parent
dc3fafc6ef
commit
448c66752f
21 files changed
+1615
-53
No files matched your search
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const sourcePath = join(root, 'scripts', 'exercise-name-sources', 'pt-BR.json')
|
||||
const outputPath = join(root, 'frontend', 'src', 'exercise-names', 'pt-BR.js')
|
||||
const exercisesPath = join(root, 'frontend', 'src', 'lib', 'exercises-data.js')
|
||||
|
||||
const source = JSON.parse(readFileSync(sourcePath, 'utf8'))
|
||||
const { EXDB } = await import(pathToFileURL(exercisesPath))
|
||||
const known = new Set(EXDB.map(exercise => exercise.id))
|
||||
|
||||
for (const id of Object.keys(source)) {
|
||||
if (!known.has(id)) throw new Error(`Unknown exercise ID: ${id}`)
|
||||
if (typeof source[id] !== 'string' || !source[id].trim()) throw new Error(`${id}: name must be a non-empty string`)
|
||||
}
|
||||
if (Object.keys(source).length !== EXDB.length) {
|
||||
throw new Error(`Incomplete pt-BR exercise names: ${Object.keys(source).length}/${EXDB.length}`)
|
||||
}
|
||||
|
||||
const ordered = {}
|
||||
for (const exercise of EXDB) ordered[exercise.id] = source[exercise.id].trim()
|
||||
mkdirSync(dirname(outputPath), { recursive: true })
|
||||
writeFileSync(outputPath, '// generated by scripts/build-pt-br-exercise-names.mjs — edit scripts/exercise-name-sources/pt-BR.json\nexport default ' + JSON.stringify(ordered) + '\n')
|
||||
console.log(`Generated ${EXDB.length}/${EXDB.length} pt-BR exercise names.`)
|
||||
@@ -0,0 +1,23 @@
|
||||
# Brazilian Portuguese exercise names
|
||||
|
||||
`pt-BR.json` is the editable source for the Brazilian Portuguese exercise-name
|
||||
pack. It maps every built-in EXDB exercise ID to a Portuguese title. The app
|
||||
combines that title with the unchanged English source at runtime:
|
||||
|
||||
```text
|
||||
Elevação assistida das pernas deitada (assisted lying leg raise)
|
||||
```
|
||||
|
||||
Custom exercise names are never translated. IDs, plan data, workout history,
|
||||
imports and exports continue to use the canonical catalogue entries.
|
||||
|
||||
Generate the runtime pack with:
|
||||
|
||||
```sh
|
||||
node scripts/build-pt-br-exercise-names.mjs
|
||||
```
|
||||
|
||||
The initial translations were produced from the English EXDB titles with LLM
|
||||
assistance and must not be described as reviewed by a native speaker unless a
|
||||
named human reviewer completes that review. They are original translations and
|
||||
were not copied from another Portuguese exercise dataset.
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { readFileSync, writeFileSync } from 'node:fs'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const sourcePath = join(root, 'scripts', 'exercise-name-sources', 'pt-BR.json')
|
||||
const glossaryPath = join(root, 'scripts', 'instruction-sources', 'GLOSSARY.md')
|
||||
const exercisesPath = join(root, 'frontend', 'src', 'lib', 'exercises-data.js')
|
||||
const claude = process.env.CLAUDE_BIN || 'claude'
|
||||
const option = name => process.argv.find(arg => arg.startsWith(`--${name}=`))?.split('=').slice(1).join('=')
|
||||
const limit = Number(option('limit') || 1324)
|
||||
const batchSize = Number(option('batch-size') || 80)
|
||||
const apply = process.argv.includes('--apply')
|
||||
|
||||
if (!Number.isInteger(limit) || limit < 1 || !Number.isInteger(batchSize) || batchSize < 1) {
|
||||
throw new Error('limit and batch-size must be positive integers')
|
||||
}
|
||||
|
||||
const existing = JSON.parse(readFileSync(sourcePath, 'utf8'))
|
||||
const glossary = readFileSync(glossaryPath, 'utf8')
|
||||
const { EXDB } = await import(pathToFileURL(exercisesPath))
|
||||
const pending = EXDB.filter(exercise => !existing[exercise.id]).slice(0, limit)
|
||||
const next = { ...existing }
|
||||
|
||||
for (let start = 0; start < pending.length; start += batchSize) {
|
||||
const batch = pending.slice(start, start + batchSize)
|
||||
const schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
translations: {
|
||||
type: 'array', minItems: batch.length, maxItems: batch.length,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: { id: { type: 'string' }, name: { type: 'string', minLength: 1 } },
|
||||
required: ['id', 'name'], additionalProperties: false
|
||||
}
|
||||
}
|
||||
},
|
||||
required: ['translations'], additionalProperties: false
|
||||
}
|
||||
const input = batch.map(({ id, n, bp, eq, tg }) => ({ id, english: n, bodyPart: bp, equipment: eq, target: tg }))
|
||||
const prompt = `Translate every exercise title below into concise, natural Brazilian Portuguese for a gym app.
|
||||
|
||||
Rules:
|
||||
- Return only the structured JSON required by the schema, with every ID exactly once and in input order.
|
||||
- Return only the Portuguese title in "name". Do not append or repeat the English title.
|
||||
- Preserve exercise identity, equipment, stance, grip, direction, side, assisted/weighted status and version qualifiers.
|
||||
- Prefer established Brazilian gym terminology (for example: supino, agachamento, remada, puxada, rosca, elevação, extensão, flexão de braços, barra fixa, afundo, levantamento terra).
|
||||
- Keep accepted equipment or exercise names such as kettlebell, Smith, hack squat, leg press and Romanian deadlift when that is the clearest Brazilian usage.
|
||||
- Use sentence case, not Title Case. Do not use Portuguese (Portugal) terms.
|
||||
- Do not repair or reinterpret questionable source mechanics; translate the title faithfully.
|
||||
- Use the metadata only to disambiguate the English title.
|
||||
|
||||
GLOSSARY:
|
||||
${glossary}
|
||||
|
||||
INPUT:
|
||||
${JSON.stringify(input)}`
|
||||
|
||||
console.log(`Translating names ${start + 1}-${start + batch.length} of ${pending.length} (${batch[0].id}…${batch.at(-1).id})`)
|
||||
const result = spawnSync(claude, [
|
||||
'-p', '--model', 'sonnet', '--effort', 'high', '--no-session-persistence',
|
||||
'--permission-mode', 'dontAsk', '--disallowedTools', 'Bash', 'Edit', 'Write', 'Read',
|
||||
'--output-format', 'json', '--max-budget-usd', '2', '--json-schema', JSON.stringify(schema)
|
||||
], { input: prompt, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 })
|
||||
if (result.status !== 0) throw new Error(result.stderr || result.stdout || `Claude exited ${result.status}`)
|
||||
const envelope = JSON.parse(result.stdout)
|
||||
if (envelope.is_error || !envelope.structured_output) throw new Error(envelope.result || 'Claude returned no structured output')
|
||||
const rows = envelope.structured_output.translations
|
||||
const received = new Map(rows.map(row => [row.id, row.name.trim()]))
|
||||
if (received.size !== batch.length) throw new Error('Claude returned duplicate or missing IDs')
|
||||
for (const exercise of batch) {
|
||||
const name = received.get(exercise.id)
|
||||
if (!name) throw new Error(`${exercise.id}: missing translated name`)
|
||||
next[exercise.id] = name
|
||||
}
|
||||
if (apply) {
|
||||
writeFileSync(sourcePath, JSON.stringify(next, null, 2) + '\n')
|
||||
console.log(`Checkpoint: ${Object.keys(next).length}/${EXDB.length} names`)
|
||||
}
|
||||
}
|
||||
|
||||
if (!apply) console.log(`Validated ${pending.length} names. Re-run with --apply to update the source.`)
|
||||
else console.log(`Updated ${sourcePath}: ${Object.keys(next).length}/${EXDB.length} names`)
|
||||
Reference in new issue
Block a user