Package org.daisy.dotify.api.translator
Class TranslatableWithContext
- java.lang.Object
-
- org.daisy.dotify.api.translator.TranslatableWithContext
-
public class TranslatableWithContext extends Object
Provides a specification for a list of texts to translate. This class is best suited for use cases where the input is naturally segmented and contains some segments with dynamic content (in other words, content that may change after it has been submitted to a
BrailleTranslator
or aBrailleFilter
).This class has the following characteristics:
- it applies to a list of text segments
- style attributes apply to whole segments only
- style attributes may span more than one instance of
TranslatableWithContext
- a segment can have a content size that is unknown when the translatable is created
- it provides information about the context of the text segments to translate
- See Also:
Translatable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TranslatableWithContext.Builder
Provides a builder for translatable objects.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T extends ResolvableText>
TranslatableWithContext.Builderfrom(List<T> list, int index)
Returns a new Translatable builder for this list.static <T extends ResolvableText>
TranslatableWithContext.Builderfrom(List<T> list, int fromIndex, int toIndex)
Returns a new Translatable builder for this list.Optional<AttributeWithContext>
getAttributes()
Gets the attribute context.List<FollowingText>
getFollowingText()
Gets the text items in the context that follows the current text.List<PrecedingText>
getPrecedingText()
Gets the text items in the context that preceded the current text.List<ResolvableText>
getTextToTranslate()
Gets the text items to translate.static TranslatableWithContext.Builder
text(TextWithContext texts)
Creates a new Translatable.Builder with the specified text.
-
-
-
Method Detail
-
text
public static TranslatableWithContext.Builder text(TextWithContext texts)
Creates a new Translatable.Builder with the specified text.- Parameters:
texts
- the text to translate- Returns:
- a new Translatable.Builder
-
from
public static <T extends ResolvableText> TranslatableWithContext.Builder from(List<T> list, int index)
Returns a new Translatable builder for this list. The current item is the specified
index
.- Type Parameters:
T
- the type of items- Parameters:
list
- the listindex
- the index of the current item- Returns:
- a new context
- Throws:
IndexOutOfBoundsException
- for an illegal endpoint index value (fromIndex < 0 || toIndex > size || fromIndex > toIndex
)
-
from
public static <T extends ResolvableText> TranslatableWithContext.Builder from(List<T> list, int fromIndex, int toIndex)
Returns a new Translatable builder for this list. The current items are between the specified
fromIndex
, inclusive, andtoIndex
, exclusive. (IffromIndex
andtoIndex
are equal, the current items list is empty, however this isn't useful in practice.)- Type Parameters:
T
- the type of items- Parameters:
list
- the listfromIndex
- low endpoint (inclusive) of the current subListtoIndex
- high endpoint (exclusive) of the current subList- Returns:
- a new context
- Throws:
IndexOutOfBoundsException
- for an illegal endpoint index value (fromIndex < 0 || toIndex > size || fromIndex > toIndex
)
-
getPrecedingText
public List<PrecedingText> getPrecedingText()
Gets the text items in the context that preceded the current text. The preceding text may have been translated with the same translator, or it may have been translated with another translator.- Returns:
- the preceding text items
-
getFollowingText
public List<FollowingText> getFollowingText()
Gets the text items in the context that follows the current text. The following text may be translated with the same translator, or it may be translated with another translator.- Returns:
- the following text items
-
getTextToTranslate
public List<ResolvableText> getTextToTranslate()
Gets the text items to translate.- Returns:
- the text to translate
-
getAttributes
public Optional<AttributeWithContext> getAttributes()
Gets the attribute context.- Returns:
- the attribute context
-
-