wallet-core/packages/pogen
Florian Dold f56a563533
build system: get rid of prepare scripts
These don't seem to be the right location to compile packages.
The newest version of pnpm runs all those scripts on "pnpm install",
even if we filter for only one package.  That results in a build
performance issue.
2023-06-06 15:25:53 +02:00
..
bin pogen: fix quoting of double quotes 2023-04-14 16:05:09 +02:00
example/proj1 pogen: fix quoting of double quotes 2023-04-14 16:05:09 +02:00
src pogen: fix quoting of double quotes 2023-04-14 16:05:09 +02:00
.gitignore fix pogen binary 2021-03-27 14:02:48 +01:00
package.json build system: get rid of prepare scripts 2023-06-06 15:25:53 +02:00
README.md clarify 2021-03-18 14:16:34 +01:00
tsconfig.json pogen: read files from tsconfig, import po2ts 2022-02-14 16:52:02 +01:00
yarn.lock get pogen via npm registry 2019-03-28 01:30:06 +01:00

pogen - string extraction for internationalizing TypeScript programs

The pogen tool extracts internationalizable strings from TypeScript programs.

Invocation and Configuration

The pogen tool must be called from the root of an NPM package.

The input files are determined from the tsconfig.json file at the root of the package. All input files inside the package that the compiler would use are automatically processed.

Further configuration options are specified in the package's package.json file. The following configuration options are supported:

{

  // [ ... ]

  "pogen": {
    // Output location of the pofile (mandatory)
    "pofile": "...",

    // Calls to plain i18n functions are extracted if they
    // are imported from this package.
    "plainI18nPackage": "@gnu-taler/taler-util",

    // Calls to react-style i18n functions are extracted if they
    // are imported from this package.
    "reactI18nPackage": "@gnu-taler/preact-i18n",
  }

}

Syntax

Two flavors of syntax are supported:

Template strings:

import { i18n } from "@gnu-taler/taler-util";

console.log(i18n.str`Hello World`);
console.log(i18n.str`Hello ${user}`);

console.log(i18n.plural(n, i18n.lazy`I have ${n} apple`, i18n.lazy`I have ${n} apples`));

React components:


import {
  Translate,
  TranslateSwitch,
  TranslateSingular,
  TranslatePlural
} from "@gnu-taler/preact-i18n";

<Translate>Hello, World</Translate>

// Placeholders are other React elements
<Translate>Hello, <span className="highlight">{userName}<span></Translate>

// Plain placeholders are not supported, they must be surrounded
// by an element:
// WRONG: <Translate>Hello, {userName}</Translate>

<TranslateSwitch n={numApples}>
  <TranslateSingular>I have <span>{n}</span> apple</TranslateSingular>
  <TranslatePlural>I have <span>{n}</span> apple</TranslatePlural>
</TranslateSwitch>