File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ """Search and replace in msgstrs."""
3+
4+ import sys
5+ from pathlib import Path
6+
7+ import polib
8+
9+
10+ def replace (file : Path , from_str : str , to_str : str ) -> None :
11+ try :
12+ pofile = polib .pofile (file )
13+ except OSError :
14+ print (f"{ file } doesn't seem to be a .po file" , file = sys .stderr )
15+ return
16+ for entry in pofile :
17+ entry .msgstr = entry .msgstr .replace (from_str , to_str )
18+ pofile .save ()
19+
20+
21+ def parse_args ():
22+ import argparse
23+
24+ parser = argparse .ArgumentParser (description = __doc__ )
25+ parser .add_argument ("from_str" , help = "Replace occurrences of this string" )
26+ parser .add_argument (
27+ "to_str" ,
28+ help = "with this string." ,
29+ )
30+ parser .add_argument ("path" , nargs = "*" , type = Path )
31+ return parser .parse_args ()
32+
33+
34+ def main ():
35+ args = parse_args ()
36+ for filename in args .path :
37+ replace (filename , args .from_str , args .to_str )
38+
39+
40+ if __name__ == "__main__" :
41+ main ()
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ msgstr ""
1616
1717#: library/mailcap.rst:2
1818msgid ":mod:`!mailcap` --- Mailcap file handling"
19- msgstr ":mod:`!mailcap` --- Gestion des fichiers mailcap"
19+ msgstr ":mod:`!mailcap` — Gestion des fichiers mailcap"
2020
2121#: library/mailcap.rst:10
2222msgid ""
Original file line number Diff line number Diff line change @@ -380,7 +380,7 @@ msgid ""
380380msgstr ""
381381"*ZipFile* est aussi un gestionnaire de contexte et gère ainsi la "
382382"déclaration :keyword:`with`. Dans l'exemple, *myzip* est fermé à la fin de "
383- "la déclaration :keyword:`!with` --- même si une exception est levée ::"
383+ "la déclaration :keyword:`!with` — même si une exception est levée ::"
384384
385385#: library/zipfile.rst:247
386386msgid ""
You can’t perform that action at this time.
0 commit comments