Class TranslationHandlerImpl
- All Implemented Interfaces:
TranslationContext, TranslationHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int(package private) final FormatterOptionsprivate HtmlIdGenerator(package private) final HtmlIdGeneratorFactoryprivate MergeContextprivate Function<String, CharSequence> private intprivate TranslationPlaceholderGeneratorprivate int(package private) final Patternprivate RenderPurposeprivate int(package private) final MutableDataSetprivate MarkdownWriter -
Constructor Summary
ConstructorsConstructorDescriptionTranslationHandlerImpl(DataHolder options, HtmlIdGeneratorFactory idGeneratorFactory) -
Method Summary
Modifier and TypeMethodDescriptionstatic StringaddPrefixSuffix(CharSequence placeholderId, CharSequence prefix, CharSequence suffix, CharSequence suffix2) voidbeginRendering(@NotNull Document node, @NotNull NodeFormatterContext context, @NotNull MarkdownWriter appendable) voidcustomPlaceholderFormat(@NotNull TranslationPlaceholderGenerator generator, @NotNull TranslatingSpanRender render) Temporarily change the format for placeholdersgetPlaceholderId(String format, int placeholderId, CharSequence prefix, CharSequence suffix, CharSequence suffix2) @NotNull RenderPurposeGet the reason this format rendering is being performed@NotNull MutableDataSetGet MutableDataHolder for storing this translation run values across render purpose phases(package private) static booleanisNotBlank(CharSequence csq) booleanbooleanReturns false if special translation functions are no-opsvoidnonTranslatingSpan(@NotNull TranslatingSpanRender render) Separate non-translation span.voidpostProcessNonTranslating(@NotNull Function<String, CharSequence> postProcessor, @NotNull Runnable scope) <T> TpostProcessNonTranslating(@NotNull Function<String, CharSequence> postProcessor, @NotNull Supplier<T> scope) private StringrenderInSubContext(TranslatingSpanRender render, boolean copyToMain) voidsetMergeContext(@NotNull MergeContext context) voidsetRenderPurpose(@NotNull RenderPurpose renderPurpose) voidsetTranslatedTexts(@NotNull List<? extends CharSequence> translatedTexts) @NotNull CharSequencetransformAnchorRef(@NotNull CharSequence pageRef, @NotNull CharSequence anchorRef) DuringRenderPurpose.TRANSLATION_SPANSthis converts anchorRef to ordinal placeholder id DuringRenderPurpose.TRANSLATED_SPANSthis returns the ordinal placeholder DuringRenderPurpose.TRANSLATEDthis returns new anchorRef for the AnchorRefTarget original was referring to@NotNull CharSequencetransformNonTranslating(CharSequence prefix, @NotNull CharSequence nonTranslatingText, CharSequence suffix, CharSequence suffix2) Transform non-translating text@NotNull CharSequencetransformTranslating(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.voidtranslatingRefTargetSpan(@Nullable Node target, @NotNull TranslatingSpanRender render) Separate translation span which is also a ref targetvoidtranslatingSpan(@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:
getMergeContextin interfaceTranslationContext
-
setMergeContext
- Specified by:
setMergeContextin interfaceTranslationHandler
-
getTranslationStore
Description copied from interface:TranslationContextGet MutableDataHolder for storing this translation run values across render purpose phases- Specified by:
getTranslationStorein interfaceTranslationContext
-
getIdGenerator
- Specified by:
getIdGeneratorin interfaceTranslationContext
-
beginRendering
public void beginRendering(@NotNull @NotNull Document node, @NotNull @NotNull NodeFormatterContext context, @NotNull @NotNull MarkdownWriter appendable) - Specified by:
beginRenderingin interfaceTranslationHandler
-
isNotBlank
-
getTranslatingTexts
- Specified by:
getTranslatingTextsin interfaceTranslationHandler
-
setTranslatedTexts
- Specified by:
setTranslatedTextsin interfaceTranslationHandler
-
setRenderPurpose
- Specified by:
setRenderPurposein interfaceTranslationHandler
-
getRenderPurpose
Description copied from interface:TranslationContextGet the reason this format rendering is being performed- Specified by:
getRenderPurposein interfaceTranslationContext- Returns:
- RenderPurpose for current rendering
-
isTransformingText
public boolean isTransformingText()Description copied from interface:TranslationContextReturns false if special translation functions are no-opsDuring
RenderPurpose.TRANSLATION_SPANSthis is true DuringRenderPurpose.TRANSLATED_SPANSthis is true DuringRenderPurpose.TRANSLATEDthis is true- Specified by:
isTransformingTextin 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:TranslationContextDuringRenderPurpose.TRANSLATION_SPANSthis converts anchorRef to ordinal placeholder id DuringRenderPurpose.TRANSLATED_SPANSthis returns the ordinal placeholder DuringRenderPurpose.TRANSLATEDthis returns new anchorRef for the AnchorRefTarget original was referring to- Specified by:
transformAnchorRefin 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:TranslationContextTemporarily change the format for placeholders- Specified by:
customPlaceholderFormatin interfaceTranslationContext- Parameters:
generator- placeholder generatorrender- render which will be used with the custom generator
-
translatingSpan
Description copied from interface:TranslationContextSeparate translation span. Will generate a paragraph of text which should be translated as one pieceDuring
RenderPurpose.TRANSLATION_SPANSthis adds the generated output to translation spans DuringRenderPurpose.TRANSLATED_SPANSoutput from renderer is suppressed, instead outputs corresponding translated span DuringRenderPurpose.TRANSLATEDcalls render- Specified by:
translatingSpanin interfaceTranslationContext
-
renderInSubContext
-
translatingRefTargetSpan
public void translatingRefTargetSpan(@Nullable @Nullable Node target, @NotNull @NotNull TranslatingSpanRender render) Description copied from interface:TranslationContextSeparate translation span which is also a ref target- Specified by:
translatingRefTargetSpanin interfaceTranslationContext- Parameters:
target- target node,render-
-
nonTranslatingSpan
Description copied from interface:TranslationContextSeparate non-translation span. Will generate a paragraph of text which will not be translatedDuring
RenderPurpose.TRANSLATION_SPANSthis adds the generated output to translation spans DuringRenderPurpose.TRANSLATED_SPANSoutput from renderer is suppressed, instead outputs corresponding translated span DuringRenderPurpose.TRANSLATEDcalls render- Specified by:
nonTranslatingSpanin 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:
postProcessNonTranslatingin 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:
postProcessNonTranslatingin interfaceTranslationContext- Parameters:
postProcessor- id post processor for TRANSLATED purposescope- code to which the post processor applies
-
isPostProcessingNonTranslating
public boolean isPostProcessingNonTranslating()- Specified by:
isPostProcessingNonTranslatingin 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:TranslationContextTransform non-translating textDuring
RenderPurpose.TRANSLATION_SPANSthis converts text to non-translating placeholder based on ordinal id DuringRenderPurpose.TRANSLATED_SPANSthis returns the non-translating placeholder based on ordinal id DuringRenderPurpose.TRANSLATEDthis returns the original non-translating text for the nonTranslatingText (placeholder)- Specified by:
transformNonTranslatingin 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:TranslationContextTransform translating text but which is contextually isolated from the text block in which it is located ie. link reference or image referenceDuring
RenderPurpose.TRANSLATION_SPANSthis converts text to non-translating placeholder based on ordinal id and adds it to translation snippets DuringRenderPurpose.TRANSLATED_SPANSthis returns the non-translating placeholder based on ordinal id DuringRenderPurpose.TRANSLATEDthis returns the translated text for the translatingText (placeholder)- Specified by:
transformTranslatingin 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
-