NAME

Lingua::StarDict::Writer - A module that allows to create a StarDict dictionary

VERSION

Version 0.01

SYNOPSIS

A module that allows to create a StarDict-compatible dictionary, with multipart and multitype entries.

use Lingua::StarDict::Writer;

my $stardict_writer = StarDict::Writer->new(name=>'My Cool Dictionary', date=>"2020-12-31");

$stardict_writer->entry('42')->add_part(type=> "t", data => "ˈfɔɹti tuː");
$stardict_writer->entry('42')->add_part(type=> "m", data => "Answer to the Ultimate Question of Life, the Universe, and Everything");

$stardict_writer->entry('Perl')->add_part(type=> "t", data => "pɛʁl");
$stardict_writer->entry('Perl')->add_part(type=> "h", data => "The <b>best</b> programming language ever");

$stardict_writer->write;

DESCRIPTION

StarDict is a popular dictionary format, supported by many dictionary and book reading programs.

StarDict entry may consist of several parts of various text or media types.

This module allows to create a new StarDict dictionary with entries consisting of parts of arbitrary types.

METHODS

new ( option_name => 'value')

Constructs and returns a new Lingua::StarDict::Writer object. This object will accept parts for the dictionary entry via add_entry_part method. You can write the resulting dictionary with write method. new method accepts arguments represented as name=>value options hash. Following options are available:

  • name - sets a name for the dictionary. It will be specified in StarDict dictionary .ifo file as dictionary name. When you call write method, writer will create name dir in the output_dir dir, and all dictionary files that will be written there will use name as the base part of file name. By default, the name will be set to "Some Dictionary written by Lingua::StarDict::Writer" if none is provided.

  • date - date of dictionary creation in YYYY-MM-DD format. Will be saved in Stardict .ifo file. By default, current date will be used.

  • output_dir - path where dictionary files will be saved. By default, current dir will be used as the output_dir.

entry($entry_title)

Returns dictionary entry named $entry_title, if entry $entry_title does not exist, a new empty empty dictionary entry will be created and returned. The only reason you may want to get dictionary entry is to add a new part using add_part method (See below)

Entries can be added in arbitrary order, they will be sorted alphabetically using StarDict sorting algorithm, when dictionary is written.

entry->($enry_title)->add_part(type => $part_type, data => $part_data)

Adds new part to an entry.

  • type - part type, coded as one Latin letter as specified in StarDictFileFormat. ('m' for plaintext, 'h' for html, 't' for pronunciation, etc. See StarDictFileFormat in "See Also" chapter for more info). By default 'm' type will be used if none is specified.

  • data - Content of added entry part: a text string that can be formatted using chosen type markup.

Parts will be saved in the entry in the order they were added.

write

This method will write all entries to the disk formatted as StarDict dictionary. .dict .idx and .ifo files will be placed in a name dir at the path you've specified in output_dir option. You should put them to /usr/share/stardict/dic or ~/.stardict/dic path to make them visible to StarDict.

ENCODING ISSUE

All methods expect to recieve data encoded as perl character strings, not byte string (I.e. Cyrillic "я" should be encoded as \x{44f}, and not as \x{d1}\x{8f}. If you have read utf-8 source data from a file, database or from web, make sure that utf-8 bytes you've got are converted to perl characters. See this article for more info.

CAVEATS

  • sametypesequence mode is not implemented. Use custom sequence mode instead.

  • Support for binary parts is not implemented.

  • Dictionary compression is not implemented.

  • Synonyms is not implemented.

etc...

SEE ALSO

  • StarDictFileFormat - StarDict format description. A copy of this file can be found in this package in doc/ dir.

  • Lingua::StarDict::Gen - another module for writing StarDict dictionaries. It supports only single-part plain text entries.

AUTHOR

Nikolay Shaplov, <dhyan at nataraj.su>

CREDITS

Special thanks to xq from freenode #perl for deep code review.

BUGS

Please report any bugs or feature requests through the web interface at https://gitlab.com/dhyannataraj/lingua-stardict-writer-perl/-/issues

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Lingua::StarDict::Writer

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2021 Nikolay Shaplov.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.