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
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
$dict1PopUp
private
bool
$dict1PopUp
$dict1Uri
private
string
$dict1Uri
$dict2PopUp
private
bool
$dict2PopUp
$dict2Uri
private
string
$dict2Uri
$exceptionsSplitSentences
private
string
$exceptionsSplitSentences
$exportTemplate
private
string
$exportTemplate
$id
private
LanguageId
$id
$localDictMode
private
int
$localDictMode
$name
private
string
$name
$parserType
private
string|null
$parserType
$piperVoiceId
private
string|null
$piperVoiceId
$regexpSplitSentences
private
string
$regexpSplitSentences
$regexpWordCharacters
private
string
$regexpWordCharacters
$removeSpaces
private
bool
$removeSpaces
$rightToLeft
private
bool
$rightToLeft
$showRomanization
private
bool
$showRomanization
$sourceLang
private
string|null
$sourceLang
$splitEachChar
private
bool
$splitEachChar
$targetLang
private
string|null
$targetLang
$textSize
private
int
$textSize
$translatorPopUp
private
bool
$translatorPopUp
$translatorUri
private
string
$translatorUri
$ttsVoiceApi
private
string
$ttsVoiceApi
Methods
characterSubstitutions()
public
characterSubstitutions() : string
Return values
stringconfigureCjkMode()
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
Return values
selfdict1Uri()
public
dict1Uri() : string
Return values
stringdict2Uri()
public
dict2Uri() : string
Return values
stringexceptionsSplitSentences()
public
exceptionsSplitSentences() : string
Return values
stringexportJsDict()
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
stringgetDictionaryUrl()
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
boolhasPiperTts()
Check if Piper TTS is configured.
public
hasPiperTts() : bool
Return values
boolhasSecondaryDictionary()
Check if the language has a secondary dictionary.
public
hasSecondaryDictionary() : bool
Return values
boolhasTranslator()
Check if the language has a translator configured.
public
hasTranslator() : bool
Return values
boolhasTts()
Check if TTS is configured.
public
hasTts() : bool
Return values
boolid()
public
id() : LanguageId
Return values
LanguageIdisCjkStyle()
Check if this is a CJK-style language (no spaces between words).
public
isCjkStyle() : bool
Return values
boolisDict1PopUp()
Check if dictionary 1 should open in a popup window.
public
isDict1PopUp() : bool
Return values
boolisDict2PopUp()
Check if dictionary 2 should open in a popup window.
public
isDict2PopUp() : bool
Return values
boolisTranslatorPopUp()
Check if translator should open in a popup window.
public
isTranslatorPopUp() : bool
Return values
boollocalDictMode()
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
stringparserType()
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
stringregexpWordCharacters()
public
regexpWordCharacters() : string
Return values
stringremoveSpaces()
public
removeSpaces() : bool
Return values
boolrename()
Update the language name.
public
rename(string $name) : void
Parameters
- $name : string
-
The new name
Tags
rightToLeft()
public
rightToLeft() : bool
Return values
boolsetExportTemplate()
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
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
showRomanization()
public
showRomanization() : bool
Return values
boolsourceLang()
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
booltargetLang()
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
inttranslatorUri()
public
translatorUri() : string
Return values
stringttsVoiceApi()
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