{"action":"created","issue":{"url":"https://api.github.com/repos/smhg/gettext-parser/issues/41","repository_url":"https://api.github.com/repos/smhg/gettext-parser","labels_url":"https://api.github.com/repos/smhg/gettext-parser/issues/41/labels{/name}","comments_url":"https://api.github.com/repos/smhg/gettext-parser/issues/41/comments","events_url":"https://api.github.com/repos/smhg/gettext-parser/issues/41/events","html_url":"https://github.com/smhg/gettext-parser/pull/41","id":331785212,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk0NDMxNzMw","number":41,"title":"Sorting of entries with the same msgid isn't consistent","user":{"login":"probertson","id":133450,"node_id":"MDQ6VXNlcjEzMzQ1MA==","avatar_url":"https://avatars3.githubusercontent.com/u/133450?v=4","gravatar_id":"","url":"https://api.github.com/users/probertson","html_url":"https://github.com/probertson","followers_url":"https://api.github.com/users/probertson/followers","following_url":"https://api.github.com/users/probertson/following{/other_user}","gists_url":"https://api.github.com/users/probertson/gists{/gist_id}","starred_url":"https://api.github.com/users/probertson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/probertson/subscriptions","organizations_url":"https://api.github.com/users/probertson/orgs","repos_url":"https://api.github.com/users/probertson/repos","events_url":"https://api.github.com/users/probertson/events{/privacy}","received_events_url":"https://api.github.com/users/probertson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-06-12T23:08:23Z","updated_at":"2018-07-03T22:07:53Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/smhg/gettext-parser/pulls/41","html_url":"https://github.com/smhg/gettext-parser/pull/41","diff_url":"https://github.com/smhg/gettext-parser/pull/41.diff","patch_url":"https://github.com/smhg/gettext-parser/pull/41.patch"},"body":"A project I'm working on has instances of translation messages where the `msgid` is the same, but they have different `msgctxt` values. We use a script that crawls our code and extracts the strings, then uses this library's `po.compile()` to turn them into PO file structure before writing them to disk. We use the `sortByMsgid: true` option to attempt to minimize the changes to the PO files.\r\n\r\nApparently the way our script reads the files and constructs objects to make the PO file isn't consistent, because I've noticed that when there are pairs of strings with the same `msgid` but different `msgctxt` values, sometimes the order of the two entries changes in the PO file, even though those strings weren't modified in the source.\r\n\r\nThis PR provides a solution to this issue (and accompanying test) by modifying the sorting algorithm to first sort by `msgid`, and then, if the `msgid`s are equal, to sort by `msgctxt`. In addition to the test I added in this PR, I have tested this change with the project I mentioned, and it fixes the issue of \"moving msgctxt values\"."},"comment":{"url":"https://api.github.com/repos/smhg/gettext-parser/issues/comments/402306136","html_url":"https://github.com/smhg/gettext-parser/pull/41#issuecomment-402306136","issue_url":"https://api.github.com/repos/smhg/gettext-parser/issues/41","id":402306136,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMjMwNjEzNg==","user":{"login":"probertson","id":133450,"node_id":"MDQ6VXNlcjEzMzQ1MA==","avatar_url":"https://avatars3.githubusercontent.com/u/133450?v=4","gravatar_id":"","url":"https://api.github.com/users/probertson","html_url":"https://github.com/probertson","followers_url":"https://api.github.com/users/probertson/followers","following_url":"https://api.github.com/users/probertson/following{/other_user}","gists_url":"https://api.github.com/users/probertson/gists{/gist_id}","starred_url":"https://api.github.com/users/probertson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/probertson/subscriptions","organizations_url":"https://api.github.com/users/probertson/orgs","repos_url":"https://api.github.com/users/probertson/repos","events_url":"https://api.github.com/users/probertson/events{/privacy}","received_events_url":"https://api.github.com/users/probertson/received_events","type":"User","site_admin":false},"created_at":"2018-07-03T22:07:52Z","updated_at":"2018-07-03T22:07:52Z","author_association":"NONE","body":"@smhg:\r\nI pushed up an update to the code based on your suggestions. Let me know if I misunderstood, or if you prefer something else.\r\n\r\nThe changes are:\r\n- For `po.compile()`, the `sortByMsgId` option is renamed to `sort`\r\n- If it's a boolean (or unspecified) it behaves the same way that `sortByMsgId` did -- I believe this is the most consistent with gnu `xgettext --sort-output`\r\n- if `sort` is set to a function, that function is used as the comparator function for sorting the message entries. (This supports the use case I was trying to accomplish.)\r\n\r\nI also updated the README and tests to match."}}
{"actor":{"display_login":"probertson"}}