@hejdoktor/resx-compiler
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

resx-compiler

Compiles a resx file into typescript.

The compiled file will expose the available translations, so that the typescript compiler can help enforce valid usage.

Usage

Note that for server-side this should be added as a regular dependency, since it exposes a format function that the compiled translation files will import. For a client-side bundle, it does not matter, as long as the dependency is available at build-time.

Files can be generated using npx resx-compiler <source folder>. The code will detect all .resx files and generate a sibling .resx.ts file with the content.

This content can then be accessed via import { R } from "foo.resx". The R object have all the translations on it, via R.someTranslation.

Unusual translation names

If a translation name contains . or -, the translation will be added with the original name, but it will also follow the convention of the C# resx compiler and replace the character with _. This means that foo.bar-baz can be accessed both as R["foo.bar-baz"] and R.foo_bar_baz

Replacement strings

If the translation contains replacement points, a format-function that follows the same rules as C#'s string.Format() is exposed along with the resources: import { R, format } from "foo.resx". It can also be fetched from the library directly: import { format } from "@hejdoktor/resx-compiler".

For a translation <data name="foo"><value>Some {0} value {1}</value></data>, it can be used like so: format(R.foo, "bar", "baz").

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i @hejdoktor/resx-compiler

    Weekly Downloads

    6

    Version

    0.1.1

    License

    ISC

    Unpacked Size

    7.42 kB

    Total Files

    7

    Last publish

    Collaborators

    • fizker