Skip to content
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

Add option to sort translations by keys in resulting Strings files #26

Closed
Jeehut opened this issue Jun 23, 2016 · 11 comments
Closed

Add option to sort translations by keys in resulting Strings files #26

Jeehut opened this issue Jun 23, 2016 · 11 comments
Assignees

Comments

@Jeehut
Copy link
Member

Jeehut commented Jun 23, 2016

Currently when a Strings file is saved the order of the translations isn't changed, new translations are simply added at the end of the list. There should be an option to sort them by keys which is especially useful for the code sub command when using structured keys like 'SETTINGS.USER_SECTION.LOGOUT'.

@Jeehut Jeehut self-assigned this Jun 23, 2016
@kafejo
Copy link

kafejo commented Jul 31, 2016

I would also consider time sort option - it means that new strings will be added at the end. Because I often find myself searching through the localizable file to find a new key I've just added.

@Jeehut
Copy link
Member Author

Jeehut commented Jul 31, 2016

@kafejo That should be the current behavior though, are you sure it's not the case for you?

@kafejo
Copy link

kafejo commented Jul 31, 2016

Actually I've examined it and current behaviour sorts it by key! Strange 😅
from our strings file:

… 
/* No advert present. */
"advert-detail.no-advert-error" = "The advert does not exist.";

/* Reissue action button title of advert peek preview */
"advert-preview.actions.sold" = "Reissue advert";

/* The user does not exist. */
"user-profile.no-user" = "The user does not exist.";

/* Camera */
"action-sheet.camera" = "Take photo";

/* Choose option */
"action-sheet.choose-option" = "Choose option";

/* Library */
"action-sheet.library" = "Photo library";

/* Will ship */
"adver.will-ship" = "Will ship";

/* Advert does not exist. */
"advert-administration.advert-does-not-exist" = "Advert does not exist.";

/* Restricted camera access */
"advert-administration.camera-access-restricted" = "Camera access for this user is restricted.";
… 

We use Bartycrouch run script in aggregated target

if [ $CONFIGURATION == Debug ]; then
if which bartycrouch > /dev/null; then
# Incrementally update all Storyboards/XIBs strings files
bartycrouch interfaces -p "$PROJECT_DIR"

# Add new keys to Localizable.strings files from NSLocalizedString in code
bartycrouch code -p "$PROJECT_DIR/maarked" -l "$PROJECT_DIR" -a
else
echo "warning: BartyCrouch not installed, download it from https://github.com/Flinesoft/BartyCrouch"
fi
fi

@Jeehut
Copy link
Member Author

Jeehut commented Jul 31, 2016

I'm sorry, I still don't get it. What's sorted about those keys in your example? As far as I can see advert-detail.no-advert-error (lets call it A) appears first, then there's a user-profile.no-user key in between (B) and further down there is advert-administration.advert-does-not-exist (C).

If those keys were sorted then the order would need to be: C-A-B. But if the quoted file is the result of BartyCrouch then it's clearly not sorting by anything, instead it's just adding new ones as it should.

Btw: I think the best way to explain any odd behavior you wouldn't expect is to fork BartyCrouch, add a new test case that reproduces the unexpected behavior and send it in as a pull request marked as [WIP] (work in progress). This way I would both understand it and also have a test that could make sure an implementation of the feature actually does the right thing. :)

@Jeehut
Copy link
Member Author

Jeehut commented Aug 25, 2016

I just happened to come across this same issue in a project where PhraseApp is used. Gonna investigate this and report once I have results.

@Jeehut
Copy link
Member Author

Jeehut commented Aug 27, 2016

@kafejo I have just added a simple test in fa9739d to reproduce the issue we both have come across but without success. I expected the test to fail as we have both seen such a thing happen but it didn't – the new key was added at the end of the file.

I also copied the entire Localizable.strings over from the project where I had seen this issue – still the new key was added at the end, like expected. I think now that the test is setup you can easily alter the existing Localizable.strings file and/or the SwiftExample3.swift file(s) until you succeed in reproducing this issue. Once we know what the problem is we can fix it.

@kafejo
Copy link

kafejo commented Aug 28, 2016

Nice. I will take a look at it.

@Jeehut
Copy link
Member Author

Jeehut commented Oct 4, 2016

@kafejo I just found the issue with the reordering of existing keys and fixed it – just update to version 3.3.5 to see for yourself. I hope that fixes your issue! :)

@kafejo
Copy link

kafejo commented Oct 5, 2016

Cool! Thanks! 🎉

@Jeehut
Copy link
Member Author

Jeehut commented Dec 14, 2016

I just implemented this feature and released a new version with it – use the -s (sort-by-keys) option to sort your files by their keys starting with version 3.5.0. 🎉

@Jeehut Jeehut closed this as completed Dec 14, 2016
@Jeehut
Copy link
Member Author

Jeehut commented Dec 14, 2016

Please note that I just released version 3.5.1 which changes the behavior of the sort-by-keys option slightly: It sorts entries with empty translations to the end so untranslated keys can be easily found as expected. Another run of BartyCrouch after translating the keys will sort them correctly. I think this is gonna make this option much more useful in practice! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants