Serge

 view release on metacpan or  search on metacpan

doc/sample.serge  view on Meta::CPAN

        # that allows one to mark up unstructured plain text files for translation
        output_default_lang_file    NO

        # (STRING) [OPTIONAL] Output encoding for generated language files
        # Sample values: UTF-8, UTF-16, UCS-2, UCS-4
        # Default: UTF-8
        # This value has effect only if `output_lang_files` or `output_default_lang_file`
        # parameters are set to YES
        output_encoding             UCS-2LE

        # (BOOLEAN) [OPTIONAL] Should the BOM ("byte order mark")
        # be emitted at the beginning of the output file?
        # YES - output the BOM (default)
        # NO - do not output the BOM
        output_bom                  YES

        # [OPTIONAL] Map telling to use different language name in language macros
        # (see the list of available macros in `ts_file_path` parameter description)
        # and when constructing output path (see `output_file_path` parameter).
        # This allows to tweak language/locale names for different projects.
        output_lang_rewrite
        {
            no                      nb
        }

lib/Serge/Engine.pm  view on Meta::CPAN

    if ($result eq '0') {
        print "\t\tSkip saving $fullpath because at least one callback returned 0\n";# if $self->{debug};
        return;
    }

    $self->run_callbacks('before_save_localized_file', $file, $lang, \$out);

    my $enc = $self->{job}->{output_encoding};
    my $text;

    # print BOM
    if ($self->{job}->{output_bom}) {
        $text = "\xFF\xFE"         if  (uc($enc) eq 'UTF-16LE');
        $text = "\xFE\xFF"         if ((uc($enc) eq 'UTF-16BE') || (uc($enc) eq 'UTF-16'));
        $text = "\xFF\xFE\x00\x00" if  (uc($enc) eq 'UTF-32LE');
        $text = "\x00\x00\xFE\xFF" if ((uc($enc) eq 'UTF-32BE') || (uc($enc) eq 'UTF-32'));
        $text = "\xEF\xBB\xBF"     if  (uc($enc) eq 'UTF-8');
    }

    # append content
    $text .= encode($enc, $out);

lib/Serge/Util.pm  view on Meta::CPAN


    open(SRC, $fname) || die "Can't read [$fname]: $!";
    binmode(SRC);
    my $data = join('', <SRC>);
    close(SRC);

    my $decoder = Encode::Guess->guess($data);
    if (ref($decoder)) {
        my $enc = uc($decoder->name);

        # remove BOM
        # (not sure why this was done, as BOM is apparently needed for at least UTF-16 decoding;
        # so I disabled BOM removal for UTF-16 for now)
        $data =~ s/^\xFF\xFE//s         if  ($enc eq 'UTF-16LE');
        #$data =~ s/^\xFE\xFF//s         if (($enc eq 'UTF-16BE') || ($enc eq 'UTF-16'));
        $data =~ s/^\xFF\xFE\x00\x00//s if  ($enc eq 'UTF-32LE');
        $data =~ s/^\x00\x00\xFE\xFF//s if (($enc eq 'UTF-32BE') || ($enc eq 'UTF-32'));
        $data =~ s/^\xEF\xBB\xBF//s     if (($enc eq 'UTF-8')    || ($enc eq 'UTF8'));

        $data = $decoder->decode($data);
    } else {
        if ($data =~ m/^<\?xml\s+(.+?)\?>/i) {
            my $attrs = $1;
            if ($attrs =~ m/encoding=['"](.+?)['"]/i) {
                my $enc = uc($1);
                #print "\t\tEncoding (from XML header): $enc\n";

                # remove BOM
                $data =~ s/^\xEF\xBB\xBF//s if (($enc eq 'UTF-8') || ($enc eq 'UTF8'));

                $data = decode($enc, $data);
            }
        } else {
            #print "\t\tEncoding (default): ASCII\n"; # $decoder holds the error string
        }
    }

    $data =~ s/\r\n/\n/sg; # normalize line-feeds



( run in 0.889 second using v1.01-cache-2.11-cpan-131fc08a04b )