Documentation

StarDictImporter implements ImporterInterface

Importer for StarDict dictionary files.

Parses .ifo (info), .idx (index), and .dict (data) files. Supports both compressed (.dict.dz) and uncompressed (.dict) formats.

Tags
since
3.0.0

Table of Contents

Interfaces

ImporterInterface
Interface for dictionary importers.

Properties

$info  : array<string, string>
Dictionary metadata from .ifo file.

Methods

canImport()  : bool
Validate that a file can be imported.
getInfo()  : array<string, string>
Get dictionary metadata.
getSupportedExtensions()  : array<string|int, string>
Get the supported file extensions for this importer.
parse()  : iterable<string|int, array{term: string, definition: string, reading?: ?string, pos?: ?string}>
Parse a dictionary file and yield entries.
preview()  : array<string|int, array{term: string, definition: string, reading?: ?string, pos?: ?string}>
Get a preview of the first N entries.
cleanDefinition()  : string
Clean up a definition string.
findDictFile()  : string|null
Find the dictionary data file (.dict or .dict.dz).
getBasePath()  : string
Get the base path (without extension) for a StarDict file.
openDictFile()  : resource|false
Open the dictionary data file.
parseIdx()  : Generator<string|int, array{term: string, offset: int, size: int}>
Parse the .idx (index) file.
parseIfo()  : void
Parse the .ifo (info) file.
readDefinition()  : string|null
Read a definition from the dictionary file.

Properties

$info

Dictionary metadata from .ifo file.

private array<string, string> $info = []

Methods

canImport()

Validate that a file can be imported.

public canImport(string $filePath) : bool
Parameters
$filePath : string

Path to the file

Return values
bool

True if the file can be imported

getInfo()

Get dictionary metadata.

public getInfo(string $filePath) : array<string, string>
Parameters
$filePath : string

Path to any StarDict file

Return values
array<string, string>

Dictionary info

getSupportedExtensions()

Get the supported file extensions for this importer.

public getSupportedExtensions() : array<string|int, string>
Return values
array<string|int, string>

parse()

Parse a dictionary file and yield entries.

public parse(string $filePath[, array<string|int, mixed> $options = [] ]) : iterable<string|int, array{term: string, definition: string, reading?: ?string, pos?: ?string}>
Parameters
$filePath : string

Path to the dictionary file

$options : array<string|int, mixed> = []

Import options (format-specific)

Return values
iterable<string|int, array{term: string, definition: string, reading?: ?string, pos?: ?string}>

preview()

Get a preview of the first N entries.

public preview(string $filePath[, int $limit = 10 ][, array<string|int, mixed> $options = [] ]) : array<string|int, array{term: string, definition: string, reading?: ?string, pos?: ?string}>
Parameters
$filePath : string

Path to the dictionary file

$limit : int = 10

Number of entries to preview

$options : array<string|int, mixed> = []

Import options

Return values
array<string|int, array{term: string, definition: string, reading?: ?string, pos?: ?string}>

cleanDefinition()

Clean up a definition string.

private cleanDefinition(string $definition) : string
Parameters
$definition : string

Raw definition

Return values
string

Cleaned definition

findDictFile()

Find the dictionary data file (.dict or .dict.dz).

private findDictFile(string $basePath) : string|null
Parameters
$basePath : string

Base path without extension

Return values
string|null

Path to dict file or null

getBasePath()

Get the base path (without extension) for a StarDict file.

private getBasePath(string $filePath) : string
Parameters
$filePath : string

Path to any StarDict file

Return values
string

Base path

openDictFile()

Open the dictionary data file.

private openDictFile(string $dictPath) : resource|false
Parameters
$dictPath : string

Path to dict file

Return values
resource|false

File handle or false

parseIdx()

Parse the .idx (index) file.

private parseIdx(string $idxPath) : Generator<string|int, array{term: string, offset: int, size: int}>
Parameters
$idxPath : string

Path to .idx file

Return values
Generator<string|int, array{term: string, offset: int, size: int}>

parseIfo()

Parse the .ifo (info) file.

private parseIfo(string $ifoPath) : void
Parameters
$ifoPath : string

Path to .ifo file

Tags
throws
RuntimeException

If file is invalid

readDefinition()

Read a definition from the dictionary file.

private readDefinition(resource $handle, int $offset, int $size) : string|null
Parameters
$handle : resource

File handle

$offset : int

Byte offset

$size : int

Data size

Return values
string|null

Definition text


        
On this page

Search results