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

List:       kde-i18n-doc
Subject:    [PATCH] Declension of month names in dates
From:       Jacek Stolarczyk <jacek () mer ! chemia ! polsl ! gliwice ! pl>
Date:       2002-08-16 1:10:32
[Download RAW message or body]

Hi,

Why is it needed:
Current framework does not allow to write a proper date in long format in many 
languages.

What the patch does:
1) adds the ability to specify whether you want possessive forms of month 
names in dates ("of January" instead of "January"). In many languages (like 
Polish and Czech) it cannot be done even by concatenating "of" and month name
2) KLocale part is controlled by two keys (l10n/XX/entry.desktop):
	NounDeclension - general, grammar related, specifies whether nouns decline, 
default is false
	DateMonthNamePossessive - whether possessive forms are used
3) adds needed functions to KLocale, extends formatDate and readDate (reading 
is less strict, both possessive and not-possessive forms are recognized)
4) adds a checkbox in Date&Time control module. This chcekbox is visible only 
for languages which have "NounDeclension" set to true in 
l10n/XX/entry.desktop
5) removes "for" loops used unnecessarily in readDate, replaced by "while"

Usage of showEvent is possible a little weird, but moving that part to 
constructor didn't work.

Please, test it. The patch assumes that possessive forms of month names can be 
used only for languages in which nouns decline. That may be wrong, so please, 
notify me, I'll try to modify it accordingly.

I'll wait at least until Monday, before committing it to CVS.

Regards,

Jacek Stolarczyk
-- 
jstolarz@kde.org
Coordinator of Polish translations of KDE

["kloc.diff" (text/x-diff)]

Index: kdecore/klocale.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/klocale.h,v
retrieving revision 1.122
diff -u -r1.122 klocale.h
--- kdecore/klocale.h	2002/07/24 16:14:55	1.122
+++ kdecore/klocale.h	2002/08/16 01:10:03
@@ -393,6 +393,15 @@
 #endif
 
   /**
+   * Use this to determine whether nouns are declined in
+   * locale's language. This property should remain
+   * read-only (no setter function)
+   *
+   * @return If nouns are declined
+   */
+   bool nounDeclension() const;
+
+  /**
    * Returns a string formatted to the current locale's conventions
    * regarding dates.
    *
@@ -404,6 +413,14 @@
   QString formatDate(const QDate &pDate, bool shortFormat = false) const;
 
   /**
+   * Use this to determine whether in dates a possessive form of month
+   * name is preferred ("of January" rather than "January")
+   *
+   * @return If possessive form should be used
+  */
+  bool dateMonthNamePossessive() const;
+
+  /**
    * Returns a string formatted to the current locale's conventions
    * regarding times.
    *
@@ -451,6 +468,18 @@
   QString monthName(int i, bool shortName = false) const;
 
   /**
+   * Returns a string containing the possessive form of the month name.
+   * ("of January", "of February", etc.)
+   * It's needed in long format dates in some languages.
+   *
+   * @param i the month number of the year starting at 1/January.
+   * @param shortName we will return the short version of the string.
+   *
+   * @return The possessive form of the name of the month
+  */
+  QString monthNamePossessive(int i, bool shortName = false) const;
+
+  /**
    * Returns a string containing the name of the week day.
    *
    * @param i the day number of the week starting at 1/Monday.
@@ -628,6 +657,12 @@
    * @param format The new short date format
    */
   void setDateFormatShort(const QString & format);
