@@ -101,6 +101,10 @@ angular.module('gettext').factory('gettextCatalog', ["gettextPlurals", "$http",
101101 } ,
102102
103103 getPlural : function ( n , string , stringPlural , scope , context ) {
104+ if ( ! n && n !== 0 ) {
105+ return this . getString ( string , scope , context ) ;
106+ }
107+
104108 var form = gettextPlurals ( this . currentLanguage , n ) ;
105109 string = this . getStringForm ( string , form , context ) || prefixDebug ( n === 1 ? string : stringPlural ) ;
106110 if ( scope ) {
@@ -206,13 +210,62 @@ angular.module('gettext').directive('translate', ["gettextCatalog", "$parse", "$
206210 } ;
207211} ] ) ;
208212
209- angular . module ( 'gettext' ) . filter ( 'translate' , [ "gettextCatalog" , function ( gettextCatalog ) {
210- function filter ( input , context ) {
211- return gettextCatalog . getString ( input , null , context ) ;
212- }
213- filter . $stateful = true ;
214- return filter ;
215- } ] ) ;
213+ ( function ( ) {
214+ var translate = function ( gettextCatalog , $gettext ) {
215+ var message = gettextCatalog . getPlural ( $gettext . n , $gettext . msgid , $gettext . plural , null , $gettext . context ) ;
216+ if ( $gettext . n || $gettext . n === 0 ) {
217+ // replace $count with n, preserving leading whitespace
218+ return message . replace ( / ( ^ | \s ) \$ c o u n t \b / g, '$1' + $gettext . n ) ;
219+ } else {
220+ return message ;
221+ }
222+ } ;
223+
224+ angular . module ( 'gettext' ) . filter ( 'translate' , [ "gettextCatalog" , function ( gettextCatalog ) {
225+ function filter ( msgid ) {
226+ var $gettext = msgid . $gettext || { msgid : msgid } ;
227+
228+ // translate is the only filter that returns a string primitive
229+ return translate ( gettextCatalog , $gettext ) ;
230+ }
231+ filter . $stateful = true ;
232+ return filter ;
233+ } ] ) ;
234+
235+ angular . module ( 'gettext' ) . filter ( 'translatePlural' , [ "gettextCatalog" , function ( gettextCatalog ) {
236+ function filter ( msgid , n , plural ) {
237+ var $gettext = msgid . $gettext || { msgid : msgid } ;
238+ $gettext . n = n ;
239+ $gettext . plural = plural ;
240+
241+ /*jshint -W053 */
242+ // might as well return the correct String, even if it is a wrapper type
243+ var message = new String ( translate ( gettextCatalog , $gettext ) ) ;
244+ /*jshint +W053 */
245+
246+ message . $gettext = $gettext ;
247+ return message ;
248+ }
249+ filter . $stateful = true ;
250+ return filter ;
251+ } ] ) ;
252+
253+ angular . module ( 'gettext' ) . filter ( 'translateContext' , [ "gettextCatalog" , function ( gettextCatalog ) {
254+ function filter ( msgid , context ) {
255+ var $gettext = msgid . $gettext || { msgid : msgid } ;
256+ $gettext . context = context ;
257+
258+ /*jshint -W053 */
259+ var message = new String ( translate ( gettextCatalog , $gettext ) ) ;
260+ /*jshint +W053 */
261+
262+ message . $gettext = $gettext ;
263+ return message ;
264+ }
265+ filter . $stateful = true ;
266+ return filter ;
267+ } ] ) ;
268+ } ) ( ) ;
216269
217270// Do not edit this file, it is autogenerated using genplurals.py!
218271angular . module ( "gettext" ) . factory ( "gettextPlurals" , function ( ) {
0 commit comments