{"id":1260,"date":"2023-07-31T05:00:00","date_gmt":"2023-07-31T12:00:00","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=1260"},"modified":"2023-07-28T15:15:35","modified_gmt":"2023-07-28T22:15:35","slug":"pluralizing-text-with-the-i18nplural-pipe","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/pluralizing-text-with-the-i18nplural-pipe\/","title":{"rendered":"Pluralizing text with the i18nPlural pipe"},"content":{"rendered":"\n<p>Pluralizing is as natural in human language as it is painful to handle programmatically. Let&#8217;s say we want to address the following scenarios in an app that displays the number of posts:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If we have zero, display &#8220;No post.&#8221;<\/li>\n\n\n\n<li>If we have one, display &#8220;1 post.&#8221;<\/li>\n\n\n\n<li>If we have more than one, say 5, display &#8220;5 posts.&#8221;<\/li>\n<\/ul>\n\n\n\n<p>We could use a combination of <code>ngIf \/ else<\/code> scenarios to handle this, but it would get ugly quickly. The <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/new-control-flow-rfc\/\" target=\"_blank\" rel=\"noopener\" title=\"\">upcoming control flow API<\/a> would help, but it&#8217;s not available yet.<\/p>\n\n\n\n<p>Instead, we can use the <a href=\"https:\/\/angular.io\/api\/common\/I18nPluralPipe\" target=\"_blank\" rel=\"noopener\" title=\"\"><code>i18nPlural<\/code> pipe<\/a> as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"165\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/07\/image-44-1024x165.png\" alt=\"\" class=\"wp-image-1261\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/07\/image-44-1024x165.png 1024w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/07\/image-44-300x48.png 300w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/07\/image-44-768x124.png 768w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/07\/image-44-1536x247.png 1536w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/07\/image-44.png 1714w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The above syntax determines what to display for each scenario: 0,1 or any other value. You can find an <a href=\"https:\/\/stackblitz.com\/edit\/stackblitz-starters-vhs3hp?file=src%2Fmain.ts\" target=\"_blank\" rel=\"noopener\" title=\"\">example here on Stackblitz<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pluralizing is as natural in human language as it is painful to handle programmatically. Let&#8217;s say we want to address the following scenarios in an app that displays the number of posts: We could use a combination of ngIf \/ else scenarios to handle this, but it would get ugly quickly. The upcoming control flow [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,14],"tags":[],"class_list":["post-1260","post","type-post","status-publish","format-standard","hentry","category-angular","category-pipes"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/comments?post=1260"}],"version-history":[{"count":2,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1260\/revisions"}],"predecessor-version":[{"id":1263,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1260\/revisions\/1263"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=1260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=1260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=1260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}