Skip to content

Commit 08518d0

Browse files
committed
refactor: migrate from pofile to pofile-ts
- Replace pofile dependency with pofile-ts ^2.1.0 - Use exported types (Item, Headers) instead of manual definitions - Adapt translationIO.ts to use Promise-based po.save() API - Add pofile-ts to Jest transformIgnorePatterns for ESM support - Add .lingui/ to .gitignore (test cache artifacts) pofile-ts is a modernized fork with TypeScript support, zero dependencies, and Promise-based async methods.
1 parent fe98678 commit 08518d0

File tree

9 files changed

+24
-30
lines changed

9 files changed

+24
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ junit.xml
2222
!.yarn/releases
2323
!.yarn/sdks
2424
!.yarn/versions
25+
.lingui/

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const tsConfigPathMapping = pathsToModuleNameMapper(
99
)
1010

1111
const testMatch = ["**/?(*.)test.(js|ts|tsx)", "**/test/index.(js|ts|tsx)"]
12-
const transformIgnorePatterns = ["node_modules/(?!@messageformat)"]
12+
const transformIgnorePatterns = ["node_modules/(?!@messageformat|pofile-ts)"]
1313
/**
1414
* @type {import('jest').Config}
1515
*/

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"normalize-path": "^3.0.0",
8181
"ora": "^5.1.0",
8282
"picocolors": "^1.1.1",
83-
"pofile": "^1.1.4",
83+
"pofile-ts": "^2.1.0",
8484
"pseudolocale": "^2.0.0",
8585
"source-map": "^0.7.6",
8686
"threads": "^1.7.0"

packages/cli/src/services/translationIO.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import fs from "fs"
22
import { dirname } from "path"
3-
import PO from "pofile"
3+
import PO, { Item as POItem, type Headers as POHeaders } from "pofile-ts"
44
import https from "https"
55
import { globSync } from "glob"
66
import { format as formatDate } from "date-fns"
77
import { LinguiConfigNormalized } from "@lingui/conf"
88
import { CliExtractOptions } from "../lingui-extract"
99

