Documentation

Language
in package

A language represented as a rich domain object.

Languages define how texts are parsed (word boundaries, sentence splitting), dictionary URLs for lookups, and display settings (RTL, text size).

This class enforces domain invariants and encapsulates business logic.

Tags
since
2.10.0-fork

Get new ttsvoiceapi, showromanization properties

since
3.0.0

Refactored to rich domain model

Table of Contents

Properties

$characterSubstitutions  : string
$dict1PopUp  : bool
$dict1Uri  : string
$dict2PopUp  : bool
$dict2Uri  : string
$exceptionsSplitSentences  : string
$exportTemplate  : string
$id  : LanguageId
$localDictMode  : int
$name  : string
$parserType  : string|null
$piperVoiceId  : string|null
$regexpSplitSentences  : string
$regexpWordCharacters  : string
$removeSpaces  : bool
$rightToLeft  : bool
$showRomanization  : bool
$sourceLang  : string|null
$splitEachChar  : bool
$targetLang  : string|null
$textSize  : int
$translatorPopUp  : bool
$translatorUri  : string
$ttsVoiceApi  : string

Methods

characterSubstitutions()  : string
configureCjkMode()  : void
Configure CJK-style language settings.
configureDictionaries()  : void
Configure dictionaries.
configureDictionaryPopups()  : void
Configure popup settings for dictionaries.
configureTextParsing()  : void
Configure text parsing rules.
configureTranslator()  : void
Configure the translator.
configureTranslatorLanguages()  : void
Configure translator language codes.
configureTts()  : void
Configure TTS (text-to-speech) API.
create()  : self
Create a new language with required settings.
dict1Uri()  : string
dict2Uri()  : string
exceptionsSplitSentences()  : string
exportJsDict()  : string|false
Export word data as a JSON dictionary for JavaScript.
exportTemplate()  : string
getDictionaryUrl()  : string
Get dictionary URL for a word.
getDirectionAttribute()  : string
Get RTL direction attribute for HTML.
getEffectiveParserType()  : string
Get the effective parser type, deriving from settings if not explicitly set.
getTranslatorUrl()  : string
Get translator URL for a word.
hasExportTemplate()  : bool
Check if the language has an export template.
hasPiperTts()  : bool
Check if Piper TTS is configured.
hasSecondaryDictionary()  : bool
Check if the language has a secondary dictionary.
hasTranslator()  : bool
Check if the language has a translator configured.
hasTts()  : bool
Check if TTS is configured.
id()  : LanguageId
isCjkStyle()  : bool
Check if this is a CJK-style language (no spaces between words).
isDict1PopUp()  : bool
Check if dictionary 1 should open in a popup window.
isDict2PopUp()  : bool
Check if dictionary 2 should open in a popup window.
isTranslatorPopUp()  : bool
Check if translator should open in a popup window.
localDictMode()  : int
Get the local dictionary mode.
name()  : string
parserType()  : string|null
Get the explicitly set parser type.
piperVoiceId()  : string|null
Get the Piper TTS voice ID.
regexpSplitSentences()  : string
regexpWordCharacters()  : string
removeSpaces()  : bool
rename()  : void
Update the language name.
rightToLeft()  : bool
setExportTemplate()  : void
Configure export template.
setLocalDictMode()  : void
Set the local dictionary mode.
setParserType()  : void
Set the parser type.
setPiperVoiceId()  : void
Set the Piper TTS voice ID.
setRightToLeft()  : void
Set right-to-left display mode.
setShowRomanization()  : void
Set whether to show romanization.
setTextSize()  : void
Configure text display size.
showRomanization()  : bool
sourceLang()  : string|null
Get the source language code (BCP 47).
splitEachChar()  : bool
targetLang()  : string|null
Get the target language code (BCP 47).
textSize()  : int
translatorUri()  : string
ttsVoiceApi()  : string
__construct()  : mixed
Private constructor - use factory methods instead.

Properties

$characterSubstitutions

private string $characterSubstitutions

$exceptionsSplitSentences

private string $exceptionsSplitSentences

$exportTemplate

private string $exportTemplate

$localDictMode

private int $localDictMode

$parserType

private string|null $parserType

$piperVoiceId

private string|null $piperVoiceId

$regexpSplitSentences

private string $regexpSplitSentences

$regexpWordCharacters

private string $regexpWordCharacters

$removeSpaces

private bool $removeSpaces

$showRomanization

private bool $showRomanization

$sourceLang

private string|null $sourceLang

$splitEachChar

private bool $splitEachChar

