igorkulman / iOSLocalizationEditor

Simple macOS editor app to help you manage iOS and macOS app localizations by allowing you to edit all the translations side by side
MIT License
1.46k stars 116 forks source link

Added localization message #8

Closed Tantalum73 closed 5 years ago

Tantalum73 commented 5 years ago

As a localized string is generated, one can provide a message to help the localizer to get a sense for the context of the string.

With this commit, the message is parsed from the input file and presented to the user. Therefore I also made small UI adjustments.

Tantalum73 commented 5 years ago

Thank you for your comments. You're mostly right about the 'ideal' case. More sophisticated regex matching is needed to catch the corner cases. As I am not an expert when it comes to regex, it was fine for me to show messages only when certain conditions are met – otherwise the app still works as expected but without mentioned messages.

Your comments are absolutely valid. I will look into it as soon as I have a few minutes 🙂

P.S. SwiftLint was added after I made the fork. Therefore this PR does not make use of it, yet.

igorkulman commented 5 years ago

Personally, I do not think using regex is the right way to go. It would be really hard to write it.

I think a state machine would be needed, to get the context, just like when writing a lexer for a programming language, just with a much simpler grammar.

Tantalum73 commented 5 years ago

In the new commit I addressed some of you suggestions: When a key/value has a message and it gets updated by the user, the message is also stored. Currently, this works only when comments for the entire file are present. If not, the message is still deleted (by accident). I'm working on a more sophisticated way of importing and parsing the input file. However, I still need some time to finish the first draft of this kind of lexer.

igorkulman commented 5 years ago

Thanks for the changes. Just a few comments about the tests.

Please do not edit the existing tests data files and the existing tests but add new test files (strings file with a header, strings file just a few values with comments, strings file with all the values with comments) and new tests for those files. This should cover all the cases (I can think of).

Tantalum73 commented 5 years ago

Now, I addressed more of your comments. I wrote a parser that not only parses key-value pairs but also the corresponding messages. Xcode's license header and friends are not taken into consideration when a valid message follows. Also messages and key/value are matched.

Editing keys / values / messages and loading is tested. SwiftLint is not completely happy, yet, but I do not see where I can do better. (I disagree with most of the leading/trailing whitespace rules – whitespace sometimes makes it easier to read and to visually combine comments with code).

However, the interface-Label does not use multiple lines automatically. Currently, I don't see any way to implement this without having a visual glitch on resizing the columns.

Tantalum73 commented 5 years ago

Thank you for your great comments 🙃 Now it should be ready to be merged, I just resolved the conflicts.

igorkulman commented 5 years ago

Thanks!