Repository navigation
fix(cli): re-translate keys whose source value changed in fill - #519
theluckystrike wants to merge 3 commits into
Conversation
`intlayer fill` in complete mode only translated locales with missing values, so editing a source string left every existing translation stale. Record a hash of each source value a target locale was filled from in `intlayer.journal.json` at the project root, so the file can be committed and used in CI. On the next run, values whose hash changed are treated as missing for that locale and sent for translation again. Unchanged translations are kept. Locales filled before the journal existed are taken as up to date on the first run. Fixes aymericzip#513 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hey @theluckystrike Thanks for your contribution |
…e journal The journal file had to be committed after each fill and would conflict between team members. Fill now reads the previous version of each content declaration from git instead. It compares with HEAD by default, with the merge base of the base branch when --git-diff is set, and with the upstream when --unpushed is set. A source value that changed while its translation did not is sent for translation again. A translation edited in the same change is kept. Nothing extra is written to the project. loadContentDeclaration and loadExternalFile accept the file content as an option so the git version can be loaded with the same imports and aliases.
|
Makes sense. I removed the journal. Fill now reads the previous version of each content declaration from git and compares the source values. It uses HEAD by default, the merge base with |
aymericzip
left a comment
There was a problem hiding this comment.
Changes seems good @theluckystrike, nothing to say regarding the code. Good job
I will have to test it properly before we merge
I also saw that .yml, .yaml, .md & .mdx are covered, which is great
Few notes to study,
- Is that approach will work in CI (e.g. Github Action)?
- What if git is not initialized on the project?
- Will it cover content loaded via
syncJSON/loadJSONplugins &syncPO/loadPOplugins - No breaking changes are present with remote dictionaries, considering both
remote&locale&remotelocations
…ailable Fill already fell back to filling missing translations when git could not give the previous version of a file, but it did so silently. It now checks the ref once before reading any file and logs the reason: no git repository, no commit, no upstream branch, or no merge base with --git-diff (for example a shallow clone from actions/checkout with its default fetch-depth: 1). Adds hasGitRef to the engine git helpers, with tests against real repositories (no repository, no commit, shallow clone), and a test that remote and plugin dictionaries are never read from git.
|
Thanks for the review. I went through each point in the code, then tried them on throwaway git repos.
One correction on Tests: cli fill 49 passed, engine git helpers 4 passed. I haven't run a live fill against an AI provider. |
|
New note @theluckystrike
It's a great work, but I'm not 100% satisfied by the suggested change. I can't provide a feature that does only work in some specifics cases. After going deeper on it, the best way to implement it will probably be to use journals connected to the CMS & Intlayer backend |
|
Both points are right, thanks for checking them. On the first one: with two commits already on main, On the second: Agreed that a feature that only works in some setups is not good enough. I'll keep this as a draft and won't push more code. Once you have settled on how the journal should connect to the CMS and backend, I can rework it on top of that, or close this PR if a fresh one is easier. |
|
Thanks @theluckystrike I will keep you updated once we will have a clearer vision on that feature |
|
@aymericzip, sounds good, thanks. I'll keep #519 current with main until the direction is clearer, then adapt it to whatever you settle on. In the meantime #521 is a small docs fix. It removes the output-content-declarations flag from the extract docs, since the CLI doesn't have it. Thank you, |
Fixes #513
In
completemode,intlayer fillonly sends values that are missing in a target locale. So when a source value is edited, the old translations stay. This PR detects edited source values with git, so no extra file is written or committed.Before building the tasks,
fillreads the previous version of each local content declaration withgit show. The ref isHEADby default, the merge base of--git-diff-baseand--git-diff-currentwhen--git-diffis set, and@{push}with--unpushed. Unchanged files are skipped without being loaded. Changed ones are loaded throughloadContentDeclaration, which now accepts the file content as an option, so imports and theintlayeralias resolve as usual.listTranslationsTasksthen compares the old and new source values. A target locale gets a task when a source value changed and its translation didn't. If the translation was edited in the same change, it is kept.translateDictionarydrops the stale target values before the existing missing-content filter runs, so only changed and missing values go to the AI.Only the base locale counts as a source, since per-locale files written by
fillare outputs. Files that are new, untracked, or outside a git repo behave as before. Markdown and YAML declarations aren't compared.docs/docs/en/cli/fill.mdnow says whatcompletedoes and which ref it compares with.What I checked
sourceChanges.test.ts,listTranslationsTasks.test.tsandtranslateDictionary.test.tsfor changed values, translations edited in the same change, per-locale files and the ref choice.vitest runin@intlayer/cli, 205 passed, 19 skipped, 0 failed. TheloadDictionariestests in@intlayer/enginepass.fillagainst an AI provider.I wrote this with AI assistance and reviewed every changed line by hand.