Skip to content

Fix localized variant groups across targets and support folder resources - #1640

Open
eschwieb wants to merge 2 commits into
yonaskolb:masterfrom
eschwieb:fix/localized-resource-variants
Open

Fix localized variant groups across targets and support folder resources#1640
eschwieb wants to merge 2 commits into
yonaskolb:masterfrom
eschwieb:fix/localized-resource-variants

Conversation

@eschwieb

Copy link
Copy Markdown
Contributor

What was wrong

XcodeGen reused localized variant groups and their child file references across targets. That works only when every target uses the same localizations. If two targets selected different languages, generating the second target could move shared references out of the first target’s variant group or leave a same-named variant group detached from the project hierarchy.

XcodeGen also did not handle directories inside .lproj folders as localized folder resources. A structure such as:

Resources/
├── Base.lproj/
│   └── Help/
├── de.lproj/
│   └── Help/
└── en.lproj/
    └── Help/

needs to become a Help variant group whose language children are folder references. Previously, the children had no folder type and the variant group was not added to the resources phase, so Xcode would not copy the localized directories correctly.

What changed

Variant groups are now kept separate for each target, and localized child references are scoped to the variant group that owns them. Ordinary file references remain shared across the project.

Localized directories are now emitted as folder references and their variant groups are added to the resources phase. A non-base localization can create the folder variant group when the folder is missing from Base.lproj or when a target selects only another language.

Folder matching is also kept separate from extension-insensitive file matching, so resources such as Help/ and Help.strings do not accidentally end up in the same variant group.

Tests

The new tests cover:

  • Different and identical language selections across targets
  • Localized references used across multiple source entries
  • Direct and localized uses of the same physical file
  • Storyboard and strings companion resources
  • Project serialization and reloading
  • Localized folders copied as opaque folder references
  • Localized folders alongside compiled XIB resources
  • Targets selecting only a non-development language
  • Folders missing from the base localization
  • Same-stem folder and file collisions
  • Parent ownership and build-phase membership

The complete Swift test suite passes.

Developed with assistance from GitHub Copilot. I did human review of each step along the way, and verified this addresses the issues we found in downstream code.

Localized resources can be shared by several targets, but each target may include a different set of languages. XcodeGen was reusing the same variant groups and file references across those targets. Since an Xcode file reference can only have one parent, processing a later target could pull a child away from an earlier group or leave a same-named group detached from the project hierarchy.

Use a separate variant-group cache for each target, while still reusing groups across source entries within that target. Localized file references are now cached together with their owning variant group, while ordinary file references continue to be shared across the project.

The new tests cover targets with both different and identical language selections, direct and localized uses of the same file, storyboard resources split across source entries, and the final relationships after writing and reopening the generated project.
XcodeGen could create variant groups for localized files, but directories inside .lproj folders had no file type and were not added to the resources phase. This prevented resources such as localized Help folders from being copied by Xcode.

Treat these directories as folder references and add their variant groups to the resources phase. Allow a non-base localization to create the group when necessary, while keeping folders separate from same-named localized files.

Add coverage for serialized folder groups, mixed folder and XIB resources, target-specific language selections, folders missing from Base, and same-stem folder/file collisions.
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.

1 participant