Class AutoPageTranslateServiceImpl

  • All Implemented Interfaces:
    AutoPageTranslateService

    public class AutoPageTranslateServiceImpl
    extends Object
    implements AutoPageTranslateService

    Translated would normally be properties that "obviously" contain text, like jcr:title, jcr:description, text, title etc. (Let's search the wcm core components documentation for that), and properties that heuristically "look like text", that is, contain multiple whitespace sequences. Since that's bound to fail sometimes, we later need a rule configuration mechanism in the OSGI configuration that defines positive / negative exceptions, but that's not in scope for now.

    We save property values : the property value before the translation is saved with prefix `ai_` and suffix `_original` for the property name, and the property value after the translation is saved with prefix `ai_` and suffix `_translated` for the property name.

    • Field Detail

      • LOG

        protected static final org.slf4j.Logger LOG
      • PATTERN_IGNORED_SUBNODE_NAMES

        protected static final Pattern PATTERN_IGNORED_SUBNODE_NAMES
      • translationService

        protected com.composum.ai.backend.base.service.chat.GPTTranslationService translationService
      • configurationService

        protected com.composum.ai.backend.slingbase.AIConfigurationService configurationService
      • liveRelationshipManager

        protected com.day.cq.wcm.msm.api.LiveRelationshipManager liveRelationshipManager
    • Constructor Detail

      • AutoPageTranslateServiceImpl

        public AutoPageTranslateServiceImpl()
    • Method Detail

      • markAsAiTranslated

        protected void markAsAiTranslated​(org.apache.sling.api.resource.Resource resource,
                                          com.day.cq.wcm.msm.api.LiveRelationship liveRelationship,
                                          AutoTranslateService.TranslationParameters parameters,
                                          com.composum.ai.backend.base.service.chat.GPTConfiguration configuration)
                                   throws com.day.cq.wcm.api.WCMException
        Throws:
        com.day.cq.wcm.api.WCMException
      • migratePathsToLanguageCopy

        protected boolean migratePathsToLanguageCopy​(org.apache.sling.api.resource.Resource resource,
                                                     String language,
                                                     AutoPageTranslateService.Stats stats)
                                              throws com.day.cq.wcm.api.WCMException
        Traverses the resource tree looking for paths pointing to /content/dam/ and /content/experience-fragments/ and changes them if there is an unique language copy in our language.
        Returns:
        true if something was changed.
        Throws:
        com.day.cq.wcm.api.WCMException
      • cancelInheritance

        protected void cancelInheritance​(org.apache.sling.api.resource.Resource resource,
                                         org.apache.sling.api.resource.Resource resourceToTranslate,
                                         AutoPageTranslateServiceImpl.PropertyToTranslate propertyToTranslate)
                                  throws com.day.cq.wcm.api.WCMException
        Throws:
        com.day.cq.wcm.api.WCMException
      • reenableInheritance

        protected void reenableInheritance​(org.apache.sling.api.resource.Resource resource,
                                           String key,
                                           com.day.cq.wcm.msm.api.LiveRelationship relationship)
                                    throws com.day.cq.wcm.api.WCMException
        Throws:
        com.day.cq.wcm.api.WCMException
      • rollback

        public void rollback​(org.apache.sling.api.resource.Resource resource)
                      throws com.day.cq.wcm.api.WCMException,
                             org.apache.sling.api.resource.PersistenceException
        Description copied from interface: AutoPageTranslateService
        Rolls everything back in the resource - mostly for testing purposes.
        Specified by:
        rollback in interface AutoPageTranslateService
        Throws:
        com.day.cq.wcm.api.WCMException
        org.apache.sling.api.resource.PersistenceException
      • isCancelled

        protected static boolean isCancelled​(org.apache.sling.api.resource.Resource resource,
                                             String key,
                                             com.day.cq.wcm.msm.api.LiveRelationship relationship)
      • compileContentPattern

        @Nonnull
        protected static Pattern compileContentPattern​(String contentMatch)
        The content match can be a word or phrase that must be present in the content of the page for the rule to match. For example, 'Product' will match all pages that contain the word 'Product', case-insensitive. Spaces will also match any whitespace. If it contains any of the regex meta characters []()*+ it'll be treated as a regex.
      • encodePropertyName

        protected static String encodePropertyName​(String prefix,
                                                   String propertyName,
                                                   String suffix)
        Searches for properties