Skip to content

Add LocalizedString support to Text - #892

Open
VictorPuga wants to merge 4 commits into
twostraws:mainfrom
victorpuga-forks:localized-string-resource
Open

VictorPuga wants to merge 4 commits into
twostraws:mainfrom
victorpuga-forks:localized-string-resource

Conversation

@VictorPuga

@VictorPuga VictorPuga commented Oct 2, 2026 •

Copy link
Copy Markdown

String literals passed to Text are now looked up in the site's Localizable.xcstrings, using the page's language. String variables still render verbatim.

LocalizedStringResource doesn't exist on Linux, and SwiftPM doesn't compile .xcstrings there. So this adds a LocalizedString type that reads the catalog JSON directly, with identical output on macOS and Linux.

Site.localizationCatalog: URL? points at the catalog and defaults to nil. Ship it as a .copy resource, since .process removes the original file.

Lookup order is the full language identifier, the language code, the source language, then the key. Plural and device variations are not supported.

🤖 Generated with Claude Code

VictorPuga and others added 2 commits October 2, 2026 15:06
LocalizedStringResource now conforms to InlineElement, so it can be used
anywhere inline content is accepted.
Resources are resolved using the page's language and the new
Site.localizationBundle, which defaults to .main.
Any bundle set on an individual resource is ignored.

Text gains an initializer taking a LocalizedStringResource, and the
InlineElement initializer is disfavored so string literals are localized.
String variables still render verbatim.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The LocalizedStringResource tests no longer build a bundle in a temporary
directory.
They now resolve strings from a Localizable.xcstrings catalog in the test
target, which is processed into Bundle.module.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@MrSkwiggs

Copy link
Copy Markdown
Collaborator

Thanks for your work @VictorPuga. This looks good to me, but I'll be curious to see whether this works on Linux. We've had issues with string catalogs & LocalizedStringResource in the past.

@VictorPuga

Copy link
Copy Markdown
Author

Yeah, I just tried out building a site with this localization on Linux and got a bunch of errors. Let me try and find an alternative.

VictorPuga and others added 2 commits October 3, 2026 09:31
LocalizedStringResource is not available on Linux, and string catalogs
processed by SwiftPM there are copied as-is instead of compiled into
.lproj files, so Bundle lookups find nothing.

Ignite now has its own LocalizedString type, which string literals
and interpolations create, and reads Localizable.xcstrings directly
as JSON on every platform.
Strings resolve using the page's language, falling back from the full
language identifier to the language code, then the source language,
then the key.
Plural and device variations are not supported.

Site.localizationBundle is replaced by Site.localizationCatalog, a URL
that defaults to nil.
The catalog must be declared as a .copy resource, because .process
compiles it and removes the original file.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Remove the unused SwiftUI import from the Button tests, and check for
built files with FileManager instead of URL.checkPromisedItemIsReachable(),
which only exists on Apple platforms.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@VictorPuga VictorPuga changed the title Add LocalizedStringResource support to Text Add LocalizedString support to Text Oct 3, 2026
@VictorPuga

Copy link
Copy Markdown
Author

I've pushed a new approach:

  • Ignite has its own LocalizedString type, which string literals still resolve to.
  • Ignite reads the .xcstrings JSON directly, so macOS and Linux behave the same.
  • Site.localizationBundle is replaced by Site.localizationCatalog: URL?, and the catalog must be shipped as a .copy resource.

The test suite passes on both macOS and Linux (aarch64, Swift 6.3.2). I also fixed two Apple-only calls in existing tests that broke the Linux build. Plural and device variations aren't supported yet.

Could you take another look?

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