-
Notifications
You must be signed in to change notification settings - Fork 386
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
convert-from json/lingui doesnt work as expected #1641
Comments
Unfortunately, this functionality was completely abandoned due to lack of interest from my side (and absence of unit tests from previous contributors). We are happily accept PR's fixing this. Or you can do the converting as one time job manually for your codebase. Using existing formatters this should be pretty straightforward to do. |
@thekip can you explain how to do it manually? |
// pseudocode, i didn't test it
import { formatter as createPoFormatter } from "@lingui/format-po"
import { formatter as createJsonFormatter } from "@lingui/format-json"
import fs from "fs/promises"
const poFormatter = createPoFormatter()
const jsonFormatter = createJsonFormatter()
async main() {
const catalog = jsonFormatter.parse(await fs.readFile('myfile.json', "utf8"));
await fs.writeFile('myfile.po', poFormatter.serialize(newFileConent))
console.log('Done!')
}
main(); |
same issue, it does not serialize correctly the minimal json format to any other format |
What are you expecting as "correct"? minimal has a reduced amount of data comparing to other formats. Obviously, while converting, it will not take this data from "nowhere". Do you use any TMS? If yes, it's easier to just re-export your strings from there in a proper format. |
When converting the minimal format to any other type, it will not keep the translation.
Then i've encountered a new issue with the new msgids, my language files are using the previous msgids. |
So it seems when extracting in "po" format it doesnt use hash msgid but in the UI I do see the msgid hash. |
try this: import { generateMessageId } from "@lingui/message-utils/generateMessageId"
const catalog = jsonFormatter.parse(fs.readFileSync(`src/language/locales/${item}/catalog.json`, 'utf8'))
const newCatalog = {}
Object.keys(catalog).forEach((k) => {
newCatalog[generateMessageId(k)] = {
translation: catalog[k],
message: k,
description: '',
origin: [],
}
})
const output = poFormatter.serialize(newCatalog, {}) |
@thekip that wouldnt work as message id is also composed of context. |
for json files you have to use a different notation, otherwise plugin/loader will not recognize them from other not related json's. // for other extension you have to use `?lingui` suffix
const { messages } = await import(`./locales/${language}.json?lingui`); And yes, loading, minimal/lingui formats directly to |
Do I understand correctly that there is then no way to load a translation catalog from an external source (e.g., CDN, AWS S3 bucket, separate project repository, etc) and every change in translation catalogs will require a new build? |
@pniebrzydowski not really. Every translation catalog should be compiled before use in runtime. But this doesn't mean you need to re-build your whole application, only catalogs You can compile catalogs and put them to an external source as compiled versions, OR you can put them as sources and compile on the fly (for example using some lambda or cloud function). Also take a look at https://github.com/lingui/js-lingui/tree/main/packages/remote-loader |
Continuing the topic. Compiling on the fly has no official solution or tutorial. Actually |
Thanks - with the |
The remote loader is quite abandoned, i mentioned it just as an example how it could be achieved. Here is a dedicated issue #1551 |
Describe the bug
Having translations in json format and a new lingui config set to "po" format
Running extract --convert-from minimal doesnt copy the already translated strings
Converting from "minimal" to "lingui" works partialy, the translated strings is converted to an array of chars and there's a field "obsolete:true", sources are missing
To Reproduce
Expected behavior
Translated strings are copied to new format
Additional context
Converting from "minimal" to "lingui" does work as expected
@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: