[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-i18n-doc
Subject:    Re: Need some help with number/date related code
From:       Chusslove Illich <caslav.ilic () gmx ! net>
Date:       2010-06-24 10:48:31
Message-ID: 201006241248.38767.caslav.ilic () gmx ! net
[Download RAW message or body]


> > [: Chusslove Illich :]
> > Could you also show us a screenshot of the dialog [...]
> 
> [: Bertjan Broeksema :]
> Yep, attached.

(Is this dialog supposed to replace the one with a lot of combos for
selecting pieces of reccurence, defined by incidencerecurrenceeditor.ui? Or
they are not related?)

First one point besides your question. The label-combo-label sequence
"every [<>N] year(s)" should be made such that when the combo value changes,
texts to labels "every" and "year(s)" ("month(s)", etc.) are set again by
plural i18n calls. The adjective "every" is also sensitive to gender of
year/month/...; but about this you can't do anything on the code side,
except to add a dynamic context. Putting it together, something like:

  void IncidenceRecurrence::updateReccurenceTypeLabels (int freq, int num)
  {
      QString labelFreq;
      QString freqKey;
      switch (freq) {
      case 2:
          labelFreq = i18ncp("repeat every N >weeks<", "week", "weeks", num);
          freqKey = 'w';
          break;
      case 3:
          labelFreq = i18ncp("repeat every N >months<", "month", "months", num);
          freqKey = 'm';
          break;
      case 4:
          labelFreq = i18ncp("repeat every N >years<", "year", "years", num);
          freqKey = 'y';
          break;
      default:
          labelFreq = i18ncp("repeat every N >days<", "day", "days", num);
          freqKey = 'd';
      }
      QString labelEvery;
      labelEvery = ki18ncp("repeat >every< N years/months/...; "
                           "dynamic context 'type': 'd' days, 'w' weeks, "
                           "'m' months, 'y' years",
                           "every")
                           .subs(num).inContext("type", freqKey).toString();
      mUi->mFrequencyLabel->setText(labelEvery);
      mUi->mRecurrenceRuleLabel->setText(labelFreq);
  }

Onto your question, first the numberToString() function is quite problematic
on its own. For a given number it produces the English ordinal ("1st",
"22nd", "143rd"), which of course does not apply to other languages. I
propose here to query translators whether to use the English ordinal or not;
if not, use just the number itself. Then the extra problem is that in non-
English case the number should really be substituted as a number type (for
proper locale formatting and some other things), and not converted to
string; therefore numberToString() should be replaced with something like
subsOrdinal() (see below for usage):

  KLocalizedString IncidenceRecurrence::subsOrdinal (const KLocalizedString &text,
                                                     int number) const
  {
      QString q = i18nc("In several of the messages below, "
                        "an ordinal number is substituted into the message. "
                        "Translate this as \"0\" if English ordinal suffixes "
                        "should be added (1st, 22nd, 123rd); "
                        "translate this as \"1\" if just the number itself "
                        "should be substituted (1, 22, 123).",
                        "0");
      if (q == "0") {
          QString ordinal;
          // ...as before, but store the string rather than return...
          return text.subs(ordinal);
      } else {
          return text.subs(number);
      }
  }

As the context of the query message suggests, for proper positional context
to translators (which see messages in order of appearance), move this
function above any usage of it in the file.

Finally, there isn't really anything that you can do in the code for
complete strings. You should only use the usual placeholder substitution,
instead of piecing up strings. E.g. this:

  item = "the " + numberToString( startDate.daysInMonth() - startDate.day() ) + " \
last day of " + longMonthName;

should become (taking subsOrdinal() into account):

  item = subsOrdinal(ki18nc("example: the 3rd last day of June",
                            "the %1 last day of %2"),
                     startDate.daysInMonth() - startDate.day())
         .subs(longMonthName).toString();

(If anyone is wondering by now, there was some discussion already to add
ordinal numbers functionality into KLocale, but there are some murky areas
with that.)

-- 
Chusslove Illich (Часлав Илић)
Serbian KDE translation team


["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic