-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All messages removed after upgrading to v4 #1700
Comments
AND Po format. Unfortunately, there is no workaround for nonstandard json formats. You can try to write script which would convert it for you, it should be relatively simple. |
In case somebody else looks for such a script: #!/usr/bin/env node
/* eslint-disable no-restricted-syntax, no-await-in-loop */
import crypto from 'node:crypto'
import fs from 'node:fs/promises'
// from https://github.com/lingui/js-lingui/blob/59f0eb3565611d5860c883aa42a20365392ca1d8/packages/message-utils/src/generateMessageId.ts
const UNIT_SEPARATOR = '\u001F'
function generateMessageId(msg, context = '') {
return crypto
.createHash('sha256')
.update(msg + UNIT_SEPARATOR + (context || ''))
.digest('base64')
.slice(0, 6)
}
function printHelp() {
process.stdout.write(
[
'Migrate Lingui’s JSON catalogues into new hash–based keys.',
'',
`Usage: ${process.argv.slice(0, 2).join(' ')} JSON_FILE...`,
'',
].join('\n')
)
}
const filePaths = process.argv.slice(2)
if (!filePaths.length) {
printHelp()
process.exit(64)
} else if (['-h', '--help'].includes(filePaths[0])) {
printHelp()
process.exit(0)
}
for (const filePath of filePaths) {
const json = await fs.readFile(filePath, { encoding: 'utf-8' })
const msgs = JSON.parse(json)
const newMsgs = Object.fromEntries(
Object.entries(msgs).map(([key, value]) => {
if (value.message) {
// Already in new format
return [key, value]
}
const message = key
const { translation, extractedComments: comments } = value
return [
generateMessageId(message),
{
translation,
message,
comments,
},
]
})
)
await fs.writeFile(filePath, JSON.stringify(newMsgs, null, 2))
}
process.stdout.write('Done. You probably want to run this now:\n')
process.stdout.write('npx lingui extract && npx lingui compile\n') |
Not sure what you mean by “nonstandard” — I’m using JSON files with |
Thanks. Would you be minded to change the migration guide and add this script as a link to gist (or any other method)? I mean "lingui" or "minimal" is not-standardized by any organization translation format. Xliff - is standardized, Po is standardized. So there are no rules how "lingui" should serialize catalog in that formats. |
Gotcha. Thanks for clarification. |
Describe the bug
After upgrading from 3.17.1 to 4.2.1 and using
lingui
JSON files. After runninglingui extract --clean
all of the translations are empty.To Reproduce
My project is using natural language as IDs.
Documentation https://lingui.dev/releases/migration-4#hash-based-message-id-generation-and-context-feature promises that:
Expected behavior
Either or:
have some CLI command to migrate to new hash–based IDs in JSON file
lingui extract
detecting older format of the JSON file and use translations from those instead of marking them all as obsoleteAdditional context
Add any other context about the problem here.
lingui --version
: 4.2.1npm list @babel/core
: 7.21.4@lingui/swc-plugin
babel-macro-plugin
.babelrc
) or framework you use (Create React App, NextJs, Vite):The text was updated successfully, but these errors were encountered: