Created
March 19, 2019 12:22
-
-
Save mmaridev/8df38f408d08abb220443959abb4f9b2 to your computer and use it in GitHub Desktop.
Translating django.po files using external tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| a = open("django.po") | |
| h = [x.strip() for x in a.readlines()] | |
| a.close() | |
| counter = 0 | |
| while counter < len(h): | |
| pre = counter | |
| line = h[counter] | |
| if line.startswith("msgid "): | |
| counter += 1 | |
| while not h[counter].startswith("msgstr "): | |
| counter += 1 | |
| if h[counter] == "msgstr \"\"" and not h[counter+1].startswith('"'): | |
| print(counter, h[pre][7:-1]) | |
| counter += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| a = open("django.po") | |
| h = [x.strip() for x in a.readlines()] | |
| a.close() | |
| a = open("load.txt") | |
| t = [x.strip() for x in a.readlines()] | |
| a.close() | |
| for line in t: | |
| # just place the translated string | |
| num = int(line.split(" ")[0])+1 | |
| txt = " ".join(line.split(" ")[1:]) | |
| if txt.strip(): | |
| h[num] = "msgstr \"%s\"" % txt | |
| a = open("django.po.new", "w") | |
| for line in h: | |
| a.write(line) | |
| a.write("\n") | |
| a.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment