~ubuntu-branches/ubuntu/wily/padre/wily

« back to all changes in this revision

Viewing changes to lib/Padre/Locale.pm

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2009-08-12 14:44:55 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090812144455-yvk90oa92khfcnls
Tags: 0.42-1
* New Upstream Version
  + add explicit dependency on libtest-simple-perl (>= 0.88)
  + rules: use dh --with quilt (and bump quilt build-dependency to 0.46-7)
  + rules: no need to re-generate .mo files from .po. Upstream does it now
  + copyright: describe share/icons/padre/16x16/logo.png
    - describe share/icons/padre/16x16/toggle-comments.png
    - Padre license is the same as Perl (i.e. not Perl 5)
    - update list of copright holders
    - also list translators
  + drop libtest-most-perl from build-dependencies
  + add liblocale-msgfmt-perl to build-dependencies
  + add libcapture-tiny-perl to (build-)dependencies
  + add libfile-remove-perl (>= 1.42) to (build-)dependencies
  + drop libmodule-inspector-perl from (build-)dependencies
  + add libppix-editortools-perl to (build-)dependencies
  + add libparse-exuberantctags-perl to (build-)dependencies
  + patches:
    - drop lower-wx-requirement-to-2.8.7.patch and replace it with
      SKIP_WXWIDGETS_VERSION_CHECK=1 when configuring
      adjust README.debian accordingly
    - refresh disable-tcp-server.patch
    - drop don't-require-new-file-path.patch (applied upstream)
    - rework fix-pod2-errors.patch (new release, new errors :))
* add fix-perl-interpreter-path.patch fixing the path to the perl interpreter
  in three examples (thanks lintian)
* add more lintian overrides about script-not-executable for scripts that are
  treated as examples/templates
* add fix-whatis.patch fixing the whatis entry of Padre::Wx
* add menu and .desktop file

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
# Padre::Wx should not implement anything using Wx modules.
42
42
# We make an exception in this case, because we're only using the locale
43
43
# logic in Wx, which isn't related to widgets anyway.
44
 
use Padre::Util   ('_T');
45
 
use Padre::Config ();
46
 
use Padre::Wx     ();
 
44
use Padre::Constant ();
 
45
use Padre::Util     ('_T');
 
46
use Padre::Config   ();
 
47
use Padre::Wx       ();
47
48
 
48
49
use constant DEFAULT  => 'en-gb';
49
50
use constant SHAREDIR => File::Spec->rel2abs( Padre::Util::sharedir('locale') );
50
51
 
51
 
our $VERSION = '0.36';
 
52
our $VERSION = '0.42';
52
53
 
53
54
# The RFC4646 table is the primary language data table and contains
54
55
# mappings from a Padre-supported language to all the relevant data
60
61
BEGIN {
61
62
        %RFC4646 = (
62
63
 
63
 
                # The default language for Padre is "United Kingdom English"
64
 
                # The most common English dialect, used not only in the UK,
65
 
                # but also other Commonwealth countries such as Australia,
66
 
                # New Zealand, India, and Canada (sort of...)
 
64
                # The default language for Padre is "United Kingdom English".
 
65
                # This is the most common English dialect, used not only in
 
66
                # the UK, but also other Commonwealth countries such as
 
67
                # Australia, New Zealand, India, and Canada (sort of...)
67
68
                # The following entry for it is heavily commented for
68
69
                # documentation purposes.
69
70
                'en-gb' => {
128
129
                'x-unknown' => {
129
130
                        gettext  => _T('Unknown'),
130
131
                        utf8text => 'Unknown',
131
 
                        iso639   => 'en',                     # For convenience
 
132
                        iso639   => 'en',                  # For convenience
132
133
                        iso3166  => undef,
133
134
                        wxid     => Wx::wxLANGUAGE_UNKNOWN,
134
135
                        fallback => [],
137
138
                # The official languages are listed sorted by identifier.
138
139
                # NOTE: Please do not populate entries into this list unless
139
140
                # you are a native speaker of a particular language and are
140
 
                # fully aware of any
 
141
                # fully aware of any idiosyncracies for that language.
141
142
 
142
143
                'ar' => {
143
144
                        gettext   => _T('Arabic'),
429
430
                # a language is not supported by various older standards.
430
431
                'x-klingon' => {
431
432
                        gettext   => _T('Klingon'),
432
 
                        utf8text  => 'Klingon',       # TODO Fix this at some point
 
433
                        utf8text  => 'Klingon',    # TODO Fix this at some point
433
434
                        iso639    => undef,
434
435
                        iso3166   => undef,
435
436
                        wxid      => undef,
436
 
                        fallback  => ['en-gb'],       # Debatable... :)
 
437
                        fallback  => ['en-gb'],    # Debatable... :)
437
438
                        supported => 0,
438
439
                },
439
440
        );
483
484
#
484
485
sub iso639 {
485
486
        my $id     = rfc4646();
486
 
        my $iso693 = $RFC4646{$id}{iso639};
 
487
        my $iso639 = $RFC4646{$id}{iso639};
 
488
}
 
489
 
 
490
sub system_iso639 {
 
491
        my $system = system_rfc4646();
 
492
        my $iso639 = $RFC4646{$system}{iso639};
487
493
}
488
494
 
489
495
# Given a rfc4646 identifier, sets the language globally
509
515
 
510
516
sub encoding_system_default {
511
517
        my $encoding;
512
 
        if (Padre::Util::MAC) {
 
518
        if (Padre::Constant::MAC) {
513
519
 
514
520
                # In mac system Wx::Locale::GetSystemEncodingName() couldn't
515
521
                # return the name of encoding directly.
523
529
                        $encoding = $codeset;
524
530
                }
525
531
 
526
 
        } elsif (Padre::Util::WIN32) {
 
532
        } elsif (Padre::Constant::WIN32) {
527
533
 
528
534
                # In windows system Wx::Locale::GetSystemEncodingName() returns
529
535
                # like ``windows-1257'' and it matches as ``cp1257''
531
537
                $encoding = Wx::Locale::GetSystemEncodingName();
532
538
                $encoding =~ s/^windows-/cp/i;
533
539
 
534
 
        } elsif (Padre::Util::UNIX) {
 
540
        } elsif (Padre::Constant::UNIX) {
535
541
                $encoding = Wx::Locale::GetSystemEncodingName();
536
542
                unless ($encoding) {
537
543
 
558
564
                return;
559
565
        }
560
566
 
 
567
        Padre::Util::debug("Encoding system default: ($encoding)");
 
568
 
561
569
        return $encoding;
562
570
}
563
571
 
573
581
        # Or, we'll use system default encode setting
574
582
        # If we cannot get system default, then forced it to set 'utf-8'
575
583
        my $default  = '';
576
 
        my @guess    = ();
 
584
        my @guesses  = ();
577
585
        my $encoding = '';
578
586
        my $language = rfc4646();
579
 
        if ( $language eq 'ko' ) {    # Korean
580
 
                @guess = qw/utf-8 euc-kr/;
581
 
        } elsif ( $language eq 'ja' ) {    # Japan (not yet tested)
582
 
                @guess = qw/utf-8 iso8859-1 euc-jp shiftjis 7bit-jis/;
583
 
        } elsif ( $language =~ /^zh/ ) {    # Chinese (not yet tested)
584
 
                @guess = qw/utf-8 iso8859-1 euc-cn/;
 
587
        if ( $language eq 'ko' ) { # Korean
 
588
                @guesses = qw/utf-8 euc-kr/;
 
589
        } elsif ( $language eq 'ja' ) { # Japan (not yet tested)
 
590
                @guesses = qw/utf-8 iso8859-1 euc-jp shiftjis 7bit-jis/;
 
591
        } elsif ( $language =~ /^zh/ ) { # Chinese (not yet tested)
 
592
                @guesses = qw/utf-8 iso8859-1 euc-cn/;
585
593
        } else {
586
594
                $default ||= encoding_system_default();
587
 
                @guess = ($default) if $default;
 
595
                @guesses = ($default) if $default;
588
596
        }
589
597
 
590
598
        require Encode::Guess;
591
 
        my $guess = Encode::Guess::guess_encoding( $content, @guess );
 
599
        my $guess = Encode::Guess::guess_encoding( $content, @guesses );
592
600
        unless ( defined $guess ) {
593
 
                $guess = '';                    # to avoid warnings
 
601
                $guess = '';                 # to avoid warnings
594
602
        }
595
603
 
 
604
        Padre::Util::debug("Encoding guess: ($guess)");
 
605
 
596
606
        # Wow, nice!
597
607
        if ( ref($guess) and ref($guess) =~ m/^Encode::/ ) {
598
608
                $encoding = $guess->name;
620
630
                $encoding = 'utf-8';
621
631
        }
622
632
 
 
633
        Padre::Util::debug("Encoding selected: ($encoding)");
 
634
 
623
635
        return $encoding;
624
636
}
625
637