On Sun, Apr 20, 2008 at 7:17 PM, Eben Eliason <[EMAIL PROTECTED]> wrote: > All sounds good, thanks for the suggestions. Hopefully I'll have time > to tidy up the patch tomorrow. > > - Eben > > > > > On Sun, Apr 20, 2008 at 5:04 PM, Sayamindu Dasgupta <[EMAIL PROTECTED]> > wrote: > > On Mon, Apr 21, 2008 at 2:18 AM, Tomeu Vizoso <[EMAIL PROTECTED]> wrote: > > > On Sat, Apr 19, 2008 at 7:54 PM, Eben Eliason <[EMAIL PROTECTED]> wrote: > > > > > +NOW = _('Seconds ago') > > > > > > > > > > Translators may not be able to translate adequately from 'Seconds > > > > > ago'. Perhaps a translation comment may help here? Example from > > > > > misc.py: > > > > > > > > > > # TRANS: Relative dates (eg. 1 month and 5 days). > > > > > > > > What if we are explicit in the comment about the intended meaning > of NOW, as in: > > > > # TRANS: Indicating something that just happened; "just now", "right > > > > now", "moments ago" > > > > > > Sounds good. > > > > > > > > > > > +AGO = _(' ago') > > > > > ... > > > > > + return result + AGO > > > > > > > > > > This will break in most languages other than english. Sayamindu, > do > > > > > you have any idea about what can be done here? > > > > > > > > Likewise: > > > > # TRANS: Indicating time passed, eg (1 month, 5 days ago); "ago", > "in > > > > the past", "earlier" > > > > > > Yes, but in some languages that string may appear in a different > > > position inside the sentence. What about _('%s ago') % result instead? > > > Btw, may be better to change the name of the result variable to > > > something more descriptive (like 'period'?). > > > > > > http://docs.python.org/lib/typesseq-strings.html > > > > I would say +1 for the above. It is very difficult to predict how a > > translation might rearrange a string, so _('%s ago') would be the > > safest option (along with a #TRANS comment explaining the string). > > > > Thanks, > > Sayamindu > > > > > > -- > > Sayamindu Dasgupta > > [http://sayamindu.randomink.org/ramblings] > > >
From 468b11787f601ec90a440f0a998edcdcc0a9c661 Mon Sep 17 00:00:00 2001 From: Eben Eliason <[EMAIL PROTECTED]> Date: Sat, 19 Apr 2008 04:13:03 -0400 Subject: [PATCH] Improve formatting of relative dates
This limits display of relative dates to units that are within max_levels of magnitude from the primary unit. In other words, (years, months), (weeks, days), or (hours, minutes), but not (weeks, hours) when max_levels is 2. --- misc.py | 32 +++++++++++++++++++------------- 1 files changed, 19 insertions(+), 13 deletions(-) diff --git a/misc.py b/misc.py index 652930e..9d3ecb8 100644 --- a/misc.py +++ b/misc.py @@ -93,7 +93,13 @@ units = [['%d year', '%d years', 356 * 24 * 60 * 60], AND = _(' and ') COMMA = _(', ') -RIGHT_NOW = _('Right now') + +# TRANS: Indicating something that just happened, eg. "just now", "moments ago" +NOW = _('Seconds ago') + +# TRANS: Indicating time passed, eg. "[10 day, 5 hours] ago", +# "[2 minutes] in the past", or "[3 years, 1 month] earlier" +ELAPSED = _('%s ago') # Explanation of the following hack: # The xgettext utility extracts plural forms by reading the strings included as @@ -117,31 +123,31 @@ del ngettext def _get_elapsed_string(timestamp, max_levels=2): levels = 0 - result = '' + time_period = '' elapsed_seconds = int(time.time() - timestamp) + for name_singular, name_plural, factor in units: elapsed_units = elapsed_seconds / factor if elapsed_units > 0: if levels > 0: - if max_levels - levels == 1: - result += AND - else: - result += COMMA + time_period += COMMA - result += gettext.ngettext(name_singular, name_plural, - elapsed_units) % elapsed_units + time_period += gettext.ngettext(name_singular, name_plural, + elapsed_units) % elapsed_units elapsed_seconds -= elapsed_units * factor + + if time_period != '': levels += 1 - - if levels == max_levels: - break + + if levels == max_levels: + break if levels == 0: - return RIGHT_NOW + return NOW - return result + return ELAPSED % time_period def get_date(jobject): """ Convert from a string in iso format to a more human-like format. """ -- 1.5.3.3
_______________________________________________ Sugar mailing list Sugar@lists.laptop.org http://lists.laptop.org/listinfo/sugar