Skip to content

Support for Xcode String Catalogs#931

Closed
mbernson wants to merge 2 commits into
mainfrom
feature/string-catalogs
Closed

Support for Xcode String Catalogs#931
mbernson wants to merge 2 commits into
mainfrom
feature/string-catalogs

Conversation

@mbernson
Copy link
Copy Markdown
Collaborator

@mbernson mbernson commented Feb 7, 2025

This PR adds support for Xcode String Catalogs to R.swift.

The string catalogs are parsed in a similar fashion to Strings files and Strings Dicts. They output the same type, a StringsTable.

What's changed in this PR

  • Extended StringsTable+Parser.swift with support for parsing string catalogs.
  • Added unit tests for the StringsTable parser under RswiftParsersTests.
  • Added a test app StringCatalogApp as an integration test. This is also used in the checks workflow on GitHub Actions.

Fixes #840, #861

@mbernson mbernson requested a review from tomlokhorst February 7, 2025 13:51
@mbernson
Copy link
Copy Markdown
Collaborator Author

mbernson commented Feb 7, 2025

Of course, after creating this PR I noticed that #886 also exists with an implementation of this. 🤦🏼

@selkadri
Copy link
Copy Markdown

selkadri commented Mar 9, 2025

Hello @mbernson
is that done ? will that be merged soon ?

@mbernson
Copy link
Copy Markdown
Collaborator Author

There's a big real-world app that I'm working on that uses R.swift and strings files. I'm going to convert it to string catalogs soon (probably next week) and will test it with this version of R.swift.

Also one of the unit tests I wrote is failing on the CI, I have to fix that. But other than that it's done :)

@tomlokhorst @mac-cain13 Is there anything else I can do to help get this feature across the finish line? It's also fine for me if PR #886 is merged instead of this one.

This fixes non-determinism in the parser.
Also expanded the tests a little bit.
@alexShekotev
Copy link
Copy Markdown

When will the release for CocoaPods be out? Version 7.8.0 doesn’t include any changes

@mbernson
Copy link
Copy Markdown
Collaborator Author

This localization workflow with typed localized strings is now supported in Xcode 26! That removes the need for this PR too.

It supports multiple parameters and multiple string tables too. You may have to turn on the build setting "Generate String Catalog Symbols”.

Watch this WWDC25 talk from about minute 14:00 to learn more about it.

@mbernson mbernson closed this Jun 19, 2025
@Wuou
Copy link
Copy Markdown

Wuou commented Feb 5, 2026

This localization workflow with typed localized strings is now supported in Xcode 26! That removes the need for this PR too.这种带类型化本地化字符串的本地化工作流程现在已在 Xcode 26 中得到支持!这也消除了对这次 PR 的需求。

It supports multiple parameters and multiple string tables too. You may have to turn on the build setting "Generate String Catalog Symbols”.它支持多个参数和多个字符串表。您可能需要打开构建设置“生成字符串目录符号”。

Watch this WWDC25 talk from about minute 14:00 to learn more about it.观看这个 WWDC25 演讲,从大约 14:00 分钟开始,了解更多关于它的信息。

That's only for SwiftUI, it's still not supported for UIKit projects

@mbernson
Copy link
Copy Markdown
Collaborator Author

mbernson commented Feb 5, 2026

@Wuou There is an overload for String(localized:) that takes a LocalizedStringResource. That can be used in UIKit. For example:

let label = UILabel()
label.text = String(localized: .helloWorld)

See Apple documentation: https://developer.apple.com/documentation/swift/string/init(localized:options:)

@Wuou
Copy link
Copy Markdown

Wuou commented Feb 6, 2026

@Wuou There is an overload for String(localized:) that takes a LocalizedStringResource. That can be used in UIKit. For example:

let label = UILabel()
label.text = String(localized: .helloWorld)

See Apple documentation: https://developer.apple.com/documentation/swift/string/init(localized:options:)

But I tried, and it works in the library I created. But in the main project, when I tried to do what I saw in the video, xcode didn't automatically generate the keys for me, and when I manually added the keys, I couldn't get any code hints. It's weird

@mbernson
Copy link
Copy Markdown
Collaborator Author

mbernson commented Feb 6, 2026

@Wuou In your project's Xcode build settings, have you enabled "Generate String Catalog Symbols"?

@Wuou
Copy link
Copy Markdown

Wuou commented Feb 9, 2026

@Wuou In your project's Xcode build settings, have you enabled "Generate String Catalog Symbols"?

Oh, thank you for your help. It's my table name that doesn't match. However, there is a problem, this interface only supports iOS16 and above, we apply minimum support iOS13
How can I handle this situation?

It seems that this generation tool is still used in the low version

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.

Support xcstring on Xcode 15

4 participants