Skip to content

Commit beb0541

Browse files
authored
feat(loaders): po files (GNU gettext) (#496)
1 parent f428057 commit beb0541

4 files changed

Lines changed: 45 additions & 0 deletions

File tree

.changeset/silly-queens-tap.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@lingo.dev/_spec": patch
3+
"lingo.dev": patch
4+
---
5+
6+
po files

packages/cli/src/cli/loaders/index.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,42 @@ return array(
16361636

16371637
expect(fs.writeFile).toHaveBeenCalledWith("i18n/es.php", expectedOutput, { encoding: "utf-8", flag: "w" });
16381638
});
1639+
1640+
describe("po bucket loader", () => {
1641+
it("should load po file", async () => {
1642+
setupFileMocks();
1643+
1644+
const input = `msgid "Hello"\nmsgstr "Hello"`;
1645+
const expectedOutput = { "Hello/singular": "Hello" };
1646+
1647+
mockFileOperations(input);
1648+
1649+
const jsonLoader = createBucketLoader("po", "i18n/[locale].po");
1650+
jsonLoader.setDefaultLocale("en");
1651+
const data = await jsonLoader.pull("en");
1652+
1653+
expect(data).toEqual(expectedOutput);
1654+
});
1655+
1656+
it("should save po file", async () => {
1657+
setupFileMocks();
1658+
1659+
const input = `msgid "Hello"\nmsgstr "Hello"`;
1660+
const expectedOutput = `msgid "Hello"\nmsgstr "Hola"`;
1661+
1662+
mockFileOperations(input);
1663+
1664+
const jsonLoader = createBucketLoader("po", "i18n/[locale].po");
1665+
jsonLoader.setDefaultLocale("en");
1666+
await jsonLoader.pull("en");
1667+
1668+
await jsonLoader.push("es", {
1669+
"Hello/singular": "Hola",
1670+
});
1671+
1672+
expect(fs.writeFile).toHaveBeenCalledWith("i18n/es.po", expectedOutput, { encoding: "utf-8", flag: "w" });
1673+
});
1674+
});
16391675
});
16401676
});
16411677

packages/cli/src/cli/utils/find-locale-paths.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export default function findLocaleFiles(bucket: string) {
1818
return findLocaleFilesWithExtension(".md");
1919
case "php":
2020
return findLocaleFilesWithExtension(".php");
21+
case "po":
22+
return findLocaleFilesWithExtension(".po");
2123
case "xcode-xcstrings":
2224
return findLocaleFilesForFilename("Localizable.xcstrings");
2325
case "xcode-strings":

packages/spec/src/formats.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const bucketTypes = [
2121
"compiler",
2222
"vtt",
2323
"php",
24+
"po",
2425
] as const;
2526

2627
export const bucketTypeSchema = Z.enum(bucketTypes);

0 commit comments

Comments
 (0)