Esempio n. 1
0
    def _build(self, locale, messages, path, pathGlobal=None):
        '''
        Builds a catalog based on the provided locale paths, the path is used as the main source any messages that are not
        found in path locale but are part of messages will attempt to be extracted from the global path locale.

        @param locale: Locale
            The locale.
        @param messages: Iterable(Message)
            The messages to build the PO file on.
        @param path: string
            The path of the targeted PO file from the locale repository.
        @param pathGlobal: string|None
            The path of the global PO file from the locale repository.
        @return: file like object
            File like object that contains the PO file content
        '''
        assert isinstance(locale, Locale), 'Invalid locale %s' % locale
        assert isinstance(messages, Iterable), 'Invalid messages %s' % messages
        assert isinstance(path, str), 'Invalid path %s' % path
        assert pathGlobal is None or isinstance(pathGlobal, str), 'Invalid global path %s' % pathGlobal
        if isfile(path):
            with open(path) as fObj: catalog = read_po(fObj, locale)
        else:
            catalog = Catalog(locale, creation_date=datetime.now(), **self.catalog_config)
        if pathGlobal and isfile(pathGlobal):
            with open(pathGlobal) as fObj: catalogGlobal = read_po(fObj, locale)
        else:
            catalogGlobal = None

        self._processCatalog(catalog, messages, fallBack=catalogGlobal)
        catalog.revision_date = datetime.now()

        return catalog
Esempio n. 2
0
    def _build(self, locale, messages, path, pathGlobal=None):
        '''
        Builds a catalog based on the provided locale paths, the path is used as the main source any messages that are not
        found in path locale but are part of messages will attempt to be extracted from the global path locale.

        @param locale: Locale
            The locale.
        @param messages: Iterable(Message)
            The messages to build the PO file on.
        @param path: string
            The path of the targeted PO file from the locale repository.
        @param pathGlobal: string|None
            The path of the global PO file from the locale repository.
        @return: file like object
            File like object that contains the PO file content
        '''
        assert isinstance(locale, Locale), 'Invalid locale %s' % locale
        assert isinstance(messages, Iterable), 'Invalid messages %s' % messages
        assert isinstance(path, str), 'Invalid path %s' % path
        assert pathGlobal is None or isinstance(
            pathGlobal, str), 'Invalid global path %s' % pathGlobal
        if isfile(path):
            with open(path) as fObj:
                catalog = read_po(fObj, locale)
        else:
            catalog = Catalog(locale,
                              creation_date=datetime.now(),
                              **self.catalog_config)
        if pathGlobal and isfile(pathGlobal):
            with open(pathGlobal) as fObj:
                catalogGlobal = read_po(fObj, locale)
        else:
            catalogGlobal = None

        self._processCatalog(catalog, messages, fallBack=catalogGlobal)
        catalog.revision_date = datetime.now()

        return catalog