Skip to content

Commit ed69003

Browse files
committed
Add option "-W" (or "--no-whitespace-eol") to not check trailing whitespace at end of lines inside strings
1 parent 6285621 commit ed69003

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
* check compilation (with command `msgfmt -c`)
77
* for each translation, the script can check:
8-
* number of lines in translated string
9-
* whitespace at beginning/end of string
10-
* punctuation at end of string
8+
* number of lines in translated strings
9+
* whitespace at beginning/end of strings
10+
* trailing whitespace at end of lines inside strings
11+
* punctuation at end of strings
1112
* spelling
1213

1314
The script requires Python >= 2.7.
@@ -35,12 +36,14 @@ Options:
3536
* `-m`, `--only-misspelled`: display only misspelled words (no error, line
3637
number and translation)
3738
* `-w`, `--no-whitespace`: do not check whitespace at beginning/end of strings
39+
* `-W`, `--no-whitespace-eol`: do not check whitespace at end of lines inside
40+
strings
3841
* `-e`, `--extract`: display all translations and exit (all checks except
3942
compilation are disabled in this mode)
4043
* `-q`, `--quiet`: quiet mode: only display number of errors
4144
* `-v`, `--version`: display version and exit
4245

43-
Environment variable 'MSGCHECK_OPTIONS' can be set with some default options.
46+
Environment variable `MSGCHECK_OPTIONS` can be set with some default options.
4447

4548
The script returns following exit code:
4649
0: all files checked are OK (0 errors) (or --extract given)
@@ -70,3 +73,20 @@ The script returns following exit code:
7073
valeur courante
7174
======================================================================
7275
fr.po: 3 errors (almost good!)
76+
77+
## Copyright
78+
79+
Copyright (C) 2009-2014 Sébastien Helleu <[email protected]>
80+
81+
This program is free software; you can redistribute it and/or modify
82+
it under the terms of the GNU General Public License as published by
83+
the Free Software Foundation; either version 3 of the License, or
84+
(at your option) any later version.
85+
86+
This program is distributed in the hope that it will be useful,
87+
but WITHOUT ANY WARRANTY; without even the implied warranty of
88+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89+
GNU General Public License for more details.
90+
91+
You should have received a copy of the GNU General Public License
92+
along with this program. If not, see <http://www.gnu.org/licenses/>.

msgcheck.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
except:
4242
pass
4343

44-
VERSION = '2.3'
44+
VERSION = '2.4'
4545

4646

4747
class PoMessage:
@@ -328,6 +328,31 @@ def check_whitespace(self, msg):
328328
errors += 1
329329
return errors
330330

331+
def check_whitespace_eol(self, msg):
332+
"""
333+
Check trailing whitespace at the end of lines in a string.
334+
Return the number of errors detected.
335+
"""
336+
errors = 0
337+
for mid, mstr in msg.messages:
338+
if not mid or not mstr:
339+
continue
340+
idlines = mid.split('\n')
341+
strlines = mstr.split('\n')
342+
if len(idlines) < 2 or len(idlines) != len(strlines):
343+
continue
344+
for i in range(0, len(idlines)):
345+
endin = len(idlines[i]) - len(idlines[i].rstrip(' '))
346+
endout = len(strlines[i]) - len(strlines[i].rstrip(' '))
347+
if (endin > 0 or endout > 0) and endin != endout:
348+
self.error(msg, mid, mstr,
349+
'different whitespace at end of a line: {0} in '
350+
'string, {1} in translation'.format(endin,
351+
endout))
352+
errors += 1
353+
break
354+
return errors
355+
331356
def check_spelling(self, msg):
332357
"""
333358
Check spelling.
@@ -377,6 +402,8 @@ def check(self):
377402
errors += self.check_punctuation(msg)
378403
if not self.args.no_whitespace:
379404
errors += self.check_whitespace(msg)
405+
if not self.args.no_whitespace_eol:
406+
errors += self.check_whitespace_eol(msg)
380407
if self.args.spelling:
381408
errors += self.check_spelling(msg)
382409
return errors
@@ -419,6 +446,9 @@ def main():
419446
parser.add_argument('-w', '--no-whitespace', action='store_true',
420447
help='do not check whitespace at beginning/end of '
421448
'strings')
449+
parser.add_argument('-W', '--no-whitespace-eol', action='store_true',
450+
help='do not check trailing whitespace at end of '
451+
'lines inside strings')
422452
parser.add_argument('-e', '--extract', action='store_true',
423453
help='display all translations and exit '
424454
'(all checks except compilation are disabled in this '

0 commit comments

Comments
 (0)