Reduce PO catalog comments changes for cleaner source control
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.9k
- Forks
- 457
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 16
Description
### Problem Description
Keeping PO files in Git can result in thousands of changed lines with minimal changes to translations after every extraction. The source of most are comments with file paths and line numbers. I think it's possible to disable comments altogether but I do want to keep the reference to the file name.
In essence I want to transform this:
```po
#: survey/config/project-survey.ts:12
#: survey/config/project-survey.ts:20
#: survey/config/project-survey.ts:55
#: survey/config/user-survey.ts:33
#: survey/config/user-survey.ts:46
msgid "Don’t know"
msgstr "Ne vem"
```
Into this:
```po
#: survey/config/project-survey.ts
#: survey/config/user-survey.ts
msgid "Don’t know"
msgstr "Ne vem"
```
### Proposed Solution
This config will get rid of the line numbers:
```js
import { defineConfig } from '@lingui/cli'
import { formatter } from '@lingui/format-po'
export default defineConfig({
format: formatter({ lineNumbers: false, printPlaceholdersInComments: false }),
// ...
})
```
But you still get duplicated lines if the same translation appears multiple times in the same file. I think the PO extractor should automatically remove duplicated comment lines regardless of there being an option or not.
Right now I'm using a post-extract script to strip unwanted lines.
__clean-po-files.sh__
```sh
#!/bin/sh
wd=$(pwd)
for po in "$wd"/src/locales/*.po; do
uniq "$po" > "${po}.new"
rm "$po"
mv "${po}.new" "$po"
done
```
__package.json__
```json
{
"scripts": {
"extract": "lingui extract && ./clean-po-files.sh"
}
}
```
### Alternatives Considered
I'm using the post-extract script for now and that works fine.
### Additional Context
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the @lingui/format-po formatter configuration shown in the issue and compare its output with the clean-po-files.sh workaround invoked by package.json. Check how extraction comments are emitted, then verify that repeated references in one source file are consolidated while distinct file references remain; the existing extract command provides the intended workflow to test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, shell, typescript
- Domain
- localization, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100