Re: [poedit-users] word count in PO files
"Werner F. Bruhin" <[email protected]>
| Newsgroups | gmane.editors.poedit.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Tibor,
Based on what you sent I did something in Python, could probably be done
better if I know how to use the "re" module, but anyhow it is close enough.
I copied the poedit list in case others are interested in this too or
maybe someone could create this a patch for poEdit to have something
like this as tool/menu option.
Best regards
Werner
Python version:
pofile = file(r'some.po', 'r')
wordcount = 0
charcount = 0
netcharcount = 0
nottocount = '0123456789-=.,;:'
for line in pofile:
if line[0:6] == 'msgid ':
text = line[7:]
for x in nottocount:
text = text.replace(x, '')
wordcount += len(text.split())
charcount += len(text)
netcharcount += len(text.replace(' ', ''))
print 'Total number of words to translate: %s' % wordcount
print 'Total number of characters to translat (spaces included): %s' %
charcount
print 'Total number of characters to translat (spaces excluded): %s' %
netcharcount
Antalóczy Tibor wrote:
> Hi,
> To be honest I don't know how to post to that list... If you have it
> set it up, please feel free to post these lines.
>
> Best regards,
>
> Tibor
>
>
> Werner F. Bruhin írta:
>> Hi,
>>
>> Antalóczy Tibor wrote:
>>> Hi,
>>> While I was waiting for your answer I put together a small php
>>> function to do this for me:
>>>
>>> function countwords()
>>> {
>>> $wc = 0;
>>> $ccs = 0;
>>> $cc = 0;
>>> $po = file('en.po');
>>>
>>> foreach($po as $line) {
>>> if(preg_match("((msgid) \"(.*)\")", $line, $match)) {
>>> $wc += str_word_count($match[2]); $ccs
>>> += strlen($match[2]);
>>> $cc += strlen(str_replace(' ', '', $match[2]));
>>> }
>>> }
>>> echo 'Total number of words to translate: '.$wc.'<br />';
>>> echo 'Total number of characters to translat (spaces
>>> included): '.$ccs.'<br />';
>>> echo 'Total number of characters to translat (spaces
>>> excluded): '.$cc.'<br />';
>>> }
>>>
>>> Probably not the nicest solution, but if you are using PHP it works.
>> Interesting, also I don't use PHP much, just about only
>> Python/wxPython, but I guess I could adapt the above.
>>
>> Maybe you want to post it to the list, you never know there might be
>> someone out there who would adapt it to c++ and propose it as a patch
>> for poedit.
>>
>> Best regards
>> Werner
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/