'Update the translation percentages for all modules for a given
language.
@ToDo: Generate fresh .py files with all relevant strings for this
(since we don\'t store untranslated strings)'

@classmethod
def update_string_counts(cls, lang_code):

    try:
        import cPickle as pickle
    except:
        import pickle
    base_dir = current.request.folder
    langfile = ('%s.py' % lang_code)
    langfile = os.path.join(base_dir, 'languages', langfile)
    lang_strings = read_dict(langfile)
    data_file = os.path.join(base_dir, 'uploads', 'temp.pkl')
    f = open(data_file, 'rb')
    all_strings = pickle.load(f)
    string_dict = pickle.load(f)
    f.close()
    db = current.db
    ptable = current.s3db.translate_percentage
    translated = set()
    addindex = translated.add
    for (index, string) in enumerate(all_strings):
        translation = lang_strings.get(string)
        if ((translation is None) or (translation[:4] == '***    ')):
            continue
        elif ((translation != string) or (lang_code == 'en-gb')):
            addindex(index)
    for (module, indices) in string_dict.items():
        all_indices = set(indices)
        num_untranslated = len((all_indices - translated))
        num_translated = (len(all_indices) - num_untranslated)
        data = dict(code=lang_code, module=module, translated=num_translated, untranslated=num_untranslated, dirty=False)
        query = ((ptable.code == lang_code) & (ptable.module == module))
        record = db(query).select(ptable._id, limitby=(0, 1)).first()
        if record:
            record.update_record(**data)
        else:
            ptable.insert(**data)
    return
