Example #1
0
def link_translations(items):
    """
        Links the translations with the declared items with the form:
        [(obj1, lang1), (obj2, lang2), ...] assuming that the first element
        is the 'canonical' (in PAM there is no such thing).
    """
    # Grab the first item object and get its canonical handler
    canonical = ITranslationManager(items[0][0])

    for obj, language in items:
        if not canonical.has_translation(language):
            canonical.register_translation(language, obj)
Example #2
0
def link_translations(items):
    """
        Links the translations with the declared items with the form:
        [(obj1, lang1), (obj2, lang2), ...] assuming that the first element
        is the 'canonical' (in PAM there is no such thing).
    """
    # Grab the first item object and get its canonical handler
    canonical = ITranslationManager(items[0][0])

    for obj, language in items:
        if not canonical.has_translation(language):
            canonical.register_translation(language, obj)
Example #3
0
 def __call__(self, language):
     """
     Look for the closest translated folder or siteroot
     """
     parent = aq_parent(self.context)
     translated_parent = parent
     found = False
     while not (IPloneSiteRoot.providedBy(parent) and not ILanguageRootFolder.providedBy(parent)) and not found:
         parent_translation = ITranslationManager(parent)
         if parent_translation.has_translation(language):
             translated_parent = \
                 parent_translation.get_translation(language)
             found = True
         parent = aq_parent(parent)
     return translated_parent
Example #4
0
 def __call__(self, language):
     """
     Look for the closest translated folder or siteroot
     """
     parent = aq_parent(self.context)
     translated_parent = parent
     found = False
     while not (IPloneSiteRoot.providedBy(parent) and
                not ILanguageRootFolder.providedBy(parent))\
             and not found:
         parent_translation = ITranslationManager(parent)
         if parent_translation.has_translation(language):
             translated_parent =\
                 parent_translation.get_translation(language)
             found = True
         parent = aq_parent(parent)
     return translated_parent
Example #5
0
    def copy_contents_of(self, item, target_languages):
        if item.portal_type in SKIPPED_PORTAL_TYPES:
            log.info("Item skipped: {0}".format("/".join(
                item.getPhysicalPath())))
        else:
            for language in target_languages:
                manager = ITranslationManager(item)
                if not manager.has_translation(language):
                    manager.add_translation(language)
                    log.info("Created translation for {}: {}".format(
                        "/".join(item.getPhysicalPath()), language))
                    import transaction

                    transaction.commit()
                translated = manager.get_translation(language)
                self.copy_fields(item, translated)
                self.copy_seo_properties(item, translated)
                self.copy_other_properties(item, translated)
                self.copy_other_things(item, translated)
                # translated.id = safe_unicode(translated.id).encode('utf-8')
                translated.reindexObject()
Example #6
0
    def linkTranslations(self):
        """Links the translations of the default language Folders
        """
        doneSomething = False

        try:
            canonical = ITranslationManager(self.folders[self.defaultLanguage])
        except TypeError as e:
            raise TypeError(str(e) + u' Are your folders ITranslatable?')

        for language in self.languages:
            if language == self.defaultLanguage:
                continue
            if not canonical.has_translation(language):
                language_folder = self.folders[language]
                canonical.register_translation(language, language_folder)
                doneSomething = True

        if doneSomething:
            logger.info(u'Translations linked.')

        return doneSomething
Example #7
0
    def linkTranslations(self):
        """Links the translations of the default language Folders
        """
        doneSomething = False

        try:
            canonical = ITranslationManager(self.folders[self.defaultLanguage])
        except TypeError as e:
            raise TypeError(str(e) + u' Are your folders ITranslatable?')

        for language in self.languages:
            if language == self.defaultLanguage:
                continue
            if not canonical.has_translation(language):
                language_folder = self.folders[language]
                canonical.register_translation(language, language_folder)
                doneSomething = True

        if doneSomething:
            logger.info(u'Translations linked.')

        return doneSomething
 def test_has_translation(self):
     translation_manager = ITranslationManager(self.a_ca)
     self.assertTrue(translation_manager.has_translation('ca'))
     self.assertFalse(translation_manager.has_translation('es'))
 def test_has_translation(self):
     translation_manager = ITranslationManager(self.a_ca)
     self.assertTrue(translation_manager.has_translation('ca'))
     self.assertFalse(translation_manager.has_translation('es'))