10-
type POItem = InstanceType<typeof PO.Item>
11-
1210
type TranslationIoSegment = {
1311
type: string
1412
source: string
@@ -26,7 +24,7 @@ type TranslationIoProject = {
2624
const EXPLICIT_ID_FLAG = "js-lingui-explicit-id"
2725
const EXPLICIT_ID_AND_CONTEXT_FLAG = "js-lingui-explicit-id-and-context"
2826

29-
const getCreateHeaders = (language: string) => ({
27+
const getCreateHeaders = (language: string): Partial<POHeaders> => ({
3028
"POT-Creation-Date": formatDate(new Date(), "yyyy-MM-dd HH:mmxxxx"),
3129
"MIME-Version": "1.0",
3230
"Content-Type": "text/plain; charset=utf-8",
@@ -354,15 +352,14 @@ function saveSegmentsToTargetPos(
354352
})
355353

356354
// Check that localePath directory exists and save PO file
357-
fs.promises.mkdir(dirname(localePath), { recursive: true }).then(() => {
358-
po.save(localePath, (err) => {
359-
if (err) {
360-
console.error("Error while saving target PO files:")
361-
console.error(err)
362-
process.exit(1)
363-
}
355+
fs.promises
356+
.mkdir(dirname(localePath), { recursive: true })
357+
.then(() => po.save(localePath))
358+
.catch((err) => {
359+
console.error("Error while saving target PO files:")
360+
console.error(err)
361+
process.exit(1)
364362
})
365-
})
366363
})
367364
}
368365

packages/format-po-gettext/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"cldr-core": "^45.0.0",
5151
"node-gettext": "^3.0.0",
5252
"plurals-cldr": "^2.0.1",
53-
"pofile": "^1.1.4"
53+
"pofile-ts": "^2.1.0"
5454
},
5555
"devDependencies": {
5656
"@lingui/jest-mocks": "workspace:^",

packages/format-po-gettext/src/po-gettext.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { parse as parseIcu, Select, SelectCase } from "@messageformat/parser"
22
import pluralsCldr from "plurals-cldr"
3-
import PO from "pofile"
3+
import PO, { Item as POItem } from "pofile-ts"
44
import gettextPlurals from "node-gettext/lib/plurals"
55

66
import type { CatalogFormatter, CatalogType, MessageType } from "@lingui/conf"
@@ -9,8 +9,6 @@ import { formatter as poFormatter } from "@lingui/format-po"
99
import type { PoFormatterOptions } from "@lingui/format-po"
1010
import { getCldrPluralSamples } from "./plural-samples"
1111

12-
type POItem = InstanceType<typeof PO.Item>
13-
1412
export type PoGettextFormatterOptions = PoFormatterOptions & {
1513
disableSelectWarning?: boolean
1614
customICUPrefix?: string

packages/format-po/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@lingui/conf": "5.6.1",
4747
"@lingui/message-utils": "5.6.1",
4848
"date-fns": "^3.6.0",
49-
"pofile": "^1.1.4"
49+
"pofile-ts": "^2.1.0"
5050
},
5151
"devDependencies": {
5252
"@lingui/jest-mocks": "workspace:^",

packages/format-po/src/po.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { format as formatDate } from "date-fns"
2-
import PO from "pofile"
2+
import PO, { Item as POItem, type Headers as POHeaders } from "pofile-ts"
33

44
import { CatalogFormatter, CatalogType, MessageType } from "@lingui/conf"
55
import { generateMessageId } from "@lingui/message-utils/generateMessageId"
66
import { normalizePlaceholderValue } from "./utils"
77

8-
type POItem = InstanceType<typeof PO.Item>
9-
108
const splitOrigin = (origin: string) => {
119
const [file, line] = origin.split(":")
1210
return [file, line ? Number(line) : null] as [file: string, line: number]
@@ -110,7 +108,7 @@ function isGeneratedId(id: string, message: MessageType): boolean {
110108
function getCreateHeaders(
111109
language: string,
112110
customHeaderAttributes: PoFormatterOptions["customHeaderAttributes"]
113-
): PO["headers"] {
111+
): Partial<POHeaders> {
114112
return {
115113
"POT-Creation-Date": formatDate(new Date(), "yyyy-MM-dd HH:mmxxxx"),
116114
"MIME-Version": "1.0",

yarn.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,7 +3029,7 @@ __metadata:
30293029
normalize-path: ^3.0.0
30303030
ora: ^5.1.0
30313031
picocolors: ^1.1.1
3032-
pofile: ^1.1.4
3032+
pofile-ts: ^2.1.0
30333033
pseudolocale: ^2.0.0
30343034
source-map: ^0.7.6
30353035
threads: ^1.7.0
@@ -3135,7 +3135,7 @@ __metadata:
31353135
mockdate: ^3.0.5
31363136
node-gettext: ^3.0.0
31373137
plurals-cldr: ^2.0.1
3138-
pofile: ^1.1.4
3138+
pofile-ts: ^2.1.0
31393139
unbuild: 2.0.0
31403140
languageName: unknown
31413141
linkType: soft
@@ -3149,7 +3149,7 @@ __metadata:
31493149
"@lingui/message-utils": 5.6.1
31503150
date-fns: ^3.6.0
31513151
mockdate: ^3.0.5
3152-
pofile: ^1.1.4
3152+
pofile-ts: ^2.1.0
31533153
unbuild: 2.0.0
31543154
languageName: unknown
31553155
linkType: soft
@@ -13769,10 +13769,10 @@ __metadata:
1376913769
languageName: node
1377013770
linkType: hard
1377113771

13772-
"pofile@npm:^1.1.4":
13773-
version: 1.1.4
13774-
resolution: "pofile@npm:1.1.4"
13775-
checksum: 7ef428d2793fcbcf021e4250d36043374ffbd7c8e15268977fae2361536abb894e97ee58525b2c1eeda5688a2b14b274657a271e08816059b12d8c02ac99fde0
13772+
"pofile-ts@npm:^2.1.0":
13773+
version: 2.1.0
13774+
resolution: "pofile-ts@npm:2.1.0"
13775+
checksum: 7e0a366177df5cca95a52111cc3353a46609f9c19b5971060b961a214ecdaf17a854b9025d623a77429617d2f29b702e3bebba07a6d1785ed41115da4c6e1be8
1377613776
languageName: node
1377713777
linkType: hard
1377813778

0 commit comments

Comments
 (0)