Skip to content

Commit

Permalink
rename to customICUPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
garikkh committed Oct 1, 2024
1 parent 907bc94 commit 9a29b80
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/format-po-gettext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

> **Warning**
> This formatter is made for compatibility with translation management systems, which do not support ICU expressions in PO files.
>
>
> It does not support all features of LinguiJS and should be carefully considered over other formats.
>
> Not supported features (native gettext doesn't support this):
Expand Down Expand Up @@ -82,7 +82,7 @@ export type PoGettextFormatterOptions = {
*
* @default "js-lingui:"
*/
customCtxPrefix?: string
customICUPrefix?: string
}
```
Expand Down
6 changes: 3 additions & 3 deletions packages/format-po-gettext/src/po-gettext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ msgstr[2] "# dní"
)

const defaultPrefix = createFormat()
const customPrefix = createFormat({ customCtxPrefix: "custom-prefix:" })
const customPrefix = createFormat({ customICUPrefix: "custom-prefix:" })

const defaultCatalog = defaultPrefix.parse(
defaultProfile,
Expand All @@ -259,7 +259,7 @@ msgstr[2] "# dní"
.toString()

const usingInvalidPrefix = createFormat({
customCtxPrefix: "invalid-prefix:",
customICUPrefix: "invalid-prefix:",
})
mockConsole((console) => {
const catalog = usingInvalidPrefix.parse(
Expand All @@ -277,7 +277,7 @@ msgstr[2] "# dní"
})

it("handles custom prefix", () => {
const format = createFormat({ customCtxPrefix: "custom-prefix:" })
const format = createFormat({ customICUPrefix: "custom-prefix:" })

const catalog: CatalogType = {
message_with_id: {
Expand Down
6 changes: 3 additions & 3 deletions packages/format-po-gettext/src/po-gettext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type POItem = InstanceType<typeof PO.Item>

export type PoGettextFormatterOptions = PoFormatterOptions & {
disableSelectWarning?: boolean
customCtxPrefix?: string
customICUPrefix?: string
}

// Attempts to turn a single tokenized ICU plural case back into a string.
Expand Down Expand Up @@ -53,7 +53,7 @@ function serializePlurals(
// Depending on whether custom ids are used by the developer, the (potential plural) "original", untranslated ICU
// message can be found in `message.message` or in the item's `key` itself.
const icuMessage = message.message
const ctxPrefix = options.customCtxPrefix || DEFAULT_CTX_PREFIX
const ctxPrefix = options.customICUPrefix || DEFAULT_CTX_PREFIX

if (!icuMessage) {
return item
Expand Down Expand Up @@ -269,7 +269,7 @@ export function formatter(
item,
pluralForms,
po.headers.Language,
options.customCtxPrefix
options.customICUPrefix
)
})

Expand Down
15 changes: 7 additions & 8 deletions website/docs/ref/catalog-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,29 +155,29 @@ export type PoGettextFormatterOptions = {
*
* @default true
*/
origins?: boolean
origins?: boolean;

/**
* Print line numbers in origins
*
* @default true
*/
lineNumbers?: boolean
lineNumbers?: boolean;

/**
* Disable warning about unsupported `Select` feature encountered in catalogs
*
* @default false
*/
disableSelectWarning?: boolean
disableSelectWarning?: boolean;

/**
* Overrides the default prefix for icu and plural comments in the final PO catalog.
*
* @default "js-lingui:"
*/
customCtxPrefix?: string
}
customICUPrefix?: string;
};
```

### Examples {#po-gettext-examples}
Expand Down Expand Up @@ -210,19 +210,18 @@ With this format, plural messages are exported in the following ways, depending

Note how `msgid` and `msgid_plural` were extracted from the original message.

- Message **with a custom comment prefix**.

Some TMS might modify the ICU comment by attempting to split lines to be 80 characters or less,
or have trouble reading lingui comments because of the `js-lingui:` prefix. To change the prefix,
set `customCtxPrefix` to modify the prefix for ICU comments.
set `customICUPrefix` to modify the prefix for ICU comments.

```po
# with default prefix
#. js-
#. lingui:icu=%7BanotherCount%2C+plural%2C+one+%7BSingular+case%7D+other+%7BCase+number+%7BanotherCount%7D%7D%7D&pluralize_on=anotherCount
# customCtxPrefix = jsi18n:
# customICUPrefix = jsi18n:
#. jsi18n:icu=%7BanotherCount%2C+plural%2C+one+%7BSingular+case%7D+other+%7BCase+number+%7BanotherCount%7D%7D%7D&pluralize_on=anotherCount
```

Expand Down

0 comments on commit 9a29b80

Please sign in to comment.