Package org.opencms.ai
Class CmsDeeplTranslation
java.lang.Object
org.opencms.ai.CmsDeeplTranslation
- All Implemented Interfaces:
I_CmsContentTranslator,I_CmsConfigurationParameterHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final ObjectConfiguration parameter for determining a target locale mapping.static final StringKey used for looking up the API key in the secret store.Fields inherited from interface org.opencms.configuration.I_CmsConfigurationParameterHandler
ADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHOD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConfigurationParameter(String paramName, String paramValue) Adds a configuration parameter to this parameter configurable class instance.Returns the parameters of this configurable class instance, ornullif the class does not need any parameters.Returns a fresh content augmentation object for doing the actual translation work.static com.deepl.api.LanguagegetMatchingLanguage(Locale locale, List<com.deepl.api.Language> languages) Tries to find a suitable Language object from a list of DeepL-supported languages that matches a given locale.Gets (and lazily creates if necessary) the target locale mapping.voidInitializes a configuration after all parameters have been added.voidinitialize(CmsObject cms) Initializes the content translator with an admin CmsObject.booleanisEnabled(CmsObject cms, CmsADEConfigData config, CmsFile file) Checks if the translation should be enabled for the current context.
-
Field Details
-
SECRET_API_KEY
Key used for looking up the API key in the secret store.- See Also:
-
PARAM_TARGET_LOCALE_MAPPING
Configuration parameter for determining a target locale mapping.
-
-
Constructor Details
-
CmsDeeplTranslation
public CmsDeeplTranslation()
-
-
Method Details
-
getMatchingLanguage
public static com.deepl.api.Language getMatchingLanguage(Locale locale, List<com.deepl.api.Language> languages) Tries to find a suitable Language object from a list of DeepL-supported languages that matches a given locale.- Parameters:
locale- the localelanguages- the languages- Returns:
- the matching language
-
addConfigurationParameter
Description copied from interface:I_CmsConfigurationParameterHandlerAdds a configuration parameter to this parameter configurable class instance.- Specified by:
addConfigurationParameterin interfaceI_CmsConfigurationParameterHandler- Parameters:
paramName- the name of the parameterparamValue- the value for the parameter- See Also:
-
getConfiguration
Description copied from interface:I_CmsConfigurationParameterHandlerReturns the parameters of this configurable class instance, ornullif the class does not need any parameters.- Specified by:
getConfigurationin interfaceI_CmsConfigurationParameterHandler- Returns:
- the parameters of this configurable class instance,
or
nullif the class does not need any parameters - See Also:
-
getContentAugmentation
Description copied from interface:I_CmsContentTranslatorReturns a fresh content augmentation object for doing the actual translation work.- Specified by:
getContentAugmentationin interfaceI_CmsContentTranslator- Returns:
- the content augmentation object
- See Also:
-
initConfiguration
Description copied from interface:I_CmsConfigurationParameterHandlerInitializes a configuration after all parameters have been added.- Specified by:
initConfigurationin interfaceI_CmsConfigurationParameterHandler- Throws:
CmsConfigurationException- if something goes wrong- See Also:
-
initialize
Description copied from interface:I_CmsContentTranslatorInitializes the content translator with an admin CmsObject.If the translator is already initialized, this should do nothing.
- Specified by:
initializein interfaceI_CmsContentTranslator- Parameters:
cms- an admin CmsObject
-
isEnabled
Description copied from interface:I_CmsContentTranslatorChecks if the translation should be enabled for the current context.- Specified by:
isEnabledin interfaceI_CmsContentTranslator- Parameters:
cms- the CMS contextconfig- the currently active ADE configurationfile- the edited file- Returns:
- true if the translation should be enabled
- See Also:
-
getTargetLocaleMapping
Gets (and lazily creates if necessary) the target locale mapping.DeepL API only lists en-US / en-GB for English, and pt-BR / pt-PT for Portuguese as target languages. Using just en or pt might work, but it's probably a good idea to be specific, So if just en or pt is specified, we map it to the variant that's more widely used by default.
This can be overriden by the configuration parameter targetLocaleMapping, which has the form l1:r1|l2:r2|..., where the li is the locale to map, and the ri is the locale to map to.
- Returns:
-