<commit_before>#
# Jasy - JavaScript Tooling Refined
# Copyright 2010 <NAME>
#

import logging, re, copy, json
from jasy.parser.Node import Node
from jasy.ext import polib

__all__ = ["TranslationError", "Translation"]


class TranslationError(Exception):
    pass


class Translation:
    def __init__(self, locale, files=None, table=None):
        self.__locale = locale

        logging.debug("Initialize translation: %s" % locale)
        self.__table = {}

        if table:
            self.__table.update(table)
        
        if files:
            logging.debug("Load %s translation files..." % len(files))
            for path in files:
                pofile = polib.pofile(path)
                print("Process: %s" % path)
                for entry in pofile:
                    if (entry.msgstr != "" or entry.msgstr_plural) and not entry.msgid in self.__table:
                        self.__table[entry.msgid] = entry.msgstr
                        
        logging.debug("Translation of %s entries ready" % len(self.__table))
        
        
        
    #
    # Public API
    #

    def generate(self):
        return "this.$$translation=%s;" % json.dumps(self.__generate({}), separators=(',',':'))

    def patch(self, node):
        self.__recurser(node)
        
    def load(self, pofile):<commit_msg>Another minor fix for plural support<commit_after>#
# Jasy - JavaScript Tooling Refined
# Copyright 2010 <NAME>
#

import logging, re, copy, json
from jasy.parser.Node import Node
from jasy.ext import polib

__all__ = ["TranslationError", "Translation"]


class TranslationError(Exception):
    pass


class Translation:
    def __init__(self, locale, files=None, table=None):
        self.__locale = locale

        logging.debug("Initialize translation: %s" % locale)
        self.__table = {}

        if table:
            self.__table.update(table)
        
        if files:
            logging.debug("Load %s translation files..." % len(files))
            for path in files:
                pofile = polib.pofile(path)
                print("Process: %s" % path)
                for entry in pofile:
                    if not entry.msgid in self.__table:
                        if entry.msgstr != "":
                            self.__table[entry.msgid] = entry.msgstr
                        elif entry.msgstr_plural:
                            self.__table[entry.msgid] = entry.msgstr_plural
                        
        logging.debug("Translation of %s entries ready" % len(self.__table))
        
        
        
    #
    # Public API
    #

    def generate(self):
        return "this.$$translation=%s;" % json.dumps(self.__generate({}), separators=(',',':'))

    def patch(self, node):
        self.__recurser(node)
        
    def load(self, pofile):
{'fraction_non_alphanumeric': 0.11119030648610122, 'fraction_numerical': 0.002851033499643621, 'mean_word_length': 1.8526422764227641, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7292518', 'n_tokens_mistral': 805, 'n_tokens_neox': 754, 'n_words': 198}