Update check_po to support msgctxt strings
This commit is contained in:
parent
41720c5a7e
commit
ab5d12bf34
96
po/check_po
96
po/check_po
@ -276,9 +276,11 @@ class Msgid:
|
|||||||
fuzzy_pat = re.compile( 'fuzzy' )
|
fuzzy_pat = re.compile( 'fuzzy' )
|
||||||
tips_xml_pat = re.compile( r'tips\.xml' )
|
tips_xml_pat = re.compile( r'tips\.xml' )
|
||||||
def __init__( self, msgnr, lineno ):
|
def __init__( self, msgnr, lineno ):
|
||||||
|
self._msgctxt = [] # For debugging purpose the original text
|
||||||
self._msgid = [] # For debugging purpose the original text
|
self._msgid = [] # For debugging purpose the original text
|
||||||
self._msgidp = [] # For debugging purpose the original text
|
self._msgidp = [] # For debugging purpose the original text
|
||||||
self._msgstr = [] # For debugging purpose the original text
|
self._msgstr = [] # For debugging purpose the original text
|
||||||
|
self.msgctxt = ''
|
||||||
self.msgid = ''
|
self.msgid = ''
|
||||||
self.msgidp = ''
|
self.msgidp = ''
|
||||||
self.msgstr = [] # This is a list to support plural
|
self.msgstr = [] # This is a list to support plural
|
||||||
@ -299,6 +301,15 @@ class Msgid:
|
|||||||
else:
|
else:
|
||||||
sys.stdout.write( ''.join( self._msgstr ) )
|
sys.stdout.write( ''.join( self._msgstr ) )
|
||||||
|
|
||||||
|
def add_msgctxt( self, line, lineno ):
|
||||||
|
self._msgctxt.append( line )
|
||||||
|
line = re.sub( r'msgctxt\s+', '', line )
|
||||||
|
line = line.strip()
|
||||||
|
if line[0] != '"' or line[-1:] != '"':
|
||||||
|
print("ERROR at line %d: Missing quote." % lineno)
|
||||||
|
line = strip_quotes( line )
|
||||||
|
self.msgctxt += line
|
||||||
|
|
||||||
def add_msgid( self, line, lineno ):
|
def add_msgid( self, line, lineno ):
|
||||||
self._msgid.append( line )
|
self._msgid.append( line )
|
||||||
line = re.sub( r'msgid\s+', '', line )
|
line = re.sub( r'msgid\s+', '', line )
|
||||||
@ -345,6 +356,7 @@ def create_new_Msgid( msgs, lineno ):
|
|||||||
def read_msgs( fname ):
|
def read_msgs( fname ):
|
||||||
empty_pat = re.compile( r'^ \s* $', re.VERBOSE )
|
empty_pat = re.compile( r'^ \s* $', re.VERBOSE )
|
||||||
comment_pat = re.compile( r'\#', re.VERBOSE )
|
comment_pat = re.compile( r'\#', re.VERBOSE )
|
||||||
|
msgctxt_pat = re.compile( r'msgctxt \s+ "', re.VERBOSE )
|
||||||
msgid_pat = re.compile( r'msgid \s+ "', re.VERBOSE )
|
msgid_pat = re.compile( r'msgid \s+ "', re.VERBOSE )
|
||||||
msgid_plural_pat = re.compile( r'msgid_plural \s+ "', re.VERBOSE )
|
msgid_plural_pat = re.compile( r'msgid_plural \s+ "', re.VERBOSE )
|
||||||
msgstr_pat = re.compile( r'msgstr (\[\d\])? \s+ "', re.VERBOSE )
|
msgstr_pat = re.compile( r'msgstr (\[\d\])? \s+ "', re.VERBOSE )
|
||||||
@ -355,13 +367,14 @@ def read_msgs( fname ):
|
|||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
|
||||||
# parse it like a statemachine
|
# parse it like a statemachine
|
||||||
NONE = 'NONE' # Nothing detected, yet
|
NONE = 'NONE' # Nothing detected, yet
|
||||||
CMNT = 'CMNT' # Inside comment part
|
CMNT = 'CMNT' # Inside comment part
|
||||||
MSGID = 'msgid' # Inside msgid part
|
MSGCTXT = 'msgctxt' # Inside msgctxt part
|
||||||
MSGIDP = 'msgid_plural' # Inside msgid_plural part
|
MSGID = 'msgid' # Inside msgid part
|
||||||
MSGSTR = 'msgstr' # Inside msgstr part
|
MSGIDP = 'msgid_plural' # Inside msgid_plural part
|
||||||
STR = 'STR' # A continuation string
|
MSGSTR = 'msgstr' # Inside msgstr part
|
||||||
OLD = 'OLD' # An old pattern with #~
|
STR = 'STR' # A continuation string
|
||||||
|
OLD = 'OLD' # An old pattern with #~
|
||||||
|
|
||||||
global msgs
|
global msgs
|
||||||
state = NONE
|
state = NONE
|
||||||
@ -380,6 +393,8 @@ def read_msgs( fname ):
|
|||||||
next_state = OLD
|
next_state = OLD
|
||||||
elif comment_pat.match( line ):
|
elif comment_pat.match( line ):
|
||||||
next_state = CMNT
|
next_state = CMNT
|
||||||
|
elif msgctxt_pat.match( line ):
|
||||||
|
next_state = MSGCTXT
|
||||||
elif msgid_pat.match( line ):
|
elif msgid_pat.match( line ):
|
||||||
next_state = MSGID
|
next_state = MSGID
|
||||||
elif msgid_plural_pat.match( line ):
|
elif msgid_plural_pat.match( line ):
|
||||||
@ -394,13 +409,19 @@ def read_msgs( fname ):
|
|||||||
|
|
||||||
#print("%(state)d->%(next_state)d\t%(line)s" % vars())
|
#print("%(state)d->%(next_state)d\t%(line)s" % vars())
|
||||||
if state == NONE:
|
if state == NONE:
|
||||||
# expect msgid or comment or old stuff
|
# expect msgctxt, msgid, comment or old stuff
|
||||||
if next_state == CMNT:
|
if next_state == CMNT:
|
||||||
state = CMNT
|
state = CMNT
|
||||||
# Start with an empty new item
|
# Start with an empty new item
|
||||||
msg = create_new_Msgid( msgs, lineno )
|
msg = create_new_Msgid( msgs, lineno )
|
||||||
msg.add_cmnt( line )
|
msg.add_cmnt( line )
|
||||||
|
|
||||||
|
elif next_state == MSGCTXT:
|
||||||
|
state = MSGCTXT
|
||||||
|
# Start with an empty new item
|
||||||
|
msg = create_new_Msgid( msgs, lineno )
|
||||||
|
msg.add_msgctxt( line, lineno )
|
||||||
|
|
||||||
elif next_state == MSGID:
|
elif next_state == MSGID:
|
||||||
state = MSGID
|
state = MSGID
|
||||||
# Start with an empty new item
|
# Start with an empty new item
|
||||||
@ -429,7 +450,7 @@ def read_msgs( fname ):
|
|||||||
'(state = %(state)s)' % vars() )
|
'(state = %(state)s)' % vars() )
|
||||||
|
|
||||||
elif state == CMNT:
|
elif state == CMNT:
|
||||||
# Expect more comment, or msgid.
|
# Expect more comment, msgctxt, or msgid.
|
||||||
# If msgstr or string it is flagged as error.
|
# If msgstr or string it is flagged as error.
|
||||||
if next_state == CMNT:
|
if next_state == CMNT:
|
||||||
if msg:
|
if msg:
|
||||||
@ -439,6 +460,13 @@ def read_msgs( fname ):
|
|||||||
# Skip for now
|
# Skip for now
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
elif next_state == MSGCTXT:
|
||||||
|
state = MSGCTXT
|
||||||
|
if not msg:
|
||||||
|
# Start with an empty new item
|
||||||
|
msg = create_new_Msgid( msgs, lineno )
|
||||||
|
msg.add_msgctxt( line, lineno )
|
||||||
|
|
||||||
elif next_state == MSGID:
|
elif next_state == MSGID:
|
||||||
state = MSGID
|
state = MSGID
|
||||||
if not msg:
|
if not msg:
|
||||||
@ -467,6 +495,43 @@ def read_msgs( fname ):
|
|||||||
else:
|
else:
|
||||||
raise CheckException( 'Unexpected state in po parsing '
|
raise CheckException( 'Unexpected state in po parsing '
|
||||||
'(state = %(state)s)' % vars() )
|
'(state = %(state)s)' % vars() )
|
||||||
|
elif state == MSGCTXT:
|
||||||
|
# Expect more msgctxt or msgid.
|
||||||
|
# If msgstr or string it is flagged as error.
|
||||||
|
if next_state == CMNT:
|
||||||
|
# Hmmm. A comment here?
|
||||||
|
print('WARNING: Unexpted comment '
|
||||||
|
'at %(fname)s:%(lineno)d' % vars())
|
||||||
|
|
||||||
|
elif next_state == MSGCTXT:
|
||||||
|
raise CheckException( 'Unexpected %(next_state)s '
|
||||||
|
'at %(fname)s:%(lineno)d' % vars() )
|
||||||
|
|
||||||
|
elif next_state == MSGID:
|
||||||
|
state = MSGID
|
||||||
|
msg.add_msgid( line, lineno )
|
||||||
|
|
||||||
|
elif next_state == MSGIDP:
|
||||||
|
raise CheckException( 'Unexpected %(next_state)s '
|
||||||
|
'at %(fname)s:%(lineno)d' % vars() )
|
||||||
|
|
||||||
|
elif next_state == MSGSTR:
|
||||||
|
print('WARNING: Wild msgstr at %(fname)s:%(lineno)d' % vars())
|
||||||
|
state = MSGSTR
|
||||||
|
# Start with an empty new item
|
||||||
|
msg = create_new_Msgid( msgs, lineno )
|
||||||
|
msg.add_new_msgstr( line, lineno )
|
||||||
|
|
||||||
|
elif next_state == STR:
|
||||||
|
print('WARNING: Wild string at %(fname)s:%(lineno)d' % vars())
|
||||||
|
|
||||||
|
elif next_state == STR:
|
||||||
|
# Continuation of msgctxt, stay in state MSGCTXT
|
||||||
|
msg.add_msgctxt( line, lineno )
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise CheckException( 'Unexpected state in po parsing '
|
||||||
|
'(state = %(state)s)' % vars() )
|
||||||
|
|
||||||
elif state == MSGID:
|
elif state == MSGID:
|
||||||
# Expect msgstr or msgid_plural or string
|
# Expect msgstr or msgid_plural or string
|
||||||
@ -475,6 +540,10 @@ def read_msgs( fname ):
|
|||||||
print('WARNING: Unexpted comment '
|
print('WARNING: Unexpted comment '
|
||||||
'at %(fname)s:%(lineno)d' % vars())
|
'at %(fname)s:%(lineno)d' % vars())
|
||||||
|
|
||||||
|
elif next_state == MSGCTXT:
|
||||||
|
raise CheckException( 'Unexpected %(next_state)s '
|
||||||
|
'at %(fname)s:%(lineno)d' % vars() )
|
||||||
|
|
||||||
elif next_state == MSGID:
|
elif next_state == MSGID:
|
||||||
raise CheckException( 'Unexpected %(next_state)s '
|
raise CheckException( 'Unexpected %(next_state)s '
|
||||||
'at %(fname)s:%(lineno)d' % vars() )
|
'at %(fname)s:%(lineno)d' % vars() )
|
||||||
@ -506,6 +575,10 @@ def read_msgs( fname ):
|
|||||||
print('WARNING: Unexpected comment '
|
print('WARNING: Unexpected comment '
|
||||||
'at %(fname)s:%(lineno)d' % vars())
|
'at %(fname)s:%(lineno)d' % vars())
|
||||||
|
|
||||||
|
elif next_state == MSGCTXT:
|
||||||
|
raise CheckException( 'Unexpected %(next_state)s '
|
||||||
|
'at %(fname)s:%(lineno)d' % vars() )
|
||||||
|
|
||||||
elif next_state == MSGID:
|
elif next_state == MSGID:
|
||||||
raise CheckException( 'Unexpected %(next_state)s '
|
raise CheckException( 'Unexpected %(next_state)s '
|
||||||
'at %(fname)s:%(lineno)d' % vars() )
|
'at %(fname)s:%(lineno)d' % vars() )
|
||||||
@ -538,6 +611,11 @@ def read_msgs( fname ):
|
|||||||
msg = create_new_Msgid( msgs, lineno )
|
msg = create_new_Msgid( msgs, lineno )
|
||||||
msg.add_cmnt( line )
|
msg.add_cmnt( line )
|
||||||
|
|
||||||
|
elif next_state == MSGCTXT:
|
||||||
|
state = MSGCTXT
|
||||||
|
msg = create_new_Msgid( msgs, lineno )
|
||||||
|
msg.add_msgctxt( line, lineno )
|
||||||
|
|
||||||
elif next_state == MSGID:
|
elif next_state == MSGID:
|
||||||
state = MSGID
|
state = MSGID
|
||||||
msg = create_new_Msgid( msgs, lineno )
|
msg = create_new_Msgid( msgs, lineno )
|
||||||
|
Loading…
Reference in New Issue
Block a user