Project: NOCC
Code Location: https://nocc.svn.sourceforge.net/svnroot/nocc/trunk/trunk
Browse
/
Download File
get_translations_status.py
#!/usr/bin/python
# -*- coding: utf-8 -*-;

# Python script to get the status of the translations
#
# Copyright 2009 Tim Gerundt <tim@gerundt.de>
#
# This file is part of NOCC. NOCC is free software under the terms of the
# GNU General Public License. You should have received a copy of the license
# along with NOCC.  If not, see <http://www.gnu.org/licenses/>.
#
# $Id: get_translations_status.py 2031 2009-10-24 14:20:15Z gerundt $

from os import listdir
from os.path import abspath, basename, isfile, join, splitext
import string
import re

class LangStatus(object):
    def __init__(self, file, language, translations):
        self.file = file
        self.language = language
        self.translations = translations

def getLangFiles(path):
    ''' Get all language files from a folder '''
    phpfiles = []
    for itemname in listdir(path): #For all dir items...
        fullitempath = abspath(join(path, itemname))
        if isfile(fullitempath): #If a file...
            filename = splitext(itemname)
            if str.lower(filename[1]) == '.php': #If a PHP file...
                phpfiles.append(fullitempath)
    return phpfiles

def getStatusFromLangFile(lang_file):
    ''' Get the translation status from a language file '''
    languagefilename = basename(lang_file)
    languagename = ''
    translationscount = 0
    
    rLanguage = re.compile('/\*\* ([a-zA-Z ]+)', re.IGNORECASE)
    rTranslation = re.compile('(^\$\w+)\s*=\s*["\'](.*)["\']\s*;', re.IGNORECASE)
    
    lines = open(lang_file, 'r')
    for line in lines: #For all lines...
        tmp = rLanguage.findall(line)
        if tmp: #If found the language name...
            languagename = tmp[0]
        tmp = rTranslation.findall(line)
        if tmp: #If found a translation...
            translationscount += 1
    if languagename == '':
        languagename = splitext(languagefilename)[0]
    return LangStatus(languagefilename, languagename.strip(), translationscount)

#Main routine...
lang_files = getLangFiles('webmail/lang')
print 'File,Language,Total,Translated,Untranslated'
total = getStatusFromLangFile('webmail/lang/en.php').translations
for lang_file in lang_files: #For all language files...
    lang_status = getStatusFromLangFile(lang_file)
    if lang_status.file != 'en.php': #If NOT English language file...
        if lang_status.file != 'qqq.php': #If NOT message documentation file...
            untranslated = total - lang_status.translations
            print "%s,%s,%u,%u,%u" % (lang_status.file, lang_status.language, total, lang_status.translations, untranslated)
    else: #If English language file...
        print "%s,%s,%u,%u,%u" % ('en.php', 'English', total, total, 0)