FlineDev / RemafoX

Report issues, request features or ask for help for the ReMafoX app here.
30 stars 1 forks source link

[Feat] Find NSLocalizedString in code and add them to Strings files #8

Open Sn0wfreezeDev opened 1 year ago

Sn0wfreezeDev commented 1 year ago

Problem Statement

I was a big fan of bartycrouch and I am happy to see that you are working on a Swift based version. The main feature I liked about Barty crouch was the ability to fetch all Keys from NSLocalizedString and add them to the Localizable.strings file.

When working on an app with multiple people it is easier if just one person keeps an eye on localization. The others just add their basic strings using NSLocalizedString or maybe even LocalizedStringKey. As far as I see it now the option to add automatically get all strings to the Localizable.strings file is not implemented.

Suggested Solution

Adding a Regex parser with the new Swift Regex features that finds all NSLocalizedStrings. Then these are added to the Localizable.strings file (which are known by ReMaFox already). In the next step the Generated resources file gets updated and the discovered NSLocalizedStrings gets replaced by a fixed enum.

Additional Considerations

For me the most important issue is that I want to simplify the way to translate strings. ReMaFox is great, but it would require that every dev has it installed and uses the keyboard shortcut to add new strings. Other methods of adding a new string would need interaction with the Localizable.strings file. Just typing in a quick NSLocalizedString and then handling the translations later might improve the workflow.

Sn0wfreezeDev commented 1 year ago

I would also be happy to contribute if you plan to go open source 😊

Jeehut commented 1 year ago

@Sn0wfreezeDev Thank you for requesting this feature and explaining your use case. As you might have already recognized, unlike BartyCrouch, ReMafoX is designed in a way that no code file parsing is ever needed. This has multiple advantages, for example not losing your Xcode edit history (undo/redo) and also that the "Add Translation" UI can give developers hints when adding new keys, e.g. by automatically detecting a %d and providing a better UI for this case (pluralization support without the complexity).

I hope that this new workflow of adding translations is so easy, that all developers in a team can be taught to use it. It allows me to provide more useful features in the future as well, such as providing a screenshot of the related screen for translators if the developer happens to have the simulator open for example. By the way, I personally would recommend for all developers in a team to always have localization (and other accessibility aspects) in mind when writing their code.

Having that said, I do see your use case where the "localization" responsibility is given to a single developer and I think it makes sense to support it in ReMafoX, too. For version 1.0 the feature set is already established. But I'm planning to release one new feature per month after that, which one depends on the number of upvotes (👍) on the feature request and the Size: label (see also the Roadmap section in the README).


In the meantime, please note that while ReMafoX is designed to be the spiritual successor to BartyCrouch, the latter isn't going anywhere and ReMafoX was designed in a way that it can totally be used in combination with BartyCrouch – just keep your BartyCrouch build script above the ReMafoX build script. Feel free to keep whatever workflow you had with BartyCrouch to find and add NSLocalizedString references in code to your Strings files. ReMafoX would then generate the Swift enum based on the resulting Localizable.strings file and you would be able to replace the NSLocalizedString entry with a call to the ReMafoX enum. This step would need to be done manually though as of now because BartyCrouch has no support for ReMafoX-generated .strings files.

And no, ReMafoX isn't going to be open source. I went full-time Indie this year and ReMafoX is my first app – while it will have a decent Free tier, I have to earn money somehow. 😅 But as you offered to implement things yourself, you can totally add support for ReMafoX-style generated enums to BartyCrouch, much like BartyCrouch currently already supports both NSLocalizedString and SwiftGen-style generated enums. See the transformer option in the update.transform config within .bartycrouch.toml which can currently have the values foundation (= NSLocalizedString) or swiftgenStructured. You could simply add the option remafox and instead of generating a L10n.Some.key code reference you would create a Loc.Some.Key.string code reference. Should be easy enough, just lookup how things were done for SwiftGen and adjust.

In any case, thank you again for requesting this feature. Your feedback is much appreciated!

Jeehut commented 1 year ago

Please note that in #18 a feature was requested where the solution is somewhat related to this problem. I will try to consider finding a solution that also covers this feature request, at least on a file level. A full project-wide implementation might come later, depending on how many people vote on this feature.