npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@unitex/fluent-compiler

v1.0.3

Published

Compiler from TypeScript to Fluent Translation List (FTL)

Readme

UNITEX Fluent Compiler

Compiler from TypeScript to Fluent Translation List (FTL)

Usage

  1. Define your message lists in default locale:

    import {
      type FluentMessageList,
      defineFluentMessage as dm,
      defineFluentMessageListWithPrefix,
    } from '@unitex/fluent-compiler';
    
    // Message list can be a simple dictionary of strings
    
    const messagesEn = {
      hello: 'Hello World!',
      welcome: 'Welcome, {$user}!',
      unreadEmails: dm('{$unreadEmails:plural}', {
        $unreadEmails: {
          variants: {
            other: 'You have {$} unread emails.', // default
            one: 'You have one unread email.',
          },
        },
      }),
    } as const satisfies FluentMessageList;
    
    // Or can have a prefix to make navigation easier
    
    const exampleNamespace = 'example_';
    const namespacedMessagesEn = defineFluentMessageListWithPrefix(
      {
        'hello': 'Hello Namespace!',
        '-brand-name': 'My Brand',
        'welcome': `Welcome to {${exampleNamespace}-brand-name}.`,
        'your-rank': dm('{$pos:number}', {
          $pos: {
            params: { type: 'cardinal' },
            variants: {
              1: 'You finished first!',
              one: 'You finished {$}st',
              two: 'You finished {$}nd',
              few: 'You finished {$}rd',
              other: 'You finished {$}th',
            },
            defaultVariant: 'other',
          },
        }),
      } as const satisfies FluentMessageList,
      exampleNamespace,
    );
  2. Define message lists in the translation locale:

    import type { FluentMessageListBasedOn } from '@unitex/fluent-compiler';
    
    const messagesRu = castToReadonly({
      hello: 'Привет мир!',
      welcome: 'Добро пожаловать, {$user}!',
      unreadEmails: dm('{$unreadEmails:plural}', {
        $unreadEmails: {
          variants: {
            other: 'У вас {$} непрочитанных сообщений.', // default
            one: 'У вас одно непрочитанное сообщение.',
          },
        },
      }),
    } as const satisfies FluentMessageListBasedOn<typeof messagesEn>);
  3. To enable autocompletion you need to provide a message schema by redeclaring FluentProvidedSchema interface with your defined message lists (only in default locale):

    declare module '@unitex/fluent-compiler/fluent_schema' {
      type CustomMessages = typeof messagesEn & typeof namespacedMessagesEn;
      interface FluentProvidedSchema extends CustomMessages {}
    }
  4. Compile message lists into .ftl translation files:

    import { compile } from '@unitex/fluent-compiler';
    
    const compiledMessagesEn = compile(messagesEn);
    fs.writeFileSync('locales/en/messages.ftl', compiledMessagesEn);
  5. Use FluentReader to get translated messages (it provides simple barebone functionality):

    // in the Node environment
    import { FluentReaderBack } from '@unitex/fluent-compiler/back/fluent_reader_back';
    
    // or in the Browser environment
    import { FluentReaderFront } from '@unitex/fluent-compiler/front/fluent_reader_front';
    
    const reader = new FluentReaderBack({
      currentLocaleCode: 'en-GB',
      defaultLocaleCode: 'en-GB',
      fallbackLocaleCodes: ['en-US']
      supportedLocaleCodes: new Set(['en-GB', 'en-US', 'ru']),
      translations: new Map([
        ['en-GB', ['locales/en-GB/messages.ftl', 'locales/en-GB/namespaced_messages.ftl']],
        ['en-US', ['locales/en-US/messages.ftl', 'locales/en-US/namespaced_messages.ftl']],
        ['ru',    ['locales/ru/messages.ftl',    'locales/ru/namespaced_messages.ftl']],
      ]),
    });
    
    reader.getLocalizedString('welcome', { user: 'John Smith' });
    
    reader.setCurrentLocaleCode('ru');
    reader.setFallbackLocaleCodes(undefined);
    
    reader.getLocalizedString('welcome', { user: 'Иван Кузнецов' });
  6. Optional: write your own t function inspired by FluentReader. See implementation in the src/fluent_reader.ts file

  7. Optional: take a look at more example messages at example/messages.ts file

  8. Optional: learn more about Project Fluent

Code of Conduct

Read Here

Contributing

Read Here

Contributors

Read Here

Maintainers

Read Here

Credits

Inspired by WebDevSimplified intl-crash-course

Copyright

Read Here

Third-Party Licenses

Read Here

License

Read Here

Copying

Read Here

Repos / Mirrors