Ticket #6859: js-i18n-doc.diff

File js-i18n-doc.diff, 2.5 KB (added by Ramiro Morales, 17 years ago)
  • docs/i18n.txt

    diff -r da74ed639346 docs/i18n.txt
    a b take a string as their first argument an  
    338338take a string as their first argument and do something to that string. These
    339339functions are used by template filters as well as directly in other code.
    340340
    341 If you write your own similar functions and deal with translations, you'll 
     341If you write your own similar functions and deal with translations, you'll
    342342face the problem of what to do when the first argument is a lazy translation
    343343object. You don't want to convert it to a string immediately, because you might
    344344be using this function outside of a view (and hence the current thread's locale
    You can make the view dynamic by putting  
    789789You can make the view dynamic by putting the packages into the URL pattern::
    790790
    791791    urlpatterns = patterns('',
    792         (r'^jsi18n/(?P<packages>\S+?)/$, 'django.views.i18n.javascript_catalog'),
     792        (r'^jsi18n/(?P<packages>\S+?)/$', 'django.views.i18n.javascript_catalog'),
    793793    )
    794794
    795795With this, you specify the packages as a list of package names delimited by '+'
    interface to access it::  
    811811
    812812    document.write(gettext('this is to be translated'));
    813813
    814 There even is a ``ungettext`` interface and a string interpolation function::
     814There even is a ``ngettext`` interface and a string interpolation function::
    815815
    816816    d = {
    817817        count: 10
    818818    };
    819     s = interpolate(ungettext('this is %(count)s object', 'this are %(count)s objects', d.count), d);
     819    s = interpolate(ngettext('this is %(count)s object', 'this are %(count)s objects', d.count), d);
    820820
    821821The ``interpolate`` function supports both positional interpolation and named
    822822interpolation. So the above could have been written as::
    823823
    824     s = interpolate(ungettext('this is %s object', 'this are %s objects', 11), [11]);
     824    s = interpolate(ngettext('this is %s object', 'this are %s objects', 11), [11]);
    825825
    826826The interpolation syntax is borrowed from Python. You shouldn't go over the top
    827827with string interpolation, though: this is still JavaScript, so the code will
    828828have to do repeated regular-expression substitutions. This isn't as fast as
    829829string interpolation  in Python, so keep it to those cases where you really
    830 need it (for example, in conjunction with ``ungettext`` to produce proper
     830need it (for example, in conjunction with ``ngettext`` to produce proper
    831831pluralizations).
    832832
    833833Creating JavaScript translation catalogs
Back to Top