LanguageFacade
in package
Facade for language module operations.
Provides a unified interface to all language-related use cases. Designed for backward compatibility with existing LanguageService callers.
Tags
Table of Contents
Properties
- $createLanguage : CreateLanguage
- $deleteLanguage : DeleteLanguage
- $getLanguageById : GetLanguageById
- $getLanguageCode : GetLanguageCode
- $getPhoneticReading : GetPhoneticReading
- $listLanguages : ListLanguages
- $reparseLanguageTexts : ReparseLanguageTexts
- $repository : LanguageRepositoryInterface
- $updateLanguage : UpdateLanguage
Methods
- __construct() : mixed
- Constructor.
- canDelete() : bool
- Check if a language can be deleted (no related data).
- create() : array{success: bool, id: int}
- Save a new language to the database from request data.
- createEmptyLanguage() : Language
- Create an empty language object with default values.
- createFromData() : int
- Create a new language from data array (API-friendly version).
- delete() : array{success: bool, count: int, error: ?string}
- Delete a language.
- deleteById() : bool
- Delete a language by ID (API-friendly version).
- exists() : bool
- Check if a language exists by ID.
- getAllLanguages() : array<string, int>
- Get all languages as a name => id dictionary.
- getById() : Language|null
- Get a language by ID.
- getLanguageCode() : string
- Try to get language code from its ID.
- getLanguageDataFromRequest() : array<string, string|int|bool|null>
- Get language data from request using InputValidator.
- getLanguageName() : string
- Get language name from its ID.
- getLanguagesForSelect() : array<int, array{id: int, name: string}>
- Get languages formatted for select dropdown options.
- getLanguagesWithArchivedTextCounts() : array<int, array{id: int, name: string, text_count: int}>
- Get languages that have at least one archived text, with archived text counts.
- getLanguagesWithStats() : array<string|int, mixed>
- Get languages with statistics for display.
- getLanguagesWithTextCounts() : array<int, array{id: int, name: string, text_count: int}>
- Get languages that have at least one text, with text counts.
- getPhoneticReadingByCode() : string
- Convert text to phonetic representation by language code.
- getPhoneticReadingById() : string
- Convert text to phonetic representation using MeCab (for Japanese).
- getRelatedDataCounts() : array{texts: int, archivedTexts: int, words: int, feeds: int}
- Get counts of related data for a language.
- getScriptDirectionTag() : string
- Return a right-to-left direction indication in HTML if language is RTL.
- isDuplicateName() : bool
- Check if a language name is duplicate.
- refresh() : array{sentencesDeleted: int, textItemsDeleted: int, sentencesAdded: int, textItemsAdded: int}
- Refresh (reparse) all texts for a language.
- refreshTexts() : array{sentencesDeleted: int, textItemsDeleted: int, sentencesAdded: int, textItemsAdded: int}
- Refresh (reparse) all texts for a language and return stats.
- toViewObject() : stdClass
- Convert a Language entity to a view object (stdClass) for templates.
- update() : array{success: bool, reparsed: ?int, error: ?string}
- Update an existing language from request data.
- updateFromData() : array{success: bool, reparsed: int, message: string}
- Update an existing language from data array (API-friendly version).
Properties
$createLanguage
protected
CreateLanguage
$createLanguage
$deleteLanguage
protected
DeleteLanguage
$deleteLanguage
$getLanguageById
protected
GetLanguageById
$getLanguageById
$getLanguageCode
protected
GetLanguageCode
$getLanguageCode
$getPhoneticReading
protected
GetPhoneticReading
$getPhoneticReading
$listLanguages
protected
ListLanguages
$listLanguages
$reparseLanguageTexts
protected
ReparseLanguageTexts
$reparseLanguageTexts
$repository
protected
LanguageRepositoryInterface
$repository
$updateLanguage
protected
UpdateLanguage
$updateLanguage
Methods
__construct()
Constructor.
public
__construct([LanguageRepositoryInterface|null $repository = null ][, CreateLanguage|null $createLanguage = null ][, DeleteLanguage|null $deleteLanguage = null ][, GetLanguageById|null $getLanguageById = null ][, GetLanguageCode|null $getLanguageCode = null ][, GetPhoneticReading|null $getPhoneticReading = null ][, ListLanguages|null $listLanguages = null ][, ReparseLanguageTexts|null $reparseLanguageTexts = null ][, UpdateLanguage|null $updateLanguage = null ]) : mixed
Parameters
- $repository : LanguageRepositoryInterface|null = null
-
Repository instance
- $createLanguage : CreateLanguage|null = null
-
Create use case
- $deleteLanguage : DeleteLanguage|null = null
-
Delete use case
- $getLanguageById : GetLanguageById|null = null
-
Get by ID use case
- $getLanguageCode : GetLanguageCode|null = null
-
Get code use case
- $getPhoneticReading : GetPhoneticReading|null = null
-
Phonetic reading use case
- $listLanguages : ListLanguages|null = null
-
List use case
- $reparseLanguageTexts : ReparseLanguageTexts|null = null
-
Reparse use case
- $updateLanguage : UpdateLanguage|null = null
-
Update use case
canDelete()
Check if a language can be deleted (no related data).
public
canDelete(int $id) : bool
Parameters
- $id : int
-
Language ID
Return values
boolcreate()
Save a new language to the database from request data.
public
create() : array{success: bool, id: int}
Return values
array{success: bool, id: int}createEmptyLanguage()
Create an empty language object with default values.
public
createEmptyLanguage() : Language
Return values
LanguagecreateFromData()
Create a new language from data array (API-friendly version).
public
createFromData(array<string, mixed> $data) : int
Parameters
- $data : array<string, mixed>
-
Language data (camelCase keys)
Return values
int —Created language ID, or 0 on failure
delete()
Delete a language.
public
delete(int $id) : array{success: bool, count: int, error: ?string}
Parameters
- $id : int
-
Language ID
Return values
array{success: bool, count: int, error: ?string}deleteById()
Delete a language by ID (API-friendly version).
public
deleteById(int $id) : bool
Parameters
- $id : int
-
Language ID
Return values
bool —True if deleted
exists()
Check if a language exists by ID.
public
exists(int $id) : bool
Parameters
- $id : int
-
Language ID
Return values
boolgetAllLanguages()
Get all languages as a name => id dictionary.
public
getAllLanguages() : array<string, int>
Return values
array<string, int>getById()
Get a language by ID.
public
getById(int $id) : Language|null
Parameters
- $id : int
-
Language ID
Return values
Language|null —Language entity or null if not found
getLanguageCode()
Try to get language code from its ID.
public
getLanguageCode(int $id, array<string, array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}> $languagesTable) : string
Parameters
- $id : int
-
Language ID
- $languagesTable : array<string, array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}>
-
Table of languages, usually from LanguagePresets::getAll()
Return values
string —Two-letter code (e.g., BCP 47) or empty string
getLanguageDataFromRequest()
Get language data from request using InputValidator.
public
getLanguageDataFromRequest() : array<string, string|int|bool|null>
Return values
array<string, string|int|bool|null>getLanguageName()
Get language name from its ID.
public
getLanguageName(string|int $id) : string
Parameters
- $id : string|int
-
Language ID
Return values
string —Language name, empty string if not found
getLanguagesForSelect()
Get languages formatted for select dropdown options.
public
getLanguagesForSelect([int $maxNameLength = 30 ]) : array<int, array{id: int, name: string}>
Parameters
- $maxNameLength : int = 30
-
Maximum name length before truncation
Return values
array<int, array{id: int, name: string}>getLanguagesWithArchivedTextCounts()
Get languages that have at least one archived text, with archived text counts.
public
getLanguagesWithArchivedTextCounts() : array<int, array{id: int, name: string, text_count: int}>
Return values
array<int, array{id: int, name: string, text_count: int}>getLanguagesWithStats()
Get languages with statistics for display.
public
getLanguagesWithStats() : array<string|int, mixed>
Return values
array<string|int, mixed> —Language data with counts
getLanguagesWithTextCounts()
Get languages that have at least one text, with text counts.
public
getLanguagesWithTextCounts() : array<int, array{id: int, name: string, text_count: int}>
Return values
array<int, array{id: int, name: string, text_count: int}>getPhoneticReadingByCode()
Convert text to phonetic representation by language code.
public
getPhoneticReadingByCode(string $text, string $lang) : string
Parameters
- $text : string
-
Text to be converted
- $lang : string
-
Language code (usually BCP 47 or ISO 639-1)
Return values
string —Parsed text in phonetic format
getPhoneticReadingById()
Convert text to phonetic representation using MeCab (for Japanese).
public
getPhoneticReadingById(string $text, int $id) : string
Parameters
- $text : string
-
Text to be converted
- $id : int
-
Language ID
Return values
string —Parsed text in phonetic format
getRelatedDataCounts()
Get counts of related data for a language.
public
getRelatedDataCounts(int $id) : array{texts: int, archivedTexts: int, words: int, feeds: int}
Parameters
- $id : int
-
Language ID
Return values
array{texts: int, archivedTexts: int, words: int, feeds: int}getScriptDirectionTag()
Return a right-to-left direction indication in HTML if language is RTL.
public
getScriptDirectionTag(string|int|null $id) : string
Parameters
- $id : string|int|null
-
Language ID
Tags
Return values
string —' dir="rtl" ' or empty string
isDuplicateName()
Check if a language name is duplicate.
public
isDuplicateName(string $name[, int $excludeLgId = 0 ]) : bool
Parameters
- $name : string
-
Language name
- $excludeLgId : int = 0
-
Language ID to exclude from check (for updates)
Return values
boolrefresh()
Refresh (reparse) all texts for a language.
public
refresh(int $id) : array{sentencesDeleted: int, textItemsDeleted: int, sentencesAdded: int, textItemsAdded: int}
Parameters
- $id : int
-
Language ID
Return values
array{sentencesDeleted: int, textItemsDeleted: int, sentencesAdded: int, textItemsAdded: int}refreshTexts()
Refresh (reparse) all texts for a language and return stats.
public
refreshTexts(int $id) : array{sentencesDeleted: int, textItemsDeleted: int, sentencesAdded: int, textItemsAdded: int}
Parameters
- $id : int
-
Language ID
Return values
array{sentencesDeleted: int, textItemsDeleted: int, sentencesAdded: int, textItemsAdded: int}toViewObject()
Convert a Language entity to a view object (stdClass) for templates.
public
toViewObject(Language $language) : stdClass
Parameters
- $language : Language
-
The Language entity
Return values
stdClass —View object with public properties
update()
Update an existing language from request data.
public
update(int $id) : array{success: bool, reparsed: ?int, error: ?string}
Parameters
- $id : int
-
Language ID
Return values
array{success: bool, reparsed: ?int, error: ?string}updateFromData()
Update an existing language from data array (API-friendly version).
public
updateFromData(int $id, array<string, mixed> $data) : array{success: bool, reparsed: int, message: string}
Parameters
- $id : int
-
Language ID
- $data : array<string, mixed>
-
Language data (camelCase keys)