New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Xcode 15 String catalog support #1065
Comments
Doesn't the string catalog generate code for Swift and Obj-C already? What would you want SwiftGen to do that Xcode isn't doing already? |
@ZevEisenberg It's not basically Xcode that translates |
Oh, so Xcode isn't doing code gen of constants for localizable strings into type-checked Swift and Obj-C like it is for color and images in asset catalogs? I haven't dug much into the string side of things yet. |
@ZevEisenberg Yes that's right, it will be great if SwiftGen supports string catalogs too |
Could this be solved by a macro that reads the string catalog during compilation? |
Yes we'll need to add support for it. Is there a clear file format definition from Apple somewhere? We'll need to write down the requirements, and hopefully we can reuse our parsers from strings/stringsdict parsers. Note: Macros have nothing to do with this, and won't help either because they can't read files, they only work with the existing swift code/syntax/…. |
The WWDC session video wwdc2023-10155 mentioned the String Catalog (*.xcstrings) is a simple JSON file.
Although I can't find any document about the format in details, the format is indeed pretty simple. {
"sourceLanguage" : "en",
"strings" : {
"Hello, world!" : { // <== key
"localizations" : {
"zh-Hans" : { // <== locale
"stringUnit" : {
"state" : "translated",
"value" : "你好,世界" // <== value
}
}
}
}
},
"version" : "1.0"
} |
@gongzhang Sadly, it is way more complex than this. so far, I got
to parse a part of the xcstrings files, but that are not all the possibilities, yet. |
Do we get any more further progress in this case? I have found out that Apple is not providing the generator because the code is the source of truth. Whenever you add a string key in the code then it'll be automatically generated in the asset catalog. But they support a backward compatibility, which means during compilation time they generate .strings and .stringdics file. |
Hello, any progress here? |
That's a binary plist file! bplist at the start gives it away. You can rename it to have a .plist extension and open it in Xcode. plutil can read and write them, as well as JSONSerialization in Foundation. |
So, technically, SwiftGen can be used this way? |
As I see, apps that do not use string catalogs, also use bplist for .strings and .stringsdict files in compiled app |
It is not necessarily needed but to create an enum out of the xcstring files you can use the built in JSON parser of SwiftGen. Credits @neilkachu It works this way: TODO:
Use this as config file
|
@Kondamon "Authorized rule" = "Authorized: "Priority to accounts with more than 5000 followers, View rules."";
// Expected output
"Authorized rule" = "Authorized: \"Priority to accounts with more than 5000 followers, View rules.\""; |
Hi, any progress here? |
Hi,
As apple announced a new feature in WWDC23 about the
String catalog
, Is there a plan to support that feature?https://developer.apple.com/videos/play/wwdc2023/10155/
The text was updated successfully, but these errors were encountered: