]> granicus.if.org Git - transmission/commitdiff
(trunk, web) replace Transmission.formatter.plural() with a slightly less brittle...
authorJordan Lee <jordan@transmissionbt.com>
Sun, 7 Oct 2012 18:10:26 +0000 (18:10 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sun, 7 Oct 2012 18:10:26 +0000 (18:10 +0000)
web/javascript/formatter.js
web/javascript/inspector.js
web/javascript/torrent-row.js
web/javascript/transmission.js

index c0be1f37bb80b9802c7df34835206185cbb0ee30..3faaeae84c7941d75a4f7feaec451a8bcabba92e 100644 (file)
@@ -268,9 +268,15 @@ Transmission.fmt = (function()
                        return [date, time, period].join(' ');
                },
 
-               plural: function(i, word)
+               ngettext: function(msgid, msgid_plural, n)
                {
-                       return [ i.toStringWithCommas(), ' ', word, (i==1?'':'s') ].join('');
+                       // TODO(i18n): http://doc.qt.digia.com/4.6/i18n-plural-rules.html
+                       return n === 1 ? msgid : msgid_plural;
+               },
+
+               countString: function(msgid, msgid_plural, n)
+               {
+                       return [ n.toStringWithCommas(), ngettext(msgid,msgid_plural,n) ].join(' ');
                },
 
                peerStatus: function( flagStr ) 
index f83f66131b27bc5fcefab4b00ad7e9b174c7bbd0..1f1955953675b9a10821c97c6a927caec7d2bfee 100644 (file)
@@ -670,7 +670,7 @@ function Inspector(controller) {
         if (tracker.hasAnnounced) {
             lastAnnounceTime = Transmission.fmt.timestamp(tracker.lastAnnounceTime);
             if (tracker.lastAnnounceSucceeded) {
-                lastAnnounce = [ lastAnnounceTime, ' (got ',  Transmission.fmt.plural(tracker.lastAnnouncePeerCount, 'peer'), ')' ];
+                lastAnnounce = [ lastAnnounceTime, ' (got ',  Transmission.fmt.countString('peer','peers',tracker.lastAnnouncePeerCount), ')' ];
             } else {
                 lastAnnounceLabel = 'Announce error';
                 lastAnnounce = [ (tracker.lastAnnounceResult ? (tracker.lastAnnounceResult + ' - ') : ''), lastAnnounceTime ];
index 9ac21aca74f883a2cf8fbe7d0256f7acb435c36a..40334a0b76506da14fd14f3785c53aed93e078ec 100644 (file)
@@ -167,15 +167,15 @@ TorrentRendererFull.prototype =
                                return [ 'Downloading from',
                                         t.getPeersSendingToUs(),
                                         'of',
-                                        fmt.plural (peer_count, 'peer'),
+                                        fmt.countString('peer','peers',peer_count),
                                         'and',
-                                        fmt.plural (webseed_count, 'web seed') ].join(' ');
+                                        fmt.countString('web seed','web seeds',webseed_count) ].join(' ');
                        }
                        else if (webseed_count)
                        {
                                // Downloading from 2 webseed(s)
                                return [ 'Downloading from',
-                                        fmt.plural (webseed_count, 'web seed') ].join(' ');
+                                        fmt.countString('web seed','web seeds',webseed_count) ].join(' ');
                        }
                        else
                        {
@@ -183,7 +183,7 @@ TorrentRendererFull.prototype =
                                return [ 'Downloading from',
                                         t.getPeersSendingToUs(),
                                         'of',
-                                        fmt.plural (peer_count, 'peer') ].join(' ');
+                                        fmt.countString('peer','peers',peer_count) ].join(' ');
                        }
                }
 
@@ -191,7 +191,7 @@ TorrentRendererFull.prototype =
                        return [ 'Seeding to',
                                 t.getPeersGettingFromUs(),
                                 'of',
-                                fmt.plural (t.getPeersConnected(), 'peer'),
+                                fmt.countString ('peer','peers',t.getPeersConnected()),
                                 '-',
                                 TorrentRendererHelper.formatUL(t) ].join(' ');
 
index 558663876ee1e53c98f96066562fabf5a0cc53a4..d741028aeb59aa9c3e3a2eba97546ac3e18af611 100644 (file)
@@ -1146,7 +1146,7 @@ Transmission.prototype =
                $('#speed-dn-label').text( fmt.speedBps( d ) );
 
                // visible torrents
-               $('#filter-count').text( fmt.plural(this._rows.length, 'Transfer') );
+               $('#filter-count').text( fmt.countString('Transfer','Transfers',this._rows.length ) );
        },
 
        setEnabled: function(key, flag)