ttag-org / ttag

:orange_book: simple approach for javascript localization
https://ttag.js.org/
MIT License
338 stars 41 forks source link

Snowpack support #213

Open ljani opened 3 years ago

ljani commented 3 years ago

I'm a Lingui refugee (hi 👋🏻) looking for new home since they removed tagged templates support and I'm looking to localize my Snowpack application as soon as possible.

Here's some context from my Lingui ticket for Snowpack support:

Snowpack is an emerging [1,2] build tool for web frontends. It focuses on build performance by using esbuild and additionally by avoiding transpilation with babel. Thus, many Snowpack users try to avoid usage of babel in their development pipeline.

As lingui relies heavily on babel-plugin-macros, it would be nice to see an alternative, type-safe API without babel-plugin-macros to be used with for example Snowpack.

Thus, I started searching for a internalization localization library using tagged templates and found ttag. ttag seems to play nice with Snowpack, because of the po2json command. Here's an excerpt from my snowpack.config.cjs:

plugins: [
    [
        "@snowpack/plugin-build-script",
        {
            input: [".po"],
            output: [".json"],
            cmd: "ttag po2json $FILE --format compact",
        },
    ]
],
packageOptions: {
    namedExports: ["ttag"],
}

I mainly opened this ticket to share my Snowpack config, but I'd like you to consider creating a Snowpack plugin for ttag. I think po2json could be quite easily adapted into a Snowpack plugin.

I also noticed a few other points, should I open separate tickets for these?

Thank you for your work!

EDIT: I forgot that ttag didn't support ESM and needs namedExports

AlexMost commented 3 years ago

Hi @ljani ! Thanks for your feedback. Haven't tried snowpack before, looks like it's quite promising build tool, so ttag plugin will be useful. We have implemented something similar for the webpack - https://github.com/ttag-org/ttag-po-loader.

Good points about improving doc and typings. Going to create separate tickets for that!

Can you, please, explain more about the ESM support? Or to provide a link to some other package that already has it, so it can be taken as an example.

ljani commented 3 years ago

Hey! Good to hear you found it interesting and made some progress already!

Sure, I was a bit plain with ESM:

Hope this dump gave you at least something.