SwiftGen / SwiftGen

The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Public access to either the fallback string or the ability to specify locale

michaeldwilliams opened this issue · comments

This may be a really niche request but I can't be the only one with this issue.

Background:
We have created a Swift UI View modifier that allows us to log button taps to our analytics platform. It takes a string, which is usually the button text. It would be great if we could use the generated localized strings variable but that would cause localized string values to be sent to our analytics platform (we just want the English values). So we are stuck passing the string directly.

Problem:
The problem is when the button string value changes in the future and we update the .strings file, Its easy for an engineer to forget to also update the analytics value.

Request:
Can we either get access to the fallback string or add the ability to optionally specify the locale when we call the L10n namespace?

Closing because I can't really think of a way to do this myself without completely overhauling how the whole thing works. Feel free to re-open if someone else has an idea.

I've been thinking of switching to property wrappers or something similar, which would give you the translation as the value, but you'd be able to access the underlying structure, which would contain (for example) the translation key & fallback value.

Same idea for the asset catalog templates, where people've complained for a while they'd rather directly access images/colors, instead of having to invoke someAsset.color and someAsset.image.

But all that has been waiting a bit until I can bump the minimum supported swift version. Right now we just have swift 4 & 5 templates, but a LOT has changed in swift 5, so we need to rethink that system.