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');
44
use Padre::Constant ();
45
use Padre::Util ('_T');
48
49
use constant DEFAULT => 'en-gb';
49
50
use constant SHAREDIR => File::Spec->rel2abs( Padre::Util::sharedir('locale') );
51
our $VERSION = '0.36';
52
our $VERSION = '0.42';
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
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.
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,
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
141
# fully aware of any idiosyncracies for that language.
143
144
gettext => _T('Arabic'),
429
430
# a language is not supported by various older standards.
431
432
gettext => _T('Klingon'),
432
utf8text => 'Klingon', # TODO Fix this at some point
433
utf8text => 'Klingon', # TODO Fix this at some point
434
435
iso3166 => undef,
436
fallback => ['en-gb'], # Debatable... :)
437
fallback => ['en-gb'], # Debatable... :)
485
486
my $id = rfc4646();
486
my $iso693 = $RFC4646{$id}{iso639};
487
my $iso639 = $RFC4646{$id}{iso639};
491
my $system = system_rfc4646();
492
my $iso639 = $RFC4646{$system}{iso639};
489
495
# Given a rfc4646 identifier, sets the language globally
531
537
$encoding = Wx::Locale::GetSystemEncodingName();
532
538
$encoding =~ s/^windows-/cp/i;
534
} elsif (Padre::Util::UNIX) {
540
} elsif (Padre::Constant::UNIX) {
535
541
$encoding = Wx::Locale::GetSystemEncodingName();
536
542
unless ($encoding) {
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 = '';
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/;
586
594
$default ||= encoding_system_default();
587
@guess = ($default) if $default;
595
@guesses = ($default) if $default;
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
604
Padre::Util::debug("Encoding guess: ($guess)");
597
607
if ( ref($guess) and ref($guess) =~ m/^Encode::/ ) {
598
608
$encoding = $guess->name;