Class TranslationHandlerImpl
- java.lang.Object
-
- com.vladsch.flexmark.formatter.internal.TranslationHandlerImpl
-
- All Implemented Interfaces:
TranslationContext
,TranslationHandler
public class TranslationHandlerImpl extends java.lang.Object implements TranslationHandler
-
-
Constructor Summary
Constructors Constructor Description TranslationHandlerImpl(DataHolder options, HtmlIdGeneratorFactory idGeneratorFactory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
addPrefixSuffix(java.lang.CharSequence placeholderId, java.lang.CharSequence prefix, java.lang.CharSequence suffix, java.lang.CharSequence suffix2)
void
beginRendering(Document node, NodeFormatterContext context, MarkdownWriter appendable)
void
customPlaceholderFormat(TranslationPlaceholderGenerator generator, TranslatingSpanRender render)
Temporarily change the format for placeholdersHtmlIdGenerator
getIdGenerator()
MergeContext
getMergeContext()
java.lang.String
getPlaceholderId(java.lang.String format, int placeholderId, java.lang.CharSequence prefix, java.lang.CharSequence suffix, java.lang.CharSequence suffix2)
RenderPurpose
getRenderPurpose()
Get the reason this format rendering is being performedjava.util.List<java.lang.String>
getTranslatingTexts()
MutableDataSet
getTranslationStore()
Get MutableDataHolder for storing this translation run values across render purpose phasesboolean
isPostProcessingNonTranslating()
boolean
isTransformingText()
Returns false if special translation functions are no-opsvoid
nonTranslatingSpan(TranslatingSpanRender render)
Separate non-translation span.void
postProcessNonTranslating(java.util.function.Function<java.lang.String,java.lang.CharSequence> postProcessor, java.lang.Runnable scope)
<T> T
postProcessNonTranslating(java.util.function.Function<java.lang.String,java.lang.CharSequence> postProcessor, java.util.function.Supplier<T> scope)
void
setMergeContext(MergeContext context)
void
setRenderPurpose(RenderPurpose renderPurpose)
void
setTranslatedTexts(java.util.List<? extends java.lang.CharSequence> translatedTexts)
java.lang.CharSequence
transformAnchorRef(java.lang.CharSequence pageRef, java.lang.CharSequence anchorRef)
DuringRenderPurpose.TRANSLATION_SPANS
this converts anchorRef to ordinal placeholder id DuringRenderPurpose.TRANSLATED_SPANS
this returns the ordinal placeholder DuringRenderPurpose.TRANSLATED
this returns new anchorRef for the AnchorRefTarget original was referring tojava.lang.CharSequence
transformNonTranslating(java.lang.CharSequence prefix, java.lang.CharSequence nonTranslatingText, java.lang.CharSequence suffix, java.lang.CharSequence suffix2)
Transform non-translating textjava.lang.CharSequence
transformTranslating(java.lang.CharSequence prefix, java.lang.CharSequence translatingText, java.lang.CharSequence suffix, java.lang.CharSequence suffix2)
Transform translating text but which is contextually isolated from the text block in which it is located ie.void
translatingRefTargetSpan(Node target, TranslatingSpanRender render)
Separate translation span which is also a ref targetvoid
translatingSpan(TranslatingSpanRender render)
Separate translation span.
-
-
-
Constructor Detail
-
TranslationHandlerImpl
public TranslationHandlerImpl(DataHolder options, HtmlIdGeneratorFactory idGeneratorFactory)
-
-
Method Detail
-
getMergeContext
public MergeContext getMergeContext()
- Specified by:
getMergeContext
in interfaceTranslationContext
-
setMergeContext
public void setMergeContext(@NotNull MergeContext context)
- Specified by:
setMergeContext
in interfaceTranslationHandler
-
getTranslationStore
@NotNull public MutableDataSet getTranslationStore()
Description copied from interface:TranslationContext
Get MutableDataHolder for storing this translation run values across render purpose phases- Specified by:
getTranslationStore
in interfaceTranslationContext
-
getIdGenerator
public HtmlIdGenerator getIdGenerator()
- Specified by:
getIdGenerator
in interfaceTranslationContext
-
beginRendering
public void beginRendering(@NotNull Document node, @NotNull NodeFormatterContext context, @NotNull MarkdownWriter appendable)
- Specified by:
beginRendering
in interfaceTranslationHandler
-
getTranslatingTexts
@NotNull public java.util.List<java.lang.String> getTranslatingTexts()
- Specified by:
getTranslatingTexts
in interfaceTranslationHandler
-
setTranslatedTexts
public void setTranslatedTexts(@NotNull java.util.List<? extends java.lang.CharSequence> translatedTexts)
- Specified by:
setTranslatedTexts
in interfaceTranslationHandler
-
setRenderPurpose
public void setRenderPurpose(@NotNull RenderPurpose renderPurpose)
- Specified by:
setRenderPurpose
in interfaceTranslationHandler
-
getRenderPurpose
@NotNull public RenderPurpose getRenderPurpose()
Description copied from interface:TranslationContext
Get the reason this format rendering is being performed- Specified by:
getRenderPurpose
in interfaceTranslationContext
- Returns:
- RenderPurpose for current rendering
-
isTransformingText
public boolean isTransformingText()
Description copied from interface:TranslationContext
Returns false if special translation functions are no-opsDuring
RenderPurpose.TRANSLATION_SPANS
this is true DuringRenderPurpose.TRANSLATED_SPANS
this is true DuringRenderPurpose.TRANSLATED
this is true- Specified by:
isTransformingText
in interfaceTranslationContext
- Returns:
- true if need to call translation related functions
-
transformAnchorRef
@NotNull public java.lang.CharSequence transformAnchorRef(@NotNull java.lang.CharSequence pageRef, @NotNull java.lang.CharSequence anchorRef)
Description copied from interface:TranslationContext
DuringRenderPurpose.TRANSLATION_SPANS
this converts anchorRef to ordinal placeholder id DuringRenderPurpose.TRANSLATED_SPANS
this returns the ordinal placeholder DuringRenderPurpose.TRANSLATED
this returns new anchorRef for the AnchorRefTarget original was referring to- Specified by:
transformAnchorRef
in interfaceTranslationContext
- Parameters:
pageRef
- url part without the anchor ref to resolve referenceanchorRef
- anchor ref- Returns:
- anchorRef for the phase to be used for rendering
-
customPlaceholderFormat
public void customPlaceholderFormat(@NotNull TranslationPlaceholderGenerator generator, @NotNull TranslatingSpanRender render)
Description copied from interface:TranslationContext
Temporarily change the format for placeholders- Specified by:
customPlaceholderFormat
in interfaceTranslationContext
- Parameters:
generator
- placeholder generatorrender
- render which will be used with the custom generator
-
translatingSpan
public void translatingSpan(@NotNull TranslatingSpanRender render)
Description copied from interface:TranslationContext
Separate translation span. Will generate a paragraph of text which should be translated as one pieceDuring
RenderPurpose.TRANSLATION_SPANS
this adds the generated output to translation spans DuringRenderPurpose.TRANSLATED_SPANS
output from renderer is suppressed, instead outputs corresponding translated span DuringRenderPurpose.TRANSLATED
calls render- Specified by:
translatingSpan
in interfaceTranslationContext
-
translatingRefTargetSpan
public void translatingRefTargetSpan(@Nullable Node target, @NotNull TranslatingSpanRender render)
Description copied from interface:TranslationContext
Separate translation span which is also a ref target- Specified by:
translatingRefTargetSpan
in interfaceTranslationContext
- Parameters:
target
- target node,
-
nonTranslatingSpan
public void nonTranslatingSpan(@NotNull TranslatingSpanRender render)
Description copied from interface:TranslationContext
Separate non-translation span. Will generate a paragraph of text which will not be translatedDuring
RenderPurpose.TRANSLATION_SPANS
this adds the generated output to translation spans DuringRenderPurpose.TRANSLATED_SPANS
output from renderer is suppressed, instead outputs corresponding translated span DuringRenderPurpose.TRANSLATED
calls render- Specified by:
nonTranslatingSpan
in interfaceTranslationContext
-
getPlaceholderId
public java.lang.String getPlaceholderId(java.lang.String format, int placeholderId, java.lang.CharSequence prefix, java.lang.CharSequence suffix, java.lang.CharSequence suffix2)
-
addPrefixSuffix
public static java.lang.String addPrefixSuffix(java.lang.CharSequence placeholderId, java.lang.CharSequence prefix, java.lang.CharSequence suffix, java.lang.CharSequence suffix2)
-
postProcessNonTranslating
public void postProcessNonTranslating(@NotNull java.util.function.Function<java.lang.String,java.lang.CharSequence> postProcessor, @NotNull java.lang.Runnable scope)
- Specified by:
postProcessNonTranslating
in interfaceTranslationContext
- Parameters:
postProcessor
- id post processor for TRANSLATED purposescope
- code to which the post processor applies
-
postProcessNonTranslating
@NotNull public <T> T postProcessNonTranslating(@NotNull java.util.function.Function<java.lang.String,java.lang.CharSequence> postProcessor, @NotNull java.util.function.Supplier<T> scope)
- Specified by:
postProcessNonTranslating
in interfaceTranslationContext
- Parameters:
postProcessor
- id post processor for TRANSLATED purposescope
- code to which the post processor applies
-
isPostProcessingNonTranslating
public boolean isPostProcessingNonTranslating()
- Specified by:
isPostProcessingNonTranslating
in interfaceTranslationContext
- Returns:
- true if non-translating post processor is set
-
transformNonTranslating
@NotNull public java.lang.CharSequence transformNonTranslating(java.lang.CharSequence prefix, @NotNull java.lang.CharSequence nonTranslatingText, java.lang.CharSequence suffix, java.lang.CharSequence suffix2)
Description copied from interface:TranslationContext
Transform non-translating textDuring
RenderPurpose.TRANSLATION_SPANS
this converts text to non-translating placeholder based on ordinal id DuringRenderPurpose.TRANSLATED_SPANS
this returns the non-translating placeholder based on ordinal id DuringRenderPurpose.TRANSLATED
this returns the original non-translating text for the nonTranslatingText (placeholder)- Specified by:
transformNonTranslating
in interfaceTranslationContext
- Parameters:
prefix
- prefix to use on non-translating placeholder so it is interpreted as a proper element during parsingnonTranslatingText
- non-rendering text of the node (content will depend on translation phase)suffix
- suffix to use on non-translating placeholder so it is interpreted as a proper element during parsingsuffix2
- suffix to use on non-translating placeholder so it is interpreted as a proper element during parsing- Returns:
- text to be used in rendering for this phase
-
transformTranslating
@NotNull public java.lang.CharSequence transformTranslating(java.lang.CharSequence prefix, @NotNull java.lang.CharSequence translatingText, java.lang.CharSequence suffix, java.lang.CharSequence suffix2)
Description copied from interface:TranslationContext
Transform translating text but which is contextually isolated from the text block in which it is located ie. link reference or image referenceDuring
RenderPurpose.TRANSLATION_SPANS
this converts text to non-translating placeholder based on ordinal id and adds it to translation snippets DuringRenderPurpose.TRANSLATED_SPANS
this returns the non-translating placeholder based on ordinal id DuringRenderPurpose.TRANSLATED
this returns the translated text for the translatingText (placeholder)- Specified by:
transformTranslating
in interfaceTranslationContext
- Parameters:
prefix
- prefix to use on non-translating placeholder so it is interpreted as a proper element during parsingtranslatingText
- translating but isolated text of the node (content will depend on translation phase)suffix
- suffix to use on non-translating placeholder so it is interpreted as a proper element during parsingsuffix2
- suffix to use on non-translating placeholder so it is interpreted as a proper element during parsing- Returns:
- text to be used in rendering for this phase
-
-