RemafoX
RemafoX copied to clipboard
[Feat] Make generated code shorter
Problem Statement
Currently, the generated code is quite verbose and repeats things like var string: String
over and over again.
Suggested Solution
Try to extract this code into something like a protocol and just conform the types to that protocol instead. At least for Strings without parameters this should be possible and save a lot of verbose generated code.
Additional Considerations
This idea was requested by @ConfusedVorlon here.
Other ways of streamlining the code could be available, too. But make sure that auto-completion works pretty much the same way before shipping this. Also, make it an option so users with an older app version don't run into different generated code results which can cause merge conflicts.
I think this could make the generated code a lot more readable. It's pretty verbose at the moment.
I'm assuming at some point there well be additional resource types and that is why the suffix .string
is used. It would be fantastic if that could be optionally removed (that is, an option for saying "I'm only using this for strings, leave the .string suffix off).
I did also see that the code generator makes keys sentence-case. So "Button.Label.OK" becomes "Loc.Button.Label.Ok".
@michaelosity The suffix .string
is used because there's already the suffix .locStringKey
for localization that supports choosing a language in SwiftUI previews. An option for removing that could be added sometime in the future, make sure to request that feature here as an issue so I can track interest.
The same goes for alternative casing options. The current casing makes sure it works well for a variety of key naming conventions, but more customization options could be added later, just make sure to request the feature and describe your use case and rationale for your naming so I can make sure to provide the best experience for your use case as well.