Skip to content

Instantly share code, notes, and snippets.

Created Sep 17, 2013
What would you like to do?
A Python script for swaping source and target language on a Gettext PO file.
#!/usr/bin/env python
# Copyright (C) 2013 Santiago M. Mola
# Released under the terms of the MIT License.
Swaps the source and target language in a Gettext PO file.
Learn more at
import sys
from import pofile
except ImportError:
print 'This script requires Translate Toolkit.'
print 'Download it at'
if len(sys.argv) != 2:
print 'USAGE: %s <PO file>' % sys.argv[0]
filename = sys.argv[1]
po = pofile(open(filename, 'r'))
# Swap every unit, except the first one,
# which should be the gettext header.
for i in po.units[1:]:
source = i.getsource()
target = i.gettarget()
print po
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment