|
| 1 | +import { formatter as createFormatter } from "./xliff" |
| 2 | +import { CatalogType } from "@lingui/conf" |
| 3 | + |
| 4 | +describe("xliff format", () => { |
| 5 | + it("should write catalog in pofile format", async () => { |
| 6 | + const format = createFormatter({ origins: true }) |
| 7 | + |
| 8 | + const catalog: CatalogType = { |
| 9 | + static: { |
| 10 | + translation: "Static message", |
| 11 | + }, |
| 12 | + withOrigin: { |
| 13 | + translation: "Message with origin", |
| 14 | + origin: [["src/App.js", 4]], |
| 15 | + }, |
| 16 | + withContext: { |
| 17 | + translation: "Message with context", |
| 18 | + context: "my context", |
| 19 | + }, |
| 20 | + Dgzql1: { |
| 21 | + message: "with generated id", |
| 22 | + translation: "", |
| 23 | + context: "my context", |
| 24 | + }, |
| 25 | + withMultipleOrigins: { |
| 26 | + translation: "Message with multiple origin", |
| 27 | + origin: [ |
| 28 | + ["src/App.js", 4], |
| 29 | + ["src/Component.js", 2], |
| 30 | + ], |
| 31 | + }, |
| 32 | + withDescription: { |
| 33 | + translation: "Message with description", |
| 34 | + comments: ["Description is comment from developers to translators"], |
| 35 | + }, |
| 36 | + // obsolete: { |
| 37 | + // translation: "Obsolete message", |
| 38 | + // obsolete: true, |
| 39 | + // }, |
| 40 | + // withFlags: { |
| 41 | + // flags: ["fuzzy", "otherFlag"], |
| 42 | + // translation: "Keeps any flags that are defined", |
| 43 | + // }, |
| 44 | + veryLongString: { |
| 45 | + translation: |
| 46 | + "One morning, when Gregor Samsa woke from troubled dreams, he found himself" + |
| 47 | + " transformed in his bed into a horrible vermin. He lay on his armour-like" + |
| 48 | + " back, and if he lifted his head a little he could see his brown belly," + |
| 49 | + " slightly domed and divided by arches into stiff sections. The bedding was" + |
| 50 | + " hardly able to cover it and seemed ready to slide off any moment. His many" + |
| 51 | + " legs, pitifully thin compared with the size of the rest of him, waved about" + |
| 52 | + " helplessly as he looked. \"What's happened to me?\" he thought. It wasn't" + |
| 53 | + " a dream. His room, a proper human", |
| 54 | + }, |
| 55 | + |
| 56 | + stringWithPlaceholders: { |
| 57 | + message: "Hello {world}", |
| 58 | + translation: null, |
| 59 | + }, |
| 60 | + |
| 61 | + stringWithJsxPlaceholders: { |
| 62 | + message: "Hello <0>String</0>", |
| 63 | + translation: null, |
| 64 | + }, |
| 65 | + } |
| 66 | + |
| 67 | + const actual = format.serialize(catalog, { |
| 68 | + locale: "en", |
| 69 | + existing: null, |
| 70 | + }) |
| 71 | + expect(actual).toMatchSnapshot() |
| 72 | + }) |
| 73 | + |
| 74 | + it.todo( |
| 75 | + "should read catalog in xliff format" /*, () => { |
| 76 | + const format = createFormatter() |
| 77 | +
|
| 78 | + const pofile = fs |
| 79 | + .readFileSync(path.join(__dirname, "fixtures/messages.po")) |
| 80 | + .toString() |
| 81 | +
|
| 82 | + const actual = format.parse(pofile) |
| 83 | + expect(actual).toMatchSnapshot() |
| 84 | + }*/ |
| 85 | + ) |
| 86 | + |
| 87 | + it.todo("should preserve attributes stored on trans unit") |
| 88 | + it.todo("should preserve children in trans unit") |
| 89 | + |
| 90 | + it.todo("should not include origins if origins option is false") |
| 91 | + |
| 92 | + it.todo("should not include lineNumbers if lineNumbers option is false") |
| 93 | +}) |
0 commit comments