Hive
Strings assets conflicts and compiler errors.
GitHub issue · Open
What happened?
Some keys that are similar can conflict with each other.
How do we reproduce it?
Have the following keys in Localizable.strings file:
- “Book now”
- “Book Now”
- “Confirmed!”
- “CONFIRMED”
- “TIckets”
- “TICKETS”
- “Event.booking.ticketsBooked.title”
- “event.share”
- “SignIn.forgotPasswordButton”
- “sign-in.error.invalid-email”
- “yes "geez”
- Observe the conflict errors.
Error log
Invalid redeclaration of <var_name>
Unterminated string literal.
macOS version
15.4
Tuist version
4.44.3
Xcode version
16.3
Investigate, reproduce, or fix this item in an isolated repository. Each Flight preserves its outcome and agent session.
Start a Flight and preserve its objective, outcome, and session here.
Thanks @pepicrft. We won’t be able to prioritize looking into it, but you or anyone is more than welcome to debug the issue following our contributors’ guidelines. If you run the same command from Xcode, you’ll be able to see where the error is coming from and come up with an idea for how to fix it.
Hi, I was looking for my first issue to work on and picked this one. First, I should mention that in these examples, multiple invalid key definitions are being used.
After some research, I found out that this behavior is actually expected. When I created a project with SwiftGen without Tuist and tested the same cases, I observed the same results. Since a variable name can only contain alphanumeric characters, SwiftGen strips others out. It also lowercases the first word when generating enum cases.
It seems possible to adjust this behavior by customizing the SynthesizedResourceInterfaceTemplates.stringsTemplate, though I’m not entirely sure if this would fully work or if it’s really necessary. Waiting your response to continue to work on it @pepicrft @louwe
In my opinion, there are two ways to fix this:
- Use a less rigid naming variable naming scheme so as to not generate duplicates.
- If it encounters a case it cannot handle, simply omit/comment it in the final generated file so as to not create a compiler error and maybe generate warning messages in the console.
Thanks @EmirhanKarahan for going deep into this one. If this is a SwiftGen behaviour, this is something that should be solved at that layer. If I’m not mistaken (It’s been a while without touching that area), you should be able to override the templates, which I’d suggest to use to workaround a limitation of SwiftGen.