Changeset 2292


Ignore:
Timestamp:
12/30/08 17:26:30 (3 years ago)
Author:
adamk
Message:

Creating proposed data structure to serve as the basis for second-generation locale support.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/Locale.pm

    r2284 r2292  
    11package Padre::Locale; 
    22 
    3 # Padre::Locale provides a variety of locale and encoding support functions, 
    4 # to prevent locale code (which can be fairly complex) from being scattered 
    5 # all over the codebase. 
    6 # 
    7 # Note: Normally, namespace convention is that modules outside of Padre::Wx 
     3=pod 
     4 
     5=head1 NAME 
     6 
     7Padre::Locale - Locale support for Padre 
     8 
     9=head1 DESCRIPTION 
     10 
     11B<Padre::Locale> is a utility library that implements locale and encoding 
     12support for the L<Padre> editor, and serves as an integration point between 
     13the various identifier systems (Wx identifiers, ISO639, RFC3066, RFC4646) 
     14 
     15The module implements a collection of public functions that can be called 
     16by various parts of the editor to get locale and encoding information. 
     17 
     18None of the functions in B<Padre::Locale> are exported. Because the need 
     19for encoding and locale functionality is very high in a user-facing 
     20application like Padre, the resulting quantity of exports would be very 
     21very high. 
     22 
     23Forcing all calls to the functions to be fully referenced assists in 
     24reducing the complexity of the Perl symbol table (saving a small amount of 
     25memory) and serves to improve maintainability, as there can always be 
     26certainty about where a particular function is being called from. 
     27 
     28=head1 FUNCTIONS 
     29 
     30TO BE COMPLETED 
     31 
     32=cut 
     33 
     34use 5.008; 
     35use strict; 
     36use warnings; 
     37 
     38# NOTE: Normally, namespace convention is that modules outside of Padre::Wx 
    839# should not implement anything using Wx modules. 
    940# We make an exception in this case, because we're only using the locale 
    1041# logic in Wx, which isn't related to widgets anyway. 
    11  
    12 use 5.008; 
    13 use strict; 
    14 use warnings; 
    1542use Padre::Util (); 
    1643use Padre::Wx   (); 
     
    2350 
    2451##################################################################### 
    25 # Locale Support 
     52# Locale 2.0 Tables 
     53 
     54use constant RFC4646_DEFAULT => 'en-gb'; 
     55 
     56# The RFC4646 table is the primary language data table and contains 
     57# mappings from a Padre-supported language to all the relevant data 
     58# about that language. 
     59# According to the RFC all identifiers are case-insensitive, but for 
     60# simplicity (for now) we list them all as lower-case. 
     61my %RFC4646 = ( 
     62    # The default language for Padre is "United Kingdom English" 
     63    # The most common English dialect, used not only in the UK, 
     64    # but also other Commonwealth countries such as Australia, 
     65    # New Zealand, India, and Canada (sort of...) 
     66    # The following entry for it is heavily commented for 
     67    # documentation purposes. 
     68    'en-gb' => { 
     69        # REQUIRED: The gettext msgid for the language. 
     70        gettext   => 'English (British)', 
     71 
     72        # REQUIRED: Mapping to ISO 639 language tag. 
     73        # Used by Padre's first-generation locale support 
     74        # This should be lowercase. 
     75        iso639    => 'en', 
     76 
     77        # OPTIONAL: Mapping to the ISO 3166 country code. 
     78        # This should be uppercase. 
     79        iso3166   => 'GB', 
     80 
     81        # REQUIRED: The wxWidgets language (integer) identifier. 
     82        wxid      => Wx::wxLANGUAGE_ENGLISH_UK, 
     83 
     84        # OPTIONAL: The wxWidgets catalog file to use. 
     85        # Having this as an explicit file name simplified the 
     86        # transition from the old to the new style. 
     87        wxcatalog => 'en.mo', 
     88 
     89        # OPTIONAL: Recommended language fallback sequence. 
     90        # This is an ordered list of alternative languages 
     91        # that Padre should try to use if no first-class 
     92        # support is available for this language. 
     93        # This is mainly used to allow closest-dialect support. 
     94        # For example, if full support for "Portugese Portugese" 
     95        # is not available, we first attempt to use 
     96        # "Brazillian Portugese" first, before falling back on 
     97        # "American English" and only then the default. 
     98        # Entries in the fallback list express intent, and 
     99        # they do not need to have an entry in %RFC4646. 
     100        fallback  => [ ], 
     101    }, 
     102 
     103    # Example entry for an language which is not supported directly, 
     104    # but which Padre is aware of. 
     105    'en-au' => { 
     106        gettext  => 'English (Australian)', 
     107        iso639   => 'en', 
     108        iso3166  => 'AU', 
     109        wxid     => Wx::wxLANGUAGE_ENGLISH_AUSTRALIAN, 
     110        # Even though en-gb is the default language, in this 
     111        # specific case there is a clearly expressed desire for 
     112        # this fallback path. 
     113        # If we are ever forced for technical reasons to move to 
     114        # using en-us as a default, this group would explicitly 
     115        # wish to retain the final fallback to en-gb. 
     116        fallback => [ 'en-nz', 'en-gb' ], 
     117    }, 
     118 
     119    # The remaining languages are listed sorted by identifier. 
     120    # NOTE: Please do not populate entries into this list unless 
     121    # you are a native speaker of a particular language and are 
     122    # fully aware of any  
     123 
     124    'en-nz' => { 
     125        gettext  => 'English (New Zealand)', 
     126        iso639   => 'en', 
     127        iso3166  => 'NZ', 
     128        wxid     => Wx::wxLANGUAGE_NEW_ZEALAND, 
     129        fallback => [ 'en-au', 'en-gb' ], # The en-au is debatable 
     130    }, 
     131 
     132    'en-us' => { 
     133        gettext  => 'English (US)', 
     134        iso639   => 'en', 
     135        iso3166  => 'US', 
     136        wxid     => Wx::wxLANGUAGE_ENGLISH_US, 
     137    }, 
     138 
     139     
     140); 
     141 
     142 
     143 
     144 
     145 
     146##################################################################### 
     147# Locale 1.0 Support 
    26148 
    27149use constant DEFAULT_LOCALE => 'en'; 
    28  
    29150 
    30151my %SHORTNAME = ( 
    31152    Wx::wxLANGUAGE_ARABIC()        => 'ar', 
    32153    Wx::wxLANGUAGE_GERMAN()        => 'de', 
     154 
     155    # This should be addressed by the fallback system 
    33156    Wx::wxLANGUAGE_ENGLISH_US()    => 'en', 
     157 
    34158    Wx::wxLANGUAGE_FRENCH()        => 'fr', 
    35159    Wx::wxLANGUAGE_HEBREW()        => 'he', 
     
    39163    Wx::wxLANGUAGE_RUSSIAN()       => 'ru', 
    40164    Wx::wxLANGUAGE_DUTCH()         => 'nl', 
    41     Wx::wxLANGUAGE_PORTUGUESE() => 'pt', # probably should be 'pt_br' 
    42         Wx::wxLANGUAGE_SPANISH()    => 'es', 
     165 
     166    # Probably should be a separate 'pt_br' 
     167    # (With apologies to the Portugese) 
     168    Wx::wxLANGUAGE_PORTUGUESE()    => 'pt', 
     169 
     170        Wx::wxLANGUAGE_SPANISH()       => 'es', 
    43171); 
    44172 
     
    47175# LANGUAGES hash needs to be here in order 
    48176# the get the run-time language change for these words too. 
     177my %LANGUAGES = ( 
     178    ar => Wx::gettext('Arabic'), 
     179    de => Wx::gettext('German'), 
     180    en => Wx::gettext('English'), 
     181    fr => Wx::gettext('French'), 
     182    he => Wx::gettext('Hebrew'), 
     183    hu => Wx::gettext('Hungarian'), 
     184    ko => Wx::gettext('Korean'), 
     185    it => Wx::gettext('Italian'), 
     186    ru => Wx::gettext('Russian'), 
     187    nl => Wx::gettext('Dutch'), 
     188    pt => Wx::gettext('Portuguese'), # Actually brazilian, which is a bug 
     189        es => Wx::gettext('Spanish'), 
     190); 
     191 
     192# TODO: The need for direct access to the table indicates a failure 
     193#       on the part of Padre::Locale to provide sufficiently useful 
     194#       functions. Second-generation locale support has data that is 
     195#       too complex to be reasonably useful to external consumers, so 
     196#       we need to fix that by providing more direct functions. 
    49197sub languages { 
    50     return ( 
    51         ar => Wx::gettext('Arabic'), 
    52         de => Wx::gettext('German'), 
    53         en => Wx::gettext('English'), 
    54         fr => Wx::gettext('French'), 
    55         he => Wx::gettext('Hebrew'), 
    56         hu => Wx::gettext('Hungarian'), 
    57         ko => Wx::gettext('Korean'), 
    58         it => Wx::gettext('Italian'), 
    59         ru => Wx::gettext('Russian'), 
    60         nl => Wx::gettext('Dutch'), 
    61         pt => Wx::gettext('Portuguese'), # brazilian 
    62                 es => Wx::gettext('Spanish'), 
    63     ); 
     198    return %LANGUAGES; 
    64199} 
    65200 
Note: See TracChangeset for help on using the changeset viewer.