Lingua::StarDict::Writer - A module that allows to create a StarDict dictionary
Version 0.01
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;
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.
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:
Lingua::StarDict::Writer
add_entry_part
write
new
name=>value
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.
name
.ifo
output_dir
"Some Dictionary written by Lingua::StarDict::Writer"
date - date of dictionary creation in YYYY-MM-DD format. Will be saved in Stardict .ifo file. By default, current date will be used.
date
YYYY-MM-DD
output_dir - path where dictionary files will be saved. By default, current dir will be used as the output_dir.
Returns dictionary entry named $entry_title. If entry $entry_title does not exist, a new empty dictionary entry will be created and returned. The only reason you may want to get a dictionary entry is to add a new part using add_part method (See below)
$entry_title
add_part
Entries can be added in arbitrary order, they will be sorted alphabetically using StarDict sorting algorithm, when dictionary is written.
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.
type
'm'
'h'
't'
data - Content of added entry part: a text string that can be formatted using chosen type markup.
data
Parts will be saved in the entry in the order they were added.
This method will write all entries to the disk formatted as StarDict dictionary. .dict, .idx and .ifo files will be placed in directory name at the path specified in output_dir option. You should put them to /usr/share/stardict/dic or ~/.stardict/dic path to make them visible to StarDict.
.dict
.idx
/usr/share/stardict/dic
~/.stardict/dic
All methods expect to recieve data encoded as perl character strings, not as 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.
\x{44f}
\x{d1}\x{8f}
sametypesequence mode is not implemented. Use custom sequence mode instead.
sametypesequence
Support for binary parts is not implemented.
Dictionary compression is not implemented.
Synonyms are not implemented.
etc...
StarDictFileFormat - StarDict format description. A copy of this file can be found in this package in doc/ dir.
doc/
Lingua::StarDict::Gen - another module for writing StarDict dictionaries. It supports only single-part plain text entries.
Nikolay Shaplov, <dhyan at nataraj.su>
<dhyan at nataraj.su>
Please report any bugs or feature requests through the web interface at https://gitlab.com/dhyannataraj/lingua-stardict-writer-perl/-/issues
You can find documentation for this module with the perldoc command.
perldoc Lingua::StarDict::Writer
You can also look for information at:
The project's bug tracker (report bugs and request features here)
https://gitlab.com/dhyannataraj/lingua-stardict-writer-perl/-/issues
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Lingua-StarDict-Writer
CPAN Ratings
https://cpanratings.perl.org/d/Lingua-StarDict-Writer
Search CPAN
https://metacpan.org/release/Lingua-StarDict-Writer
Special thanks to xq from freenode #perl for deep code review.
freenode
#perl
Thanks to Rince for proofreading.
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.
To install Lingua::StarDict::Writer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Lingua::StarDict::Writer
CPAN shell
perl -MCPAN -e shell install Lingua::StarDict::Writer
For more information on module installation, please visit the detailed CPAN module installation guide.