$targetLang

private string|null $targetLang

$translatorPopUp

private bool $translatorPopUp

$translatorUri

private string $translatorUri

$ttsVoiceApi

private string $ttsVoiceApi

Methods

characterSubstitutions()

public characterSubstitutions() : string
Return values
string

configureCjkMode()

Configure CJK-style language settings.

public configureCjkMode(bool $removeSpaces, bool $splitEachChar) : void

For languages like Chinese/Japanese that don't use spaces between words.

Parameters
$removeSpaces : bool

Whether to remove spaces

$splitEachChar : bool

Whether to split each character

configureDictionaries()

Configure dictionaries.

public configureDictionaries(string $primary[, string $secondary = '' ]) : void
Parameters
$primary : string

Primary dictionary URL

$secondary : string = ''

Secondary dictionary URL

configureDictionaryPopups()

Configure popup settings for dictionaries.

public configureDictionaryPopups(bool $dict1, bool $dict2, bool $translator) : void
Parameters
$dict1 : bool

Dictionary 1 opens in popup

$dict2 : bool

Dictionary 2 opens in popup

$translator : bool

Translator opens in popup

configureTextParsing()

Configure text parsing rules.

public configureTextParsing(string $sentenceSplitRegex, string $sentenceExceptions, string $wordCharRegex[, string $charSubstitutions = '' ]) : void
Parameters
$sentenceSplitRegex : string

Regex for splitting sentences

$sentenceExceptions : string

Exceptions for sentence splitting

$wordCharRegex : string

Regex for word characters

$charSubstitutions : string = ''

Character substitutions

configureTranslator()

Configure the translator.

public configureTranslator(string $translatorUri) : void
Parameters
$translatorUri : string

Translator URL

configureTranslatorLanguages()

Configure translator language codes.

public configureTranslatorLanguages(string|null $sourceLang, string|null $targetLang) : void
Parameters
$sourceLang : string|null

Source language code (BCP 47)

$targetLang : string|null

Target language code (BCP 47)

configureTts()

Configure TTS (text-to-speech) API.

public configureTts(string $apiUrl) : void
Parameters
$apiUrl : string

TTS API URL

create()

Create a new language with required settings.

public static create(string $name, string $dict1Uri, string $regexpSplitSentences, string $regexpWordCharacters) : self
Parameters
$name : string

Language name

$dict1Uri : string

Primary dictionary URL (lwt_term is replaced with word)

$regexpSplitSentences : string

Regex for sentence splitting

$regexpWordCharacters : string

Regex for word characters

Tags
throws
InvalidArgumentException

If name is empty

Return values
self

dict1Uri()

public dict1Uri() : string
Return values
string

dict2Uri()

public dict2Uri() : string
Return values
string

exceptionsSplitSentences()

public exceptionsSplitSentences() : string
Return values
string

exportJsDict()

Export word data as a JSON dictionary for JavaScript.

public exportJsDict() : string|false
Return values
string|false

JSON dictionary or false on error

exportTemplate()

public exportTemplate() : string
Return values
string

getDictionaryUrl()

Get dictionary URL for a word.

public getDictionaryUrl(string $word[, int $dictNum = 1 ]) : string
Parameters
$word : string

The word to look up

$dictNum : int = 1

Which dictionary (1 or 2)

Return values
string

The URL with word substituted

getDirectionAttribute()

Get RTL direction attribute for HTML.

public getDirectionAttribute() : string
Return values
string

' dir="rtl" ' or empty string

getEffectiveParserType()

Get the effective parser type, deriving from settings if not explicitly set.

public getEffectiveParserType() : string
Return values
string

Parser type ('regex', 'character', 'mecab')

getTranslatorUrl()

Get translator URL for a word.

public getTranslatorUrl(string $word) : string
Parameters
$word : string

The word to translate

Return values
string

The URL with word substituted

hasExportTemplate()

Check if the language has an export template.

public hasExportTemplate() : bool
Return values
bool

hasPiperTts()

Check if Piper TTS is configured.

public hasPiperTts() : bool
Return values
bool

hasSecondaryDictionary()

Check if the language has a secondary dictionary.

public hasSecondaryDictionary() : bool
Return values
bool

hasTranslator()

Check if the language has a translator configured.

public hasTranslator() : bool
Return values
bool

hasTts()

Check if TTS is configured.

public hasTts() : bool
Return values
bool

isCjkStyle()

Check if this is a CJK-style language (no spaces between words).

public isCjkStyle() : bool
Return values
bool