+  /**
+   * Changes the form of month name used in dates.
+   *
+   * @param possessive True if possessive forms should be used
+   */
+  void setDateMonthNamePossessive(bool possessive);
   /**
    * Changes the current time format.
    *
Index: kdecore/klocale.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/klocale.cpp,v
retrieving revision 1.312
diff -u -r1.312 klocale.cpp
--- kdecore/klocale.cpp	2002/07/24 16:14:55	1.312
+++ kdecore/klocale.cpp	2002/08/16 01:10:13
@@ -51,6 +51,8 @@
 public:
   int weekStartDay;
   int plural_form;
+  bool nounDeclension;
+  bool dateMonthNamePossessive;
   QStringList languageList;
   QValueList<KCatalogue> catalogues;
   QString encoding;
@@ -304,10 +306,15 @@
   readConfigNumEntry("NegativeMonetarySignPosition", (int)ParensAround,
 		     m_negativeMonetarySignPosition, SignPosition);
 
+  //Grammatical
+  readConfigBoolEntry("NounDeclension", false, d->nounDeclension);
+
   // Date and time
   readConfigEntry("TimeFormat", "%H:%M:%S", m_timeFormat);
   readConfigEntry("DateFormat", "%A %d %B %Y", m_dateFormat);
   readConfigEntry("DateFormatShort", "%Y-%m-%d", m_dateFormatShort);
+  readConfigBoolEntry("DateMonthNamePossessive", false,
+		      d->dateMonthNamePossessive);
   readConfigNumEntry("WeekStartDay", 1, d->weekStartDay, int);
 
   // other
@@ -485,6 +492,44 @@
   return QString::null;
 }
 
+QString KLocale::monthNamePossessive(int i, bool shortName) const
+{
+  if ( shortName )
+    switch ( i )
+      {
+      case 1:   return translate("of January", "of Jan");
+      case 2:   return translate("of February", "of Feb");
+      case 3:   return translate("of March", "of Mar");
+      case 4:   return translate("of April", "of Apr");
+      case 5:   return translate("of May short", "of May");
+      case 6:   return translate("of June", "of Jun");
+      case 7:   return translate("of July", "of Jul");
+      case 8:   return translate("of August", "of Aug");
+      case 9:   return translate("of September", "of Sep");
+      case 10:  return translate("of October", "of Oct");
+      case 11:  return translate("of November", "of Nov");
+      case 12:  return translate("of December", "of Dec");
+      }
+  else
+    switch (i)
+      {
+      case 1:   return translate("of January");
+      case 2:   return translate("of February");
+      case 3:   return translate("of March");
+      case 4:   return translate("of April");
+      case 5:   return translate("of May long", "of May");
+      case 6:   return translate("of June");
+      case 7:   return translate("of July");
+      case 8:   return translate("of August");
+      case 9:   return translate("of September");
+      case 10:  return translate("of October");
+      case 11:  return translate("of November");
+      case 12:  return translate("of December");
+      }
+
+  return QString::null;
+}
+
 QString KLocale::weekDayName (int i, bool shortName) const
 {
   if ( shortName )
@@ -809,6 +854,18 @@
   return QString::null;
 }
 
+bool KLocale::nounDeclension() const
+{
+  doFormatInit();
+  return d->nounDeclension;
+}
+
+bool KLocale::dateMonthNamePossessive() const
+{
+  doFormatInit();
+  return d->dateMonthNamePossessive;
+}
+
 int KLocale::weekStartDay() const
 {
   doFormatInit();
@@ -1040,10 +1097,16 @@
 	      put_it_in( buffer, index, pDate.month() );
 	      break;
 	    case 'b':
-	      put_it_in( buffer, index, monthName(pDate.month(), true) );
+	      if (d->nounDeclension && d->dateMonthNamePossessive)
+		put_it_in( buffer, index, monthNamePossessive(pDate.month(), true) );
+	      else
+		put_it_in( buffer, index, monthName(pDate.month(), true) );
 	      break;
 	    case 'B':
-	      put_it_in( buffer, index, monthName(pDate.month(), false) );
+	      if (d->nounDeclension && d->dateMonthNamePossessive)
+		put_it_in( buffer, index, monthNamePossessive(pDate.month(), false) );
+	      else
+		put_it_in( buffer, index, monthName(pDate.month(), false) );
 	      break;
 	    case 'd':
 	      put_it_in( buffer, index, pDate.day() );
@@ -1289,6 +1352,7 @@
     }
     else
     {
+      int j;
       // remove space at the begining
       if (str.length() > strpos && str.at(strpos).isSpace())
         strpos++;
@@ -1300,7 +1364,8 @@
 	case 'A':
 
           error = true;
-	  for (int j = 1; j < 8; j++) {
+	  j = 1;
+	  while (error && (j < 8)) {
 	    QString s = weekDayName(j, c == 'a').lower();
 	    int len = s.length();
 	    if (str.mid(strpos, len) == s)
@@ -1308,13 +1373,28 @@
 	      strpos += len;
               error = false;
             }
+	    j++;
 	  }
 	  break;
 	case 'b':
 	case 'B':
 
           error = true;
-	  for (int j = 1; j < 13; j++) {
+	  if (d->nounDeclension && d->dateMonthNamePossessive) {
+	    j = 1;
+	    while (error && (j < 13)) {
+	      QString s = monthNamePossessive(j, c == 'b').lower();
+	      int len = s.length();
+	      if (str.mid(strpos, len) == s) {
+	        month = j;
+	        strpos += len;
+                error = false;
+	      }
+	      j++;
+	    }
+	  }
+	  j = 1;
+	  while (error && (j < 13)) {
 	    QString s = monthName(j, c == 'b').lower();
 	    int len = s.length();
 	    if (str.mid(strpos, len) == s) {
@@ -1322,6 +1402,7 @@
 	      strpos += len;
               error = false;
 	    }
+	    j++;
 	  }
 	  break;
 	case 'd':
@@ -1726,6 +1807,12 @@
 {
   doFormatInit();
   m_dateFormatShort = format.stripWhiteSpace();
+}
+
+void KLocale::setDateMonthNamePossessive(bool possessive)
+{
+  doFormatInit();
+  d->dateMonthNamePossessive = possessive;
 }
 
 void KLocale::setTimeFormat(const QString & format)

["kloctim.diff" (text/x-diff)]

Index: kcontrol/locale/localetime.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/locale/localetime.h,v
retrieving revision 1.15
diff -u -r1.15 localetime.h
--- kcontrol/locale/localetime.h	2002/07/31 19:35:42	1.15
+++ kcontrol/locale/localetime.h	2002/08/16 01:08:18
@@ -46,6 +46,9 @@
   virtual ~KLocaleConfigTime( );
 
   void save();
+  
+protected:
+  void showEvent( QShowEvent *e );
 
 public slots:
   /**
@@ -66,6 +69,7 @@
   void slotDateFmtChanged(const QString &t);
   void slotDateFmtShortChanged(const QString &t);
   void slotWeekStartDayChanged(int firstDay);
+  void slotDateMonthNamePossChanged();
 
 private:
   QValueList<StringPair> timeMap() const;
@@ -89,6 +93,7 @@
   QComboBox * m_comboDateFmtShort;
   QLabel * m_labWeekStartDay;
   QComboBox * m_comboWeekStartDay;
+  QCheckBox *m_chDateMonthNamePossessive;
 };
 
 #endif
Index: kcontrol/locale/localetime.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/locale/localetime.cpp,v
retrieving revision 1.48
diff -u -r1.48 localetime.cpp
--- kcontrol/locale/localetime.cpp	2002/07/31 19:35:42	1.48
+++ kcontrol/locale/localetime.cpp	2002/08/16 01:08:21
@@ -200,7 +200,7 @@
    m_locale(_locale)
 {
   // Time
-  QGridLayout *lay = new QGridLayout(this, 5, 2,
+  QGridLayout *lay = new QGridLayout(this, 6, 2,
 				     KDialog::marginHint(),
 				     KDialog::spacingHint());
   lay->setAutoAdd(TRUE);
@@ -232,7 +232,11 @@
           << I18N_NOOP("Thursday") << I18N_NOOP("Friday") << I18N_NOOP("Saturday")
           << I18N_NOOP("Sunday");
   m_comboWeekStartDay->insertStringList(tmpDays);
-
+  
+  m_chDateMonthNamePossessive = new QCheckBox(this, I18N_NOOP("Use declined form of month name"));
+  connect( m_chDateMonthNamePossessive, SIGNAL( clicked() ),
+	     SLOT( slotDateMonthNamePossChanged() ) );
+  
   lay->setColStretch(1, 1);
 }
 
@@ -278,12 +282,30 @@
   if (firstDay != m_locale->weekStartDay())
       config->writeEntry("WeekStartDay", m_locale->weekStartDay(), true, true);
 
+  if ( m_locale->nounDeclension() )
+  {
+    bool b;    
+    b = ent.readNumEntry("DateMonthNamePossessive", false);
+    config->deleteEntry("DateMonthNamePossessive", false, true);
+    if (b != m_locale->dateMonthNamePossessive())
+      config->writeEntry("DateMonthNamePossessive",
+		         m_locale->dateMonthNamePossessive(), true, true);    
+  }
+      
   config->sync();
 
   // restore the old global locale
   KGlobal::_locale = lsave;
 }
 
+void KLocaleConfigTime::showEvent( QShowEvent *e )
+{
+  // This option makes sense only for languages where nouns are declined
+   if ( !m_locale->nounDeclension() )
+    m_chDateMonthNamePossessive->hide();  
+   QWidget::showEvent( e );
+}
+
 void KLocaleConfigTime::slotLocaleChanged()
 {
   //  m_edTimeFmt->setText( m_locale->timeFormat() );
@@ -297,6 +319,9 @@
 					  m_locale->dateFormatShort() ) );
   m_comboWeekStartDay->setCurrentItem( m_locale->weekStartDay() - 1 );
 
+  if ( m_locale->nounDeclension() )
+    m_chDateMonthNamePossessive->setChecked( m_locale->dateMonthNamePossessive() );
+  
   kdDebug(173) << "converting: " << m_locale->timeFormat() << endl;
   kdDebug(173) << storeToUser(timeMap(),
 			   m_locale->timeFormat()) << endl;
@@ -333,6 +358,15 @@
     emit localeChanged();
 }
 
+void KLocaleConfigTime::slotDateMonthNamePossChanged()
+{
+  if (m_locale->nounDeclension())
+  {
+    m_locale->setDateMonthNamePossessive(m_chDateMonthNamePossessive->isChecked());
+    emit localeChanged();
+  }
+} 
+
 void KLocaleConfigTime::slotTranslate()
 {
   QString str;
@@ -429,5 +463,13 @@
     ("<p>This option determines which day will be considered as "
      "the first one of the week.</p>");
   QWhatsThis::add( m_comboWeekStartDay,  str );
+  
+  if ( m_locale->nounDeclension() )
+  {
+    str = m_locale->translate
+      ("<p>This option determines whether possessive form of month "
+       "names should be used in dates.</p>");
+    QWhatsThis::add( m_chDateMonthNamePossessive,  str );
+  }
 }
 

["l10npl.diff" (text/x-diff)]

Index: l10n/pl/entry.desktop
===================================================================
RCS file: /home/kde/kdebase/l10n/pl/entry.desktop,v
retrieving revision 1.154
diff -u -r1.154 entry.desktop
--- l10n/pl/entry.desktop	2002/07/31 10:39:39	1.154
+++ l10n/pl/entry.desktop	2002/08/16 01:09:13
@@ -73,3 +73,5 @@
 DateFormatShort=%d/%m/%Y
 DateFormat[eo]=%A, la %ea de %B %Y
 TimeFormat=%H:%M:%S
+NounDeclension=true
+DateMonthNamePossessive=true


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

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