Permalink
Browse files

[fix] using now plural forms with gettext, not just an 's'-suffix wha…

…t doesn't work in lot of languages
  • Loading branch information...
1 parent ee66304 commit 27d029f3db4f6b861e5ac22547a9b14a0e812d39 @haschek committed Jun 6, 2011
Showing with 57 additions and 32 deletions.
  1. BIN lang/de_DE/pubwich-de_DE.mo
  2. +35 −3 lang/de_DE/pubwich-de_DE.po
  3. +22 −29 lib/Pubwich.php
View
Binary file not shown.
@@ -7,10 +7,12 @@ msgstr ""
"Last-Translator: Michael Haschke <haschek@eye48.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
-"X-Poedit-Language: French\n"
-"X-Poedit-Country: FRANCE\n"
+"X-Poedit-Language: German\n"
+"X-Poedit-Country: GERMANY\n"
+"Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1;\n"
+"X-Poedit-SourceCharset: utf-8\n"
#: lib/Pubwich.php:78
msgid "Pubwich object initialization"
@@ -56,6 +58,36 @@ msgstr "Week"
msgid "day"
msgstr "Tag"
+#: manuell für lib/Pubwich ab 400
+msgid "1 second ago"
+msgid_plural "%d seconds ago"
+msgstr[0] "vor einer Sekunde"
+msgstr[1] "vor %d Sekunden"
+
+#: manuell für lib/Pubwich ab 400
+msgid "1 minute ago"
+msgid_plural "%d minuten ago"
+msgstr[0] "vor einer Minute"
+msgstr[1] "vor %d Minuten"
+
+#: manuell für lib/Pubwich ab 400
+msgid "1 hour ago"
+msgid_plural "%d hours ago"
+msgstr[0] "vor einer Stunde"
+msgstr[1] "vor %d Stunden"
+
+#: manuell für lib/Pubwich ab 400
+msgid "1 day ago"
+msgid_plural "%d days ago"
+msgstr[0] "vor einem Tag"
+msgstr[1] "vor %d Tagen"
+
+#: manuell für lib/Pubwich ab 400
+msgid "1 week ago"
+msgid_plural "%d weeks ago"
+msgstr[0] "vor einer Woche"
+msgstr[1] "vor %d Wochen"
+
#: lib/Pubwich.php:340
msgid "hour"
msgstr "Stunde"
View
@@ -69,13 +69,17 @@ static public function init() {
/**
* Translate a string according to the defined locale/
*
- * @param string $string
+ * @param string $single
* @return string
*/
- static public function _( $string ) {
+ static public function _($single, $plural=false, $number=false) {
// gettext lib throws notices, so we turn off all error reporting
// for the translation process
- return (self::$gettext ) ? @self::$gettext->translate( $string ) : $string;
+
+ if ($plural===false && $number===false)
+ return (self::$gettext ) ? @self::$gettext->translate( $single ) : $string;
+
+ return (self::$gettext ) ? @self::$gettext->ngettext($single, $plural, $number) : $string;
}
/**
@@ -381,45 +385,34 @@ static public function getFooter() {
static public function time_since( $original ) {
$original = strtotime( $original );
-
- $chunks = array(
- array( 60 * 60 * 24 * 365 , Pubwich::_('year') ),
- array( 60 * 60 * 24 * 30 , Pubwich::_('month' ) ),
- array( 60 * 60 * 24 * 7, Pubwich::_('week') ),
- array( 60 * 60 * 24 , Pubwich::_('day') ),
- array( 60 * 60 , Pubwich::_('hour') ),
- array( 60 , Pubwich::_('minute') ),
- );
-
$today = time();
$since = $today - $original;
if ( $since < 0 ) {
return sprintf( Pubwich::_('just moments ago'), $since );
}
- if ( $since < 60 ) {
- return sprintf( Pubwich::_('%d seconds ago'), $since );
+ if ( $since >= ( 7 * 24 * 60 * 60 ) ) {
+ return strftime( Pubwich::_('%e %B at %H:%M'), $original );
}
- if ( $since > ( 7 * 24 * 60 * 60 ) ) {
- $print = strftime( Pubwich::_('%e %B at %H:%M'), $original );
- return $print;
- }
+ $timechunks = array(
+ array(60, 60,'1 second ago', '%d seconds ago'),
+ array(60*60, 60, '1 minute ago', '%d minutes ago'),
+ array(24*60*60, 24, '1 hour ago', '%d hours ago'),
+ array(7*24*60*60, 7, '1 day ago', '%d days ago'),
+ );
- for ( $i = 0, $j = count( $chunks ); $i < $j; $i++ ) {
- $seconds = $chunks[$i][0];
- $name = $chunks[$i][1];
- if ( ( $count = floor( $since / $seconds ) ) != 0 ) {
- break;
+ for ( $i = 0, $j = count( $timechunks ); $i < $j; $i++ ) {
+ $seconds = $timechunks[$i][0];
+ $string_single = $timechunks[$i][2];
+ $string_plural = $timechunks[$i][3];
+ if ( $since < $seconds) {
+ $count = floor( $since / ($seconds/$timechunks[$i][1]));
+ return sprintf( Pubwich::_($string_single, $string_plural, $count), $count );
}
}
- $suffixe = "s";
- $print = ( $count == 1 ) ? '1&nbsp;'.$name : $count.'&nbsp;'.$name.$suffixe;
-
- return sprintf( Pubwich::_('%s ago'), $print );
-
}
/**

0 comments on commit 27d029f

Please sign in to comment.