i18n-pt_BR: synchronized with
c312ef382033
transaction: only generate file when we actually close the transaction
Before this change, the file were written for every call to `tr.close()`
exposing data to reader far too early.
transaction: extract file generation into its own function
We extract the code generating files into its own function. We are
about to move this code around to fix a bug. We'll need it in a
function soon to reuse it for "pending" logic. So we move the code
into a function instead of moving it twice.