Replies: 3 comments 4 replies
-
I will try to prepare kind of migration path with script for that purpose.
|
Beta Was this translation helpful? Give feedback.
0 replies
-
try this // migrate.ts
import {
CatalogType,
ExtractedMessageType,
getConfig,
LinguiConfigNormalized,
MessageType,
} from "@lingui/conf"
import { getCatalogs } from "@lingui/cli/api"
import { formatter as createFormatter } from "@lingui/format-po"
import fs from "fs/promises"
import { generateMessageId } from "@lingui/message-utils/generateMessageId"
function _isGeneratedId(id: string, message: ExtractedMessageType): boolean {
return id === generateMessageId(message.message, message.context)
}
async function command(
config: LinguiConfigNormalized,
) {
const catalogs = await getCatalogs(config)
const formatter = createFormatter({
explicitIdAsDefault: true,
})
await Promise.all(
catalogs.map(async (catalog) => {
const extractedCatalog = await catalog.collect()
for (const locale of config.locales) {
const translationFileName = catalog.getFilename(locale)
const translationCatalog = await formatter.parse(
await fs.readFile(translationFileName, "utf-8"),
{
locale,
sourceLocale: config.sourceLocale,
filename: translationFileName,
}
)
for (const messageId in extractedCatalog) {
const extractedMessage = extractedCatalog[messageId]
const isGeneratedId = _isGeneratedId(messageId, extractedMessage)
const oldId = isGeneratedId ? extractedMessage.message : messageId
if (translationCatalog[oldId]) {
;(extractedMessage as MessageType).translation =
translationCatalog[oldId].translation
}
}
await catalog.write(locale, extractedCatalog as CatalogType)
}
})
)
}
command(getConfig()) # in the place where is your lingui.config is located
ts-node ./migrate.ts Any feedback on this would be much appreciated, as i wanted to add this a separate command in a lingui cli. |
Beta Was this translation helpful? Give feedback.
4 replies
-
Hi! Not yet sorry :( we had to reprioritise things at my company so we be migrating later this year.
… On 23 Jun 2023, at 08:42, Andrii Bodnar ***@***.***> wrote:
Hi @2snEM6 <https://github.com/2snEM6>, have you had a chance to test it? We are waiting for feedback and would like to move forward with #1686 <#1686>
—
Reply to this email directly, view it on GitHub <#1685 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABZDTPPOH34RO6BYR6DZMJDXMU3E3ANCNFSM6AAAAAAYUFB6AU>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
In our particular case, sometimes we use explicit ids and sometimes we don't. This means that we can't just set "explicitIdAsDefault" to true.
As per the docs, the way to go is to manually add
#. js-lingui-explicit-id
to every single translation entry that is extracted from an explicit ID. This is a very tedious job having a large catalog.If we don't add the
#. js-lingui-explicit-id
, then the translations disappear and we need to translate everything again.As a side note, if we add
#. js-lingui-explicit-id
, then translations are kept, but our translation provider (phrase.com) removes comments when translating the catalog via their UI. Is there any workaround for this? I guess many translation providers work this way, so it might be a problem to other people.Thank you
Beta Was this translation helpful? Give feedback.
All reactions