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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@abradley2/elm-i18next-gen

v2.0.2

Published

An elm-codegen library for creating type-safe helper methods for the excellent ChristophP/elm-i18next package.

Downloads

39

Readme

Elm I18Next Code Generation

An elm-codegen library for creating type-safe helper methods for the excellent ChristophP/elm-i18next package.

If you have a large Elm application in a business setting, you should strongly consider supporting internationalization even if you aren't considering adding extra languages to your app. Your project manager who would much rather change a line in a JSON file than put another 1-point ticket into your sprint will thank you for it.

Elm Codegen Usage

In your project that consumes the generated code, you should elm install ChristophP/elm-i18next. This library generates code for usage with ChristophP/elm-i18next.

npx @abradley2/elm-i18next-gen --output=generated --translations=relative/path/to/translations.json

This will create a directory "generated" containing a Language.elm file and a Translations.elm file, along with Translations sub modules based on the structure of your translations file.

A translations file like should look something like this, conforming to the I18Next V2 specification:

{
   "general greeting": "Hello there",
   "personal greeting": "Hello {{name}}"
}

This will generate the following:

generalGreeting : List I18Next.Translations -> String
generalGreeting translations =
    I18Next.tf translations "generalGreeting"


personalGreeting : List I18Next.Translations -> { name : String } -> String
personalGreeting translations replacements =
    I18Next.trf
        translations
        I18Next.Curly
        "personalGreeting"
        [ ( "name", replacements.name ) ]

-and a default implementation of I18Next.Translations in the sibling Language.elm module.

defaultLanguage : I18Next.Translations
defaultLanguage =
    I18Next.fromTree
         [ ( ""
           , I18Next.object 
                [ ( "generalGreeting", I18Next.string "Hello there" ) 
                , ( "personalGreeting", I18Next.string "Hello {{name}}" )
                ]
           )
         ]

You can also nest translations by page as the I18Next V2 specification allows.

{
   "home": { ... },
   "login": { ... }
}

This will create the sub-modules in the Translations directory.

Recommended Pattern

It is recommended that you only run this codegen for a single default language. Part of the output includes a defaultLanguage export of the I18Next.Translations type. For all your translations that are not part of your default language, use I18Next.translationsDecoder as you normally would.

Thanks

This library is largely based upon the work done by Yoni Gibbs on elm-i8next-gen