Skip to content
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

Make catalog file line number references optional #587

Closed
MarttiR opened this issue Nov 12, 2019 · 7 comments
Closed

Make catalog file line number references optional #587

MarttiR opened this issue Nov 12, 2019 · 7 comments

Comments

@MarttiR
Copy link
Contributor

MarttiR commented Nov 12, 2019

Problem description
Having line numbers in catalog files creates a lot of merge conflicts in a GitFlow-ish workflow when multiple developers are working on the same codebase. The same conflicts happen in each language catalog file and each one must be manually merged twice: first when merging feature branches to develop, and once more when merging to master.

Preferred solution
There should be an option to turn off the line numbers from catalog output.

Alternatives considered
This could be accomplished by using the minimal format, but it would also strip the obsolete info, which is needed for development. The PO format also includes line numbers, so it would create the same amount of conflicts.

@tricoder42
Copy link
Contributor

Hey @MarttiR! What if the extract command would resolve merge conflicts in catalog automatically in the same way how yarn does it?

Message references and sources would be extracted from the existing codebase and translations would be loaded from the current branch. Ideally we could use the latest translation in merge in case if both develop and feature branch has updates in translations.

What do you think? Willing to work on it and send a PR?

@MarttiR
Copy link
Contributor Author

MarttiR commented Nov 13, 2019

@tricoder42 I suppose that would be a step forward, but unless extract can parse a file that contains git conflict markers, it would still require manual steps from the developers (at least git checkout --ours) before the extract command could run at all. Any new translations merged in would be lost at that step, or they would have to be manually recovered from the feature branch. I think a git merge driver would work better in that regard.

However, it would be a lot easier to implement a configuration option that is checked when adding line number references to serialized translation objects.

@dcorb
Copy link

dcorb commented Nov 26, 2019

This feature will be really useful, please consider to merge it.

As a temporal fix, we came up with a workaround:
In a removeOrigin.js file:

const fs = require("fs");

function removeOrigin(path) {
  let messages = JSON.parse(fs.readFileSync(path));
  Object.keys(messages).forEach(function(key) {
    delete messages[key].origin;
  });
  fs.writeFileSync(path, JSON.stringify(messages, null, 2));
}

removeOrigin("translations/en/messages.json");
removeOrigin("translations/fi/messages.json");
console.log("✅ Translations' origin removed");

Then, as npm script:
"compile-lingui": "lingui extract --clean && node translations/removeOrigin.js && lingui compile"

@tricoder42
Copy link
Contributor

It has just been released in 2.9.0.

@joshhunt
Copy link

joshhunt commented Oct 1, 2020

Is it correct that this option is not available for PO files (yet?)? There is currently no way to configure lingui to include line numbers/origins in PO files?

@tricoder42
Copy link
Contributor

@joshhunt Not yet, but it's available in v3 (pre-release). It's not documented (yet), but I've definitely merged it https://github.com/lingui/js-lingui/blob/next/packages/conf/src/index.ts#L58

@landsman
Copy link
Contributor

landsman commented Oct 2, 2020

@MarttiR, @joshhunt is it same with #720 (comment) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants