-
Notifications
You must be signed in to change notification settings - Fork 779
Parse localizable strings comments #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Very cool! Thanks for this PR! I quickly scrolled through this, I'll look in to it more deeply when I have some more time. The warnings about duplicate identifiers should be part of the code generation step, not the parsing step. That's because multiple files can be merged together at code generation time. When parsing it is not yet known which keys will become duplicate unique identifiers. In this case that means the As for the rest of it; I'll take a closer look later, or maybe someone else will before that. |
The warning I added is meant for duplicate keys in a single file; I thought there was a todo somewhere about maybe adding a warning for that. NSPropertyListSerialization just silently takes the last of the duplicates. edit: this was a bit snarky, sorry. If that's the wrong place for the warning then I can move it no problem. But I'm not sure we're thinking of the same warning? |
Standard R.swift behaviour for duplicate keys (single file or not), is to skip generating code for that key and only print a warning. An extra feature would be to extend that behaviour to strings files. That means collecting all keys (including duplicates within a single file), and have the code generator print the warnings (which it already does). This also allows for extensibility in the future, where some other process between the parser and the code generator does something with all the keys. Like show them to the user or filter them based on some heuristic. Again, this is an additional feature that R.swift currently doesn't have. But the reason for building a custom parser, instead of using the plist parser, is to enable additional features. |
The returned struct includes any comment associated with the strings file entry. Returning an array allows for future features such as detecting duplicates within a single file.
4497f01
to
7cf54f9
Compare
Here's a first attempt at the rest of this PR, getting the parsed I removed the warning emitted during parsing (thanks @tomlokhorst for patiently explaining). We can add it to the appropriate place sometime later. Here's the todo I was talking about that mentions this warning, if anyone's curious (shout out to fellow Nolan creating that file). I've also modified the regex a bit to only consider a comment directly preceding (i.e. up to 1 line away from) a |
It's been a month, is there anything I can do to move this PR along? Y'all won't hurt my feelings if you share what you don't like about it! |
Hey Nolan, sorry for leaving this PR hanging for over a month... Due to both me and @mac-cain13 being busy with other things, R.swift maintenance is on a bit of a summer break at the moment. Unfortunately that means issues and pull requests start stacking up. Sorry about that. The next thing I plan on doing for this PR is;
Hopefully I'll find the time to do that in the next week or so. |
No worries, enjoy the break! |
One thing that would be nice to add to this PR: Tests :-)
|
I just tested this on my biggest project that uses I think these should be the test cases:
Also nice to have are single line comments:
|
Tests sound good! I have a question about how to implement them. Does it make sense to include a |
Yes, I do think it makes sense to add a The Indeed, the tests can also use the |
Cool, that makes sense. I've added the Thanks for so patiently explaining like every part of this project to me as I go. I started messing with the regex to consider |
The |
I've created a Swift 3 version of this PR: #283 |
This is an attempt to start implementing #232.
.strings
files so we can capture comment..strings
file (previously the last value was silently chosen the winner)..strings
file entry, if present, inR.generated.swift
.I'm a bit stuck on the last part, where we carry the parsed strings comment all the way through to
R.generated.swift
. I'd appreciate some guidance! (Or if someone wants to just take it from here, go for it!)