isDict1PopUp()

Check if dictionary 1 should open in a popup window.

public isDict1PopUp() : bool
Return values
bool

isDict2PopUp()

Check if dictionary 2 should open in a popup window.

public isDict2PopUp() : bool
Return values
bool

isTranslatorPopUp()

Check if translator should open in a popup window.

public isTranslatorPopUp() : bool
Return values
bool

localDictMode()

Get the local dictionary mode.

public localDictMode() : int
Return values
int

Mode (0=online only, 1=local first, 2=local only, 3=combined)

name()

public name() : string
Return values
string

parserType()

Get the explicitly set parser type.

public parserType() : string|null
Return values
string|null

Parser type or null if not set

piperVoiceId()

Get the Piper TTS voice ID.

public piperVoiceId() : string|null
Return values
string|null

Piper voice ID or null if not set

regexpSplitSentences()

public regexpSplitSentences() : string
Return values
string

regexpWordCharacters()

public regexpWordCharacters() : string
Return values
string

removeSpaces()

public removeSpaces() : bool
Return values
bool

rename()

Update the language name.

public rename(string $name) : void
Parameters
$name : string

The new name

Tags
throws
InvalidArgumentException

If name is empty

rightToLeft()

public rightToLeft() : bool
Return values
bool

setExportTemplate()

Configure export template.

public setExportTemplate(string $template) : void
Parameters
$template : string

The export template

setLocalDictMode()

Set the local dictionary mode.

public setLocalDictMode(int $mode) : void
Parameters
$mode : int

Mode (0=online only, 1=local first, 2=local only, 3=combined)

Tags
throws
InvalidArgumentException

If mode is invalid

setParserType()

Set the parser type.

public setParserType(string|null $parserType) : void
Parameters
$parserType : string|null

Parser type (regex, character, mecab, etc.)

setPiperVoiceId()

Set the Piper TTS voice ID.

public setPiperVoiceId(string|null $voiceId) : void
Parameters
$voiceId : string|null

Piper voice ID (e.g., "en_US-lessac-medium")

setRightToLeft()

Set right-to-left display mode.

public setRightToLeft(bool $rtl) : void
Parameters
$rtl : bool

Whether the language is right-to-left

setShowRomanization()

Set whether to show romanization.

public setShowRomanization(bool $show) : void
Parameters
$show : bool

Whether to show romanization

setTextSize()

Configure text display size.

public setTextSize(int $percentage) : void
Parameters
$percentage : int

Text size percentage (typically 50-200)

Tags
throws
InvalidArgumentException

If percentage is invalid

showRomanization()

public showRomanization() : bool
Return values
bool

sourceLang()

Get the source language code (BCP 47).

public sourceLang() : string|null
Return values
string|null

Source language code or null if not set

splitEachChar()

public splitEachChar() : bool
Return values
bool

targetLang()

Get the target language code (BCP 47).

public targetLang() : string|null
Return values
string|null

Target language code or null if not set

textSize()

public textSize() : int
Return values
int

translatorUri()

public translatorUri() : string
Return values
string

ttsVoiceApi()

public ttsVoiceApi() : string
Return values
string

__construct()

Private constructor - use factory methods instead.

private __construct(LanguageId $id, string $name, string $dict1Uri, string $dict2Uri, string $translatorUri, bool $dict1PopUp, bool $dict2PopUp, bool $translatorPopUp, string|null $sourceLang, string|null $targetLang, string $exportTemplate, int $textSize, string $characterSubstitutions, string $regexpSplitSentences, string $exceptionsSplitSentences, string $regexpWordCharacters, bool $removeSpaces, bool $splitEachChar, bool $rightToLeft, string $ttsVoiceApi, bool $showRomanization[, string|null $parserType = null ][, int $localDictMode = 0 ][, string|null $piperVoiceId = null ]) : mixed
Parameters
$id : LanguageId
$name : string
$dict1Uri : string
$dict2Uri : string
$translatorUri : string
$dict1PopUp : bool
$dict2PopUp : bool
$translatorPopUp : bool
$sourceLang : string|null
$targetLang : string|null
$exportTemplate : string
$textSize : int
$characterSubstitutions : string
$regexpSplitSentences : string
$exceptionsSplitSentences : string
$regexpWordCharacters : string
$removeSpaces : bool
$splitEachChar : bool
$rightToLeft : bool
$ttsVoiceApi : string
$showRomanization : bool
$parserType : string|null = null
$localDictMode : int = 0
$piperVoiceId : string|null = null

        
On this page

Search results