Class TranslationHandlerImpl
- All Implemented Interfaces:
TranslationContext
,TranslationHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
(package private) final FormatterOptions
private HtmlIdGenerator
(package private) final HtmlIdGeneratorFactory
private MergeContext
private Function
<String, CharSequence> private int
private TranslationPlaceholderGenerator
private int
(package private) final Pattern
private RenderPurpose
private int
(package private) final MutableDataSet
private MarkdownWriter
-
Constructor Summary
ConstructorsConstructorDescriptionTranslationHandlerImpl
(DataHolder options, HtmlIdGeneratorFactory idGeneratorFactory) -
Method Summary
Modifier and TypeMethodDescriptionstatic String
addPrefixSuffix
(CharSequence placeholderId, CharSequence prefix, CharSequence suffix, CharSequence suffix2) void
beginRendering
(@NotNull Document node, @NotNull NodeFormatterContext context, @NotNull MarkdownWriter appendable) void
customPlaceholderFormat
(@NotNull TranslationPlaceholderGenerator generator, @NotNull TranslatingSpanRender render) Temporarily change the format for placeholdersgetPlaceholderId
(String format, int placeholderId, CharSequence prefix, CharSequence suffix, CharSequence suffix2) @NotNull RenderPurpose
Get the reason this format rendering is being performed@NotNull MutableDataSet
Get MutableDataHolder for storing this translation run values across render purpose phases(package private) static boolean
isNotBlank
(CharSequence csq) boolean
boolean
Returns false if special translation functions are no-opsvoid
nonTranslatingSpan
(@NotNull TranslatingSpanRender render) Separate non-translation span.void
postProcessNonTranslating
(@NotNull Function<String, CharSequence> postProcessor, @NotNull Runnable scope) <T> T
postProcessNonTranslating
(@NotNull Function<String, CharSequence> postProcessor, @NotNull Supplier<T> scope) private String
renderInSubContext
(TranslatingSpanRender render, boolean copyToMain) void
setMergeContext
(@NotNull MergeContext context) void
setRenderPurpose
(@NotNull RenderPurpose renderPurpose) void
setTranslatedTexts
(@NotNull List<? extends CharSequence> translatedTexts) @NotNull CharSequence
transformAnchorRef
(@NotNull CharSequence pageRef, @NotNull 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 to@NotNull CharSequence
transformNonTranslating
(CharSequence prefix, @NotNull CharSequence nonTranslatingText, CharSequence suffix, CharSequence suffix2) Transform non-translating text@NotNull CharSequence
transformTranslating
(CharSequence prefix, @NotNull CharSequence translatingText, CharSequence suffix, CharSequence suffix2) Transform translating text but which is contextually isolated from the text block in which it is located ie.void
translatingRefTargetSpan
(@Nullable Node target, @NotNull TranslatingSpanRender render) Separate translation span which is also a ref targetvoid
translatingSpan
(@NotNull TranslatingSpanRender render) Separate translation span.
-
Field Details
-
myFormatterOptions
-
myNonTranslatingTexts
-
myAnchorTexts
-
myTranslatingTexts
-
myTranslatedTexts
-
myTranslatingPlaceholders
-
myTranslatingSpans
-
myNonTranslatingSpans
-
myTranslatedSpans
-
myIdGeneratorFactory
-
myPlaceHolderMarkerPattern
-
myTranslationStore
-
myOriginalRefTargets
-
myTranslatedRefTargets
-
myOriginalAnchors
-
myTranslatedAnchors
-
myPlaceholderId
private int myPlaceholderId -
myAnchorId
private int myAnchorId -
myTranslatingSpanId
private int myTranslatingSpanId -
myNonTranslatingSpanId
private int myNonTranslatingSpanId -
myRenderPurpose
-
myWriter
-
myIdGenerator
-
myPlaceholderGenerator
-
myNonTranslatingPostProcessor
-
myMergeContext
-
-
Constructor Details
-
TranslationHandlerImpl
-
-
Method Details
-
getMergeContext
- Specified by:
getMergeContext
in interfaceTranslationContext
-
setMergeContext
- Specified by:
setMergeContext
in interfaceTranslationHandler
-
getTranslationStore
Description copied from interface:TranslationContext
Get MutableDataHolder for storing this translation run values across render purpose phases- Specified by:
getTranslationStore
in interfaceTranslationContext
-
getIdGenerator
- Specified by:
getIdGenerator
in interfaceTranslationContext
-
beginRendering
public void beginRendering(@NotNull @NotNull Document node, @NotNull @NotNull NodeFormatterContext context, @NotNull @NotNull MarkdownWriter appendable) - Specified by:
beginRendering
in interfaceTranslationHandler
-
isNotBlank
-
getTranslatingTexts
- Specified by:
getTranslatingTexts
in interfaceTranslationHandler
-
setTranslatedTexts
- Specified by:
setTranslatedTexts
in interfaceTranslationHandler
-
setRenderPurpose
- Specified by:
setRenderPurpose
in interfaceTranslationHandler
-
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 @NotNull CharSequence transformAnchorRef(@NotNull @NotNull CharSequence pageRef, @NotNull @NotNull 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 @NotNull TranslationPlaceholderGenerator generator, @NotNull @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
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
-
renderInSubContext
-
translatingRefTargetSpan
public void translatingRefTargetSpan(@Nullable @Nullable Node target, @NotNull @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,render
-
-
nonTranslatingSpan
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 String getPlaceholderId(String format, int placeholderId, CharSequence prefix, CharSequence suffix, CharSequence suffix2) -
addPrefixSuffix
public static String addPrefixSuffix(CharSequence placeholderId, CharSequence prefix, CharSequence suffix, CharSequence suffix2) -
postProcessNonTranslating
public void postProcessNonTranslating(@NotNull @NotNull Function<String, CharSequence> postProcessor, @NotNull @NotNull 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 @NotNull Function<String, CharSequence> postProcessor, @NotNull @NotNull 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 @NotNull CharSequence transformNonTranslating(CharSequence prefix, @NotNull @NotNull CharSequence nonTranslatingText, CharSequence suffix, 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 @NotNull CharSequence transformTranslating(CharSequence prefix, @NotNull @NotNull CharSequence translatingText, CharSequence suffix, 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
-