Skip to content

Commit 4f3bfff

Browse files
committed
Ep86 - Localization - Pluralization
1 parent 43605ef commit 4f3bfff

File tree

7 files changed

+79
-0
lines changed

7 files changed

+79
-0
lines changed

_posts/2022-12-24-new-app-checklist.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ The idea of this post is to provide a list of things I like to have in-place whe
7575
- [TapShrink / LongPressShrink](/2023-10-22-shrink-modifiers/)
7676
- [Image Picker](/2024-01-30-image-picker-modifier/)
7777
- [Localization](/2022-12-27-new-app-localization/)
78+
- [Localization - Pluralization](/2025-04-29-ep86-localization-handling-plurals/)
7879
- Accessibility
7980
- [AdaptableStack](/2023-10-07-adaptable-stack/)
8081
- [Unit test helpers](/2023-02-02-new-app-testing-helpers/)

_posts/2022-12-27-new-app-localization.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,12 @@ Even though SwiftUI's Text automatically looks for the localized strings, I thin
5353
| - | - |
5454
| ![English]({{static.static_files}}/resources/ep14-new-app-localization/english.png) | ![Spanish]({{static.static_files}}/resources/ep14-new-app-localization/spanish.png) |
5555

56+
---
57+
58+
# Related Articles
59+
60+
- [Localization - Pluralization](/2025-04-29-ep86-localization-handling-plurals/)
61+
- [String Extensions](/2025-03-03-useful-string-extensions/)
62+
5663
<!-- Do not remove - SEO meta tags -->
5764
{% seo %}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
layout: post
3+
title: "Localization - Pluralizations"
4+
subtitle: "The easiest way to support plurals"
5+
date: 2025-04-29 07:00:00 -0300
6+
tags: [ios]
7+
thumbnail-img: "/resources/ep86-localization-handling-plurals/thumbnail.png"
8+
readtime: true
9+
---
10+
11+
The String Catalogs file have built-in support for pluralization.
12+
13+
[Official Apple Docs](https://developer.apple.com/documentation/xcode/localizing-and-varying-text-with-a-string-catalog)
14+
15+
#### Table of Contents
16+
- [String Catalogs](#string-catalogs)
17+
- [Handling Plurals](#handling-plurals)
18+
- [Usage](#usage)
19+
- [Related Articles](#related-articles)
20+
21+
# String Catalogs
22+
23+
Adding a String Catalog to your app is as simple as creating the file:
24+
25+
![string-catalog]({{static.static_files}}/resources/ep86-localization-handling-plurals/string-catalog.png)
26+
27+
For a detailed guide on how to add the `localizable` extension to `String`, read [this Localization article](/2022-12-27-new-app-localization/).
28+
29+
# Handling Plurals
30+
31+
Handling plurals has never been easier, the String Catalog has built-in support:
32+
33+
![vary-by-plural]({{static.static_files}}/resources/ep86-localization-handling-plurals/vary-by-plural.png)
34+
35+
![pluralization]({{static.static_files}}/resources/ep86-localization-handling-plurals/pluralization.png)
36+
37+
Forget about the `if/else` statements for good 🙌
38+
39+
## Usage
40+
41+
Using it is as straight forward as using the in-line components:
42+
43+
```swift
44+
@State private var itemCount = 0
45+
Text("\(itemCount) Books") // 0 Books, 1 Book, 2 Books
46+
```
47+
48+
Or, if you are using the String extensions from the [previous localization article](/2022-12-27-new-app-localization/):
49+
50+
```swift
51+
@State private var itemCount = 0
52+
Text("books".localized(with: [itemCount])) // 0 Books, 1 Book, 2 Books
53+
```
54+
55+
---
56+
57+
# Related Articles
58+
59+
- [New App - Localization](/2022-12-27-new-app-localization/)
60+
- [AdaptableStack](/2023-10-07-adaptable-stack/)
61+
- [Components](/2023-01-04-new-app-components/)
62+
- [Improve Build Times](/2023-08-18-improve-build-times-in-spm-packages-and-in-your-apps/)
63+
- [Xcode Templates](/2023-01-27-new-app-xcode-templates/)
64+
- [String Extensions](/2025-03-03-useful-string-extensions/)
65+
- [ViewStateController](/2023-03-04-view-state-controller/)
66+
- [ViewModifiers](/2023-01-03-new-app-view-modifiers/)
67+
68+
---
69+
70+
<!-- Do not remove - SEO meta tags -->
71+
{% seo %}
36 KB
Loading
123 KB
Loading
1.93 MB
Loading
86.9 KB
Loading

0 commit comments

Comments
 (0)