SwiftGen / SwiftGen

The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs!
MIT License
9.17k stars 728 forks source link

Dot support in identifiers for structure #93

Closed mgorbach closed 8 years ago

mgorbach commented 8 years ago

In our app, we use structured identifiers as the string keys for localizable strings, such as error.title.password-required. Before integrating swiftgen, we structured these ourselves into struct or or enum definitions that had a hierarchy, i.e. one for error, one for title. It would be great if swiftgen could do the same thing and pick up the structure from dot-delimited string keys.

AliSoftware commented 8 years ago

That's a great idea! :+1: In fact I use that convention with dots too and I agree that would be cool :sunglasses:


Note: I'm a little busy atm so even if it would be a cool to have this feature, I'll probably not be my top priority and I'll probably not implement it very soon. But don't hesitate to start a PR to try it, I'll still be around to help on the implementation if needs be :wink:

Jeehut commented 8 years ago

@mgorbach: Until this is implemented, you might want to check out https://github.com/JiriTrecak/Laurine which does exactly what you need. It doesn't support the images, colors etc. though – only Localizations. I'm currently using swiftgen for everything except Localizations alongside Laurine for exactly this reason.

mgorbach commented 8 years ago

Taking a pass at this now.

Jeehut commented 8 years ago

Laurine seems to be a little slowish and also not really maintained any more. Therefore I'd like this feature to be added to SwiftGen and plan to help getting it done when I have some time. Note that I'm using the uppercase variant of @mgorbach's suggested structure with underscores instead of dashes as separators. I'll try to make both variants convert to respective sub structures when I start implementing this. Stay tuned. You can expect first results within the next few weeks.

AliSoftware commented 8 years ago

:+1:

Jeehut commented 8 years ago

As promised I implemented one approach to tackle this issue. See #148 for additional details. Please note that i think we can release this much earlier than in v2.0.0 (which it is marked for right now) as my implementation doesn't break any existing features (or at least shouldn't – tests are passing, too).

AliSoftware commented 8 years ago

This is now merged (and will be in next release) thanks to the work by @Dschee in #148 but as explained in https://github.com/AliSoftware/SwiftGen/pull/148#issuecomment-229018218 that work is only the first working step, providing a template that generates nested structs.

I hope people are gonna get inspired from the work done by @Dschee to add more templates in the future, for example some structured templates based on structs instead of enums (to be able to use dot chain instead of nested chain) and propose some other template variants depending on how they want the generated code to look in their projects 👍