-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from collections import defaultdict | ||
from itertools import chain | ||
|
||
|
||
def msg_key(entry): | ||
return (entry.msgid, entry.msgid_plural, entry.msgctxt) | ||
|
||
|
||
def merge_catalogs(project): | ||
""" | ||
Return a nested dictionary of the form: | ||
``messages[msg_key][language, domain] = entry`` | ||
""" | ||
|
||
messages = defaultdict(dict) | ||
|
||
for catalog in project.catalogs.all(): | ||
for entry in catalog.po: | ||
messages[msg_key(entry)][catalog.language_code, catalog.domain] = entry | ||
|
||
return messages | ||
|
||
|
||
def messages_as_table(project): | ||
merged = merge_catalogs(project) | ||
language_domain_combinations = sorted( | ||
set(chain.from_iterable(thing.keys() for thing in merged.values())) | ||
) | ||
|
||
header = [ | ||
"msgctxt", | ||
"msgid", | ||
"msgid_plural", | ||
"comment", | ||
"tcomment", | ||
"flags", | ||
*( | ||
f"{language_code}:{domain}" | ||
for language_code, domain in language_domain_combinations | ||
), | ||
] | ||
data = [] | ||
|
||
for entries in merged.values(): | ||
any_entry = next(iter(entries.values())) | ||
|
||
row = [ | ||
any_entry.msgctxt, | ||
any_entry.msgid, | ||
any_entry.msgid_plural, | ||
any_entry.comment, | ||
any_entry.tcomment, | ||
", ".join(any_entry.flags), | ||
] | ||
|
||
for language_code_domain in language_domain_combinations: | ||
if entry := entries.get(language_code_domain): | ||
row.append(entry.msgstr) | ||
else: | ||
row.append("") | ||
|
||
data.append(row) | ||
|
||
return [header, *data] |
This file contains 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
This file contains 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
This file contains 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
7eb10ae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merci!
7eb10ae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nada
msgstr_plural
fehlt noch, aber wir brauchenngettext()
im entsprechenden Projekt nicht (aber in anderen Projekten schon...!)poxls ignoriert die
*_plural
Varianten aber auch. D.h. ist kein Rückschritt, abgesehen vom fehlenden Import.