Class AITranslatePropertyWrapper
- java.lang.Object
-
- com.composum.ai.aem.core.impl.autotranslate.AITranslatePropertyWrapper
-
public class AITranslatePropertyWrapper extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringAI_ACCEPTED_SOURCE_SUFFIXSuffix for the property name of a property with enabled inheritance that saves the source language for the value the user has last accepted in the AI merge tool.static StringAI_ACCEPTED_TRANSLATION_SUFFIXSuffix for the property name of a property with enabled inheritance that saves the (auto translated) property value when the user last accepted it in the AI merge tool.static StringAI_NEW_ORIGINAL_SUFFIXSuffix for the property name of an inheritance cancelled property that saves the original value of the property as it is currently in the translation source during rollout, heping with the merge.static StringAI_NEW_TRANSLATED_SUFFIXSuffix for the property name of an inheritance cancelled property that saves the auto-translated value of the property during rollout - needs to be merged with the current value.static StringAI_ORIGINAL_SUFFIXSuffix for the property name of a property that saves the original value of the property as it has been used to create a translation, to track when it has to be re-translated.static StringAI_PREFIXPrefix for property names of saved values.static StringAI_TRANSLATED_SUFFIXSuffix for the property name of a property that saves the translated value of the property, to track whether it has been manually changed after automatic translation and as used as translation when the translation source is still the same as saved inAI_ORIGINAL_SUFFIX.static StringAI_TRANSLATION_ERRORMARKERAttribute that is set on jcr:content of a page when the translation of a page failed, to make it easy to find such pages.static StringAI_TRANSLATION_MODELAttribute that is set on jcr:content of a page on successful translation: saves the model it was translated with.static StringLC_PREFIXPrefix for property names changed to language copies.static StringPROPERTY_AI_ADDINSTRUCTIONSPageContent only property: saves the additional instructions the page was translated with.static StringPROPERTY_AI_TRANSLATED_BYSaves user who triggered the automatic translation of the resource.static StringPROPERTY_AI_TRANSLATED_DATESaves the date when a resource was automatically translated.
-
Constructor Summary
Constructors Constructor Description AITranslatePropertyWrapper(org.apache.sling.api.resource.ValueMap sourceValueMap, org.apache.sling.api.resource.ModifiableValueMap targetValueMap, String propertyName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadjustForReenableInheritance()If there is a new original and new translation saved, we have to overwrite the property with that if the inheritance is reenabled since that is newer than the original value - basically synchronization.String[]allAiKeys()All keys about the property.String[]allKeys()String[]allLcKeys()String[]allPageKeys()All general keys for storing properties on a page.static List<AITranslatePropertyWrapper>allProps(org.apache.sling.api.resource.ValueMap sourceValueMap, org.apache.sling.api.resource.ModifiableValueMap targetValueMap)static StringdecodePropertyName(String prefix, String encodedPropertyName, String suffix, org.apache.sling.api.resource.ValueMap valueMap)InvertsencodePropertyName(String, String, String)by replacing _ with : if the property isn't present.static StringencodePropertyName(String prefix, String propertyName, String suffix)Searches for propertiesStringgetAcceptedSource()StringgetAcceptedTranslation()StringgetCurrentValue()StringgetLcOriginal()StringgetLcTranslated()StringgetNewOriginalCopy()StringgetNewTranslatedCopy()StringgetOriginal()StringgetOriginalCopy()StringgetPropertyName()StringgetTranslatedCopy()booleanhasSavedTranslation()protected static booleanisAiTranslateProperty(String name)Checks whether a property was created by us and must not be translated etc.booleanisMergeNeeded()A merge is needed if the property is inheritance cancelled and this is true: there is a new original and a new translated copy.booleanisOriginalAsWhenLastTranslating()booleanisRichText()Tries to guess whether the property is richtext.voidsetAcceptedSource(String value)voidsetAcceptedTranslation(String value)voidsetAiTranslatedBy(String value)voidsetAiTranslatedDate(Calendar value)voidsetCurrentValue(String value)voidsetLcOriginal(String value)voidsetLcTranslated(String value)voidsetNewOriginalCopy(String value)voidsetNewTranslatedCopy(String value)voidsetOriginalCopy(String value)voidsetTranslatedCopy(String value)StringtoString()
-
-
-
Field Detail
-
PROPERTY_AI_ADDINSTRUCTIONS
public static final String PROPERTY_AI_ADDINSTRUCTIONS
PageContent only property: saves the additional instructions the page was translated with.- See Also:
- Constant Field Values
-
PROPERTY_AI_TRANSLATED_DATE
public static final String PROPERTY_AI_TRANSLATED_DATE
Saves the date when a resource was automatically translated. Find translated resources with /content//*[@ai_translated] .- See Also:
- Constant Field Values
-
PROPERTY_AI_TRANSLATED_BY
public static final String PROPERTY_AI_TRANSLATED_BY
Saves user who triggered the automatic translation of the resource.- See Also:
- Constant Field Values
-
AI_PREFIX
public static final String AI_PREFIX
Prefix for property names of saved values.- See Also:
- Constant Field Values
-
LC_PREFIX
public static final String LC_PREFIX
Prefix for property names changed to language copies. This is set if a property is a path and the path has a (translated) language copy in the desired target language.- See Also:
- Constant Field Values
-
AI_ORIGINAL_SUFFIX
public static final String AI_ORIGINAL_SUFFIX
Suffix for the property name of a property that saves the original value of the property as it has been used to create a translation, to track when it has to be re-translated.- See Also:
- Constant Field Values
-
AI_TRANSLATED_SUFFIX
public static final String AI_TRANSLATED_SUFFIX
Suffix for the property name of a property that saves the translated value of the property, to track whether it has been manually changed after automatic translation and as used as translation when the translation source is still the same as saved inAI_ORIGINAL_SUFFIX.- See Also:
- Constant Field Values
-
AI_NEW_ORIGINAL_SUFFIX
public static final String AI_NEW_ORIGINAL_SUFFIX
Suffix for the property name of an inheritance cancelled property that saves the original value of the property as it is currently in the translation source during rollout, heping with the merge.- See Also:
AI_NEW_TRANSLATED_SUFFIX, Constant Field Values
-
AI_NEW_TRANSLATED_SUFFIX
public static final String AI_NEW_TRANSLATED_SUFFIX
Suffix for the property name of an inheritance cancelled property that saves the auto-translated value of the property during rollout - needs to be merged with the current value.- See Also:
AI_NEW_ORIGINAL_SUFFIX, Constant Field Values
-
AI_ACCEPTED_SOURCE_SUFFIX
public static final String AI_ACCEPTED_SOURCE_SUFFIX
Suffix for the property name of a property with enabled inheritance that saves the source language for the value the user has last accepted in the AI merge tool.
-
AI_ACCEPTED_TRANSLATION_SUFFIX
public static final String AI_ACCEPTED_TRANSLATION_SUFFIX
Suffix for the property name of a property with enabled inheritance that saves the (auto translated) property value when the user last accepted it in the AI merge tool.- See Also:
AI_ACCEPTED_SOURCE_SUFFIX, Constant Field Values
-
AI_TRANSLATION_ERRORMARKER
public static final String AI_TRANSLATION_ERRORMARKER
Attribute that is set on jcr:content of a page when the translation of a page failed, to make it easy to find such pages. Not set byAITranslatePropertyWrapper, but since all property names are defined here... Is set to the time at which the error occurred, to make it easy to find in the logs.- See Also:
- Constant Field Values
-
AI_TRANSLATION_MODEL
public static final String AI_TRANSLATION_MODEL
Attribute that is set on jcr:content of a page on successful translation: saves the model it was translated with.- See Also:
- Constant Field Values
-
-
Method Detail
-
getCurrentValue
public String getCurrentValue()
-
setCurrentValue
public void setCurrentValue(String value)
-
getOriginalCopy
public String getOriginalCopy()
- See Also:
AI_ORIGINAL_SUFFIX
-
setOriginalCopy
public void setOriginalCopy(String value)
- See Also:
AI_ORIGINAL_SUFFIX
-
getTranslatedCopy
public String getTranslatedCopy()
- See Also:
AI_TRANSLATED_SUFFIX
-
setTranslatedCopy
public void setTranslatedCopy(String value)
- See Also:
AI_TRANSLATED_SUFFIX
-
getNewOriginalCopy
public String getNewOriginalCopy()
- See Also:
AI_NEW_ORIGINAL_SUFFIX
-
setNewOriginalCopy
public void setNewOriginalCopy(String value)
- See Also:
AI_NEW_ORIGINAL_SUFFIX
-
getNewTranslatedCopy
public String getNewTranslatedCopy()
- See Also:
AI_NEW_TRANSLATED_SUFFIX
-
setNewTranslatedCopy
public void setNewTranslatedCopy(String value)
- See Also:
AI_NEW_TRANSLATED_SUFFIX
-
getAcceptedSource
public String getAcceptedSource()
- See Also:
AI_ACCEPTED_SOURCE_SUFFIX
-
setAcceptedSource
public void setAcceptedSource(String value)
- See Also:
AI_ACCEPTED_SOURCE_SUFFIX
-
getAcceptedTranslation
public String getAcceptedTranslation()
- See Also:
AI_ACCEPTED_TRANSLATION_SUFFIX
-
setAcceptedTranslation
public void setAcceptedTranslation(String value)
- See Also:
AI_ACCEPTED_TRANSLATION_SUFFIX
-
getLcOriginal
public String getLcOriginal()
- See Also:
LC_PREFIX,AI_ORIGINAL_SUFFIX
-
setLcOriginal
public void setLcOriginal(String value)
- See Also:
LC_PREFIX,AI_ORIGINAL_SUFFIX
-
getLcTranslated
public String getLcTranslated()
- See Also:
LC_PREFIX,AI_TRANSLATED_SUFFIX
-
setLcTranslated
public void setLcTranslated(String value)
- See Also:
LC_PREFIX,AI_TRANSLATED_SUFFIX
-
setAiTranslatedBy
public void setAiTranslatedBy(String value)
- See Also:
PROPERTY_AI_TRANSLATED_BY
-
setAiTranslatedDate
public void setAiTranslatedDate(Calendar value)
- See Also:
PROPERTY_AI_TRANSLATED_DATE
-
getPropertyName
public String getPropertyName()
-
isRichText
public boolean isRichText()
Tries to guess whether the property is richtext. We have to be somewhat heuristic here since that's not easily determined. If the property name is "text" and the attribute "textIsRich" is present we use that, if it's "jcr:description" and there is no "text" attribute the same approach is used. Otherwise we check whether the first character is "<" and the last is ">", as this always seems to be the case for richtext properties. "textIsRich" is read out as Boolean, and if it's not present we use the heuristical check.
-
hasSavedTranslation
public boolean hasSavedTranslation()
-
isOriginalAsWhenLastTranslating
public boolean isOriginalAsWhenLastTranslating()
-
isMergeNeeded
public boolean isMergeNeeded()
A merge is needed if the property is inheritance cancelled and this is true: there is a new original and a new translated copy.
-
allLcKeys
public String[] allLcKeys()
-
allAiKeys
public String[] allAiKeys()
All keys about the property.
-
allPageKeys
public String[] allPageKeys()
All general keys for storing properties on a page.
-
allKeys
public String[] allKeys()
-
isAiTranslateProperty
protected static boolean isAiTranslateProperty(String name)
Checks whether a property was created by us and must not be translated etc.
-
encodePropertyName
public static String encodePropertyName(String prefix, String propertyName, String suffix)
Searches for properties
-
decodePropertyName
@Nullable public static String decodePropertyName(@Nonnull String prefix, @Nonnull String encodedPropertyName, @Nonnull String suffix, @Nonnull org.apache.sling.api.resource.ValueMap valueMap)
InvertsencodePropertyName(String, String, String)by replacing _ with : if the property isn't present. This assumes there was only one : in the original property name.- Returns:
- the property name or null if that doesn't seem like an encoded property name.
-
allProps
@Nonnull public static List<AITranslatePropertyWrapper> allProps(@Nonnull org.apache.sling.api.resource.ValueMap sourceValueMap, @Nonnull org.apache.sling.api.resource.ModifiableValueMap targetValueMap)
-
adjustForReenableInheritance
public void adjustForReenableInheritance()
If there is a new original and new translation saved, we have to overwrite the property with that if the inheritance is reenabled since that is newer than the original value - basically synchronization.
-
-