1Locale::MO::File(3)   User Contributed Perl Documentation  Locale::MO::File(3)
2
3
4

NAME

6       Locale::MO::File - Write/read gettext MO files
7
8       $Id: File.pm 645 2018-12-24 10:16:32Z steffenw $
9
10       $HeadURL:
11       svn+ssh://steffenw@svn.code.sf.net/p/dbd-po/code/Locale-MO-File/trunk/lib/Locale/MO/File.pm
12       $
13

VERSION

15       0.09
16

SYNOPSIS

18           require Locale::MO::File;
19
20           my $mo = Locale::MO::File->new(
21               filename => $filename,
22               ...
23               messages => [
24                   {
25                       msgid  => 'original',
26                       msgstr => 'translation',
27                       ...
28                   },
29                   ...
30               ],
31           });
32           $mo->write_file;
33
34           $mo->read_file;
35           my $messages = $self->get_messages;
36

DESCRIPTION

38       The module allows to write or read gettext MO files.
39
40       Data to write are expected as array reference of hash references.  Read
41       data are stored in an array reference too.
42
43       Reading and writing is also available using an already open file
44       handle.  A given file handle will used but not closed.
45
46       Set encoding, newline and byte order to be compatible.
47

SUBROUTINES/METHODS

49   method new
50       This is the constructor method.  All parameters are optional.
51
52           my $mo = Locale::MO::File->new(
53               filename      => $string,
54               file_handle   => $file_handle, # filename expected for error messages only
55               encoding      => $string,      # e.g. 'UTF-8', if not set: bytes
56               newline       => $string,      # e.g. $CRLF or "\n", if not set: no change
57               is_big_endian => $boolean,     # if not set: little endian
58               messages      => $arrayref,    # default []
59           );
60
61   methods to modify an existing object
62       set_filename, get_filename, clear_filename
63
64       Modification of attribute filename.
65
66           $mo->set_filename($string);
67           $string = $mo->get_filename;
68           $mo->clear_filename;
69
70       set_file_handle, get_file_handle, clear_file_handle
71
72       Modification of attribute file_handle.
73
74       set_encoding, get_encoding, clear_encoding
75
76       Modification of attribute encoding.
77
78       set_newline, get_newline, clear_newline
79
80       Modification of attribute newline.
81
82       set_is_big_endian, is_big_endian, clear_is_big_endian
83
84       Modification of attribute is_big_endian.  Only needed to write files.
85
86   method set_messages, get_messages
87       Modification of attribute messages.
88
89           $mo->set_messages([
90               # header
91               {
92                   msgid   => q{},
93                   msgstr  => $header,
94               },
95               # typical
96               {
97                   msgid   => $original,
98                   msgstr  => $translation,
99               },
100               # context
101               {
102                   msgctxt => $context,
103                   msgid   => $original,
104                   msgstr  => $translation,
105               },
106               # plural
107               {
108                   msgid         => $original_singular,
109                   msgid_plural  => $original_plural,
110                   msgstr_plural => [ $tanslation_0, ..., $translation_n ],
111               },
112               # context + plural
113               {
114                   msgctxt       => $context,
115                   msgid         => $original_singular,
116                   msgid_plural  => $original_plural,
117                   msgstr_plural => [ $tanslation_0, ..., $translation_n ],
118               },
119           ]);
120
121   method write_file
122       The content of the "messages" array reference is first sorted and then
123       written.  So the header is always on top.  The transferred "messages"
124       array reference remains unchanged.
125
126           $mo->write_file;
127
128   method read_file
129       Big endian or little endian will be detected automaticly.  The read
130       data will be stored in attribute messages.
131
132           $mo = read_file;
133           my $messages = $mo->get_messages;
134

EXAMPLE

136       Inside of this distribution is a directory named example.  Run the *.pl
137       files.
138

DIAGNOSTICS

140       Full validation of messages array reference using Params::Validate.
141

CONFIGURATION AND ENVIRONMENT

143       none
144

DEPENDENCIES

146       charnames
147
148       namespace::autoclean
149
150       Carp
151
152       Const::Fast
153
154       Encode
155
156       English
157
158       IO::File
159
160       Moo
161
162       MooX::StrictConstructor
163
164       MooX::Types::MooseLike::Base
165
166       Params::Validate
167

INCOMPATIBILITIES

169       not known
170

BUGS AND LIMITATIONS

172       Hashing table not written of this module version.  So very slim MO
173       files are the result.
174

SEE ALSO

176       <http://www.gnu.org/software/hello/manual/gettext/MO-Files.html>
177

AUTHOR

179       Steffen Winkler
180
182       Copyright (c) 2011 - 2018, Steffen Winkler "<steffenw at cpan.org>".
183       All rights reserved.
184
185       This module is free software; you can redistribute it and/or modify it
186       under the same terms as Perl itself.
187
188
189
190perl v5.32.0                      2020-07-28               Locale::MO::File(3)
Impressum