Repository: lingui/js-lingui
Pull request #903 (2020-12-06 21:24:17)

fix: accept pseudolocalization in SelectOrdinal
It correctly pseudolocalize SelectOrdinal. I have also tried to fix Select
```
<Select value={gender} male="His book" female="Her book" other="Their book" />
```

After extraction the message is:

```
{gender, select, other {Their book}}
```

It looks to me like a bug. I would expect `male` and `female` to be in the message as well.



vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: [https://vercel.com/lingui-js/js-lingui/c6pdnq45y](https://vercel.com/lingui-js/js-lingui/c6pdnq45y)  
✅ Preview: *In Progress*


codecov[bot]: # [Codecov](https://codecov.io/gh/lingui/js-lingui/pull/903?src=pr&el=h1) Report
> Merging [#903](https://codecov.io/gh/lingui/js-lingui/pull/903?src=pr&el=desc) (8fb093e) into [main](https://codecov.io/gh/lingui/js-lingui/commit/fc8c628e05522167c5ad76e2cb8c6161be95b8b4?el=desc) (fc8c628) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/lingui/js-lingui/pull/903/graphs/tree.svg?width=650&height=150&src=pr&token=CuJ1VD5BY5)](https://codecov.io/gh/lingui/js-lingui/pull/903?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##             main     #903   +/-   ##
=======================================
  Coverage   82.89%   82.89%           
=======================================
  Files          51       51           
  Lines        1450     1450           
  Branches      400      400           
=======================================
  Hits         1202     1202           
  Misses        146      146           
  Partials      102      102           
```


| [Impacted Files](https://codecov.io/gh/lingui/js-lingui/pull/903?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [packages/cli/src/api/pseudoLocalize.ts](https://codecov.io/gh/lingui/js-lingui/pull/903/diff?src=pr&el=tree#diff-cGFja2FnZXMvY2xpL3NyYy9hcGkvcHNldWRvTG9jYWxpemUudHM=) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/lingui/js-lingui/pull/903?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/lingui/js-lingui/pull/903?src=pr&el=footer). Last update [fc8c628...8fb093e](https://codecov.io/gh/lingui/js-lingui/pull/903?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

semoal: Hmm has sense to me after the clarification of Tom in your last issues! Thanks
MartinCerny-awin: Should I open bug for Select?
semoal: Na, not required, we already spoke about this in other issues. 

Patch:
diff --git a/packages/cli/src/api/pseudoLocalize.ts b/packages/cli/src/api/pseudoLocalize.ts
index 098bc429..1bfe15f7 100644
--- a/packages/cli/src/api/pseudoLocalize.ts
+++ b/packages/cli/src/api/pseudoLocalize.ts
@@ -16,9 +16,9 @@ Example: https://regex101.com/r/bDHD9z/3
 const HTMLRegex = /<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/g
 /*
 Regex should match js-lingui plurals
-Example: https://regex101.com/r/utnbQw/3
+Example: https://regex101.com/r/utnbQw/4
 */
-const PluralRegex = /({\w*,\s*plural,(.|\n)*?{)|(}\s*(offset|zero|one|two|few|many|other)\s*{)/g
+const PluralRegex = /({\w*,\s*(plural|selectordinal),(.|\n)*?{)|(}\s*(offset|zero|one|two|few|many|other)\s*{)/g
 /*
 Regex should match js-lingui variables
 Example: https://regex101.com/r/dw1QHb/2


Test patch:
diff --git a/packages/cli/src/api/pseudoLocalize.test.ts b/packages/cli/src/api/pseudoLocalize.test.ts
index 6108606f..2c9bf99c 100644
--- a/packages/cli/src/api/pseudoLocalize.test.ts
+++ b/packages/cli/src/api/pseudoLocalize.test.ts
@@ -68,6 +68,16 @@ describe("PseudoLocalization", () => {
     })
   })
 
+  it("SelectOrdinal", () => {
+    expect(
+      pseudoLocalize(
+        "{count, selectordinal, offset:1 one {1st} two {2nd} few {3rd} =4 {4th} many {testMany} other {#th}}"
+      )
+    ).toEqual(
+      "{count, selectordinal, offset:1 one {1śţ} two {2ńď} few {3ŕď} =4 {4ţĥ} many {ţēśţMàńŷ} other {#ţĥ}}"
+    )
+  })
+
   it("should not pseudolocalize variables", () => {
     expect(pseudoLocalize("replace {count}")).toEqual("ŕēƥĺàćē {count}")
     expect(pseudoLocalize("replace { count }")).toEqual("ŕēƥĺàćē { count }")