Skip to content

feat(CLI): derive tags from file path slots on push and pull #STRINGS-5103 - #1418

Draft
Sven Dunemann (forelabs) wants to merge 7 commits into
mainfrom
ccr-51cd44cb-yzxeta
Draft

Sven Dunemann (forelabs) wants to merge 7 commits into
mainfrom
ccr-51cd44cb-yzxeta

Conversation

@forelabs

@forelabs Sven Dunemann (forelabs) commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Ticket: https://phrase.atlassian.net/browse/STRINGS-5103

What

CLI (clients/cli/cmd/internal/): file patterns can contain named slots ({name}). On push the slot values of a file become its tag; on pull the tag is turned back into the file path. One .phrase.yml entry covers a whole tree of nested files.

push:
  sources:
    - file: ./Modules/{module}/Resources/Strings/<locale_name>.lproj/{name}.strings
pull:
  targets:
    - file: ./Modules/{module}/Resources/Strings/<locale_name>.lproj/{name}.strings
      params:
        tags: "*"
  • Push: the file is matched against the pattern; the slot values are joined with __ into a tag and added to the upload tags. Modules/Auth/Passkey/Resources/Strings/en.lproj/Passkey.strings gets Auth__Passkey__Passkey. The tag has no locale and no static path parts, so all locales of a file share one tag.
  • Pull: each tag is split into slot values and filled into the same pattern, once per locale via the normal <locale_name> / <locale_code> placeholders. The tag is also the download filter.
  • Slot kinds: a slot that is a whole folder segment ({module}) spans one or more folders (at most one per pattern); any other slot ({name} in {name}.strings) stays within one segment. Slots must be unique, must not be adjacent, and cannot be combined with <tag> or **.
  • tags with * (pull): entries containing * are expanded through the tags API (system tags excluded, branch aware, per_page=100 with pagination). "*" is all tags, "Auth__*" only tags starting with Auth__. Needs a <tag> or {slot} placeholder in file. With slots, tags that do not fit the slot count are left out, so several entries with different path shapes can coexist.
  • A value containing __ cannot be turned into a tag and fails the push for that file with a clear error.

Existing configs without slots / * in tags are unchanged.

Why a separate matcher

placeholders.Resolve rejects **, and fillFromPath splits patterns at a single ** for push; neither can carry several slots. Slot patterns therefore use their own matcher (MatchSlots); patterns without slots still go through the unchanged code. ToGlobbingPattern only gained slot -> * / **.

Tests

go vet and go test ./cmd/internal/... pass (run with GOFLAGS=-mod=mod; the sandbox go.sum lacks phrase-go, go.mod/go.sum unchanged). Covered: slot/tag round trips for several path shapes (nested module folders, locales/{path}/<locale_name>.lang/data.json with different depths, <locale_code> folders), tags that do not fit, __ in values, slot validation, globbing, push file discovery on a temp tree, pull path building per locale, wildcard expansion over 4 pages (305 tags), glob filtering and slot-count filtering.

Not verified / follow-ups

  • Not run against a live Phrase project. The pagination test uses a mock server relying on the Link: rel=next header, like the existing locale lookup.
  • go build ./cmd fails on this branch and on main in the sandbox (UploadsApiCmd undefined, generated code not present); only cmd/internal/... could be built and tested.
  • The __ <-> / mapping is lossy for folder or file names that contain __ (push errors for those).
  • With several pull entries of the same slot count, tags: "*" pulls every fitting tag into each entry; use a glob such as tags: "Auth__*" per entry.
  • CLI documentation for slots and tags globs will follow separately (location pending).
  • The repo has no PR template, so this body is free-form.

https://claude.ai/code/session_01Tw7YUuASvfys3UNgAGNgcv


Generated by Claude Code

… pull

Auth/Login/Widget.json resolves to the tag auth_login_widget.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tw7YUuASvfys3UNgAGNgcv
… in tags

Tags derived from a path now only drop the extension and replace / with _
(Auth/Login/Widget.json -> Auth_Login_Widget). A pull target file such as
./<file_path>.json maps each tag back to a path (Auth_Login_Widget -> Auth/Login/Widget.json).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tw7YUuASvfys3UNgAGNgcv
Auth/Login/Widget_Item.json -> Auth__Login__Widget_Item, so single
underscores in file names survive the round trip on pull.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tw7YUuASvfys3UNgAGNgcv
The wildcard is expanded via the tags API (system tags excluded, branch aware,
paginated) and needs a <tag> or <file_path> placeholder in the target file.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tw7YUuASvfys3UNgAGNgcv
On push, the part of the path matched by <locale_name>/<locale_code> becomes
LOCALE_NAME/LOCALE_CODE in the tag, so all locales of a file share one tag.
On pull, ./<file_path>.ext writes each tag once per locale, substituting the
tokens; tags without a locale part are skipped unless locale_id is set.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tw7YUuASvfys3UNgAGNgcv
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

API changelog (oasdiff)

Doc-only edits (descriptions, examples) do not appear here.

No changes detected

A file pattern may contain named slots, e.g.
./Modules/{module}/Strings/<locale_name>.lproj/{name}.strings. On push the slot
values are joined with __ into one tag (Auth/Passkey + Passkey ->
Auth__Passkey__Passkey); on pull the tag is split again and filled into the
same pattern. The locale uses the normal <locale_name>/<locale_code>
placeholders, so tags carry no locale. A whole-segment slot spans one or more
folders (at most one per pattern); tags entries containing * are expanded via
the tags API and filtered by the slot count.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tw7YUuASvfys3UNgAGNNgcv
@forelabs Sven Dunemann (forelabs) changed the title feat(CLI): derive tags from file paths on push and pull #STRINGS-5103 feat(CLI): derive tags from file path slots on push and pull #STRINGS-5103 Dec 1, 2026

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

2 participants