Code

Changes between Version 1 and Version 2 of InterNationalization


Ignore:
Timestamp:
08/03/05 04:56:50 (9 years ago)
Author:
Moof <moof@…>
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • InterNationalization

    v1 v2  
    1 Currently being written up by [wiki:Moof Moof] -- 2005-08-03 10:43am GMT 
     1See also: [wiki:Localization Localization], Ticket #65, [http://developers.sun.com/dev/gadc/i18ntesting/checklists/allquestions/allquestions.html Sun.com i18n checklist index] 
     2 
     3There are a lot of things we need to do to get Django properly internationalised. 
     4 
     5This page and subject are actively '''under discussion''' over on [http://groups-beta.google.com/group/django-developers/browse_thread/thread/6a222dcb4b3978b8/a93afb70fb8a3f80 this thread in django-developers]. 
     6 
     7There are two parts to Django i18n, that need to be treated separately: Program Internals, and Templating system. This page is an attempt to create an overview of what needs to be done, in order to generate discussion. Eventually, some more tickets will be created out of these steps. 
     8 
     9== Program Internals == 
     10 
     11This is not an exhaustive list, we need to identify more things to do, and go into more detail. 
     12 
     13=== New Code === 
     14The [http://www.python.org/doc/current/lib/module-gettext.html gettext] module seems an ideal place to start, but both the gettext module and it's sibling, the [http://www.python.org/doc/current/lib/module-locale.html locale] module, seem to only really work well for single-threaded, single-locale applications. Since part of the i18n effort is to try to enable working with multiple-language websites, it seems that we must unfortunately create a lot more of the i18n framework than we would otherwise have thought. The two modules are not a total loss, we can still use large amounts of them as long as we can specify the locale on-the-fly, they are just not perfect for our need. See [http://groups-beta.google.com/group/django-developers/msg/a93afb70fb8a3f80 this message for problems with gettext] and [http://groups-beta.google.com/group/django-developers/msg/04ee6e2311b09b9b this message for problems with locale] and subsequent discussions on the thread. 
     15 
     16 * Create our own string type which will do translations lazily on an as-required basis. Will need to cope with slicing, and locale-specific interpolation of numbers, dates, etc. See [wiki:I18nString I18nString] for a more detailed specification. 
     17 * Work out how to set locale to be per-session, with appropriate fallbacks. 
     18 * Locale negotiatation: HTTP Defines an {{{Accept-Language}}} header (see section 14.4 of the [http://www.faqs.org/rfcs/rfc2616.html HTTP RFC]), a Django app should by default send out content in the preferred language of the browser, or if that is not available, work down the list of acceptable languages, trying to find one until giving up and falling back on the default language. 
     19    * In any case, a user-set locale should override any negotiated locale. If I'm in a Turkish internet café, the page should come up in Turkish until I click on English, at which point I should continue in English. 
     20 
     21=== Current Code that needs modifying === 
     22 
     23 * Identify all strings in all modules that need internationalising. I suggest one ticket per major module group, e.g. core, meta, templatetags. 
     24    * This includes all error messages. If exceptions with error messages are passed on to the user (e.g. Database errors), these need to be intercepted and translated appropriately, even if it's just adding something like "A Database Error Occurred: " before printing out the traceback or message. 
     25 * Recode meta.*Field to print out the translated field name even if no field name was specified 
     26    * This probably means coding up some sort of .pot file generator in django-admin.py or similar utility that understands things like meta.*Field models having a default name when none is specified. 
     27 * Ensure things like date select boxes in the admin interface show locale-specific month names. 
     28 * Ensure that all code can cope with unicode strings. Specifically, remove all references to {{{str()}}} and any string interpolation using non-unicode strings for anything other than essential data that needs keeping as strings, e.g. module names. 
     29 
     30== Templating System == 
     31 
     32This is, potentially, the easier of the two. 
     33 
     34 * Define a common locale directory format - something like application/localecode/template.html eg: {{{poll/en/template.html}}} or something like application/template.html.localecode eg: {{{poll/template.html.en}}} 
     35 * Modify generic views to cope with locale template searching, both explicitly passed on locales (for websites that want to have {{{http://example.com/en/2005/08/03/}}} or {{{http://example.com/2005/08/03/en}}} and implicit locales in things like sessions. 
     36 * Possibly: Create a generic i18n view, which copes with people sticking locale codes in URLs eg: {{{http://example.com/myapp/en/mypage/}}} or {{{http://example.com/myapp/mypage/en/}}} 
     37 * Put locales into the Templating system. Specifically, a locale object needs to be available in all templates for things like making up URLs, and displaying the current locale on the page, and also {{{{% extends %}}}} needs to be made (optionally) locale-aware. 
     38 * Find an easy way to mark template string for internationalization, and get the template system to deal with this appropriately (or just specify that each language should use its own set of templates, though this can be a big drag if you have 40 languages' worth of templates you want to make a minor change in.) 
     39 * Fully internationalize things like the date filter, to make sure it prints out locale-specific month names. 
     40 
     41== Miscellanea, and items for further discussion == 
     42 
     43 * How does Plone do it? They claim to be "fully internationalized". They have documentation on how to [http://plone.org/documentation/how-to/i18n-for-developers/ internationalize page templates] but I can't find anything for internal strings and objects. 
     44 * Write documentation on how to do all this stuff, for the programmer. (I'm quite happy to do this -- [wiki:Moof Moof]