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 🙏

© 2025 – Pkg Stats / Ryan Hefner

i18n-json-to-elm

v1.3.1

Published

Generates Elm sources from i18n's JSONs.

Readme

i18n-json-to-elm

Generates Elm sources from i18n's JSONs.

Instructions

  • Download the JSON from POEditor, using "key - value" format.
  • Save it inside an i18n (configurable as "source") folder in your project's path.
  • Add .elm-i18n (configurable as "dest") to source-directories in your elm.json.

Configuration

Create a i18n.json with the following contents:

{
  "source": "i18n",
  "dest": ".elm-i18n",
  "namespace": "MyModuleName",
  "generateDecoders": true,
  "generateMockLanguage": true,
  "languages": ["English", "Spanish"],
  "emptyFallback": "English",
  "rootType": "Root"
}
  • "source" defaults to "i18n";
  • "dest" defaults to ".elm-i18n";
  • "namespace" defaults to "I18n";
  • "generateDecoders" defaults to false;
  • "generateMockLanguage" defaults to false.
  • "languages" defaults to [] (when empty, it'll search for ${source}/*.json instead);
  • "emptyFallback" defaults to null (when null, don't try falling back);
  • "rootType" defaults to "Root".

Optional features

  • "generateDecoders" generates a Decoders.elm with JSON decoders;
  • "generateMockLanguage" generates a MockLanguage.elm where the value of each terms reflects their own context.key.
  • "languages" chooses what files to transform; helps when using with "generateDecoders" for loading non-specified languages during runtime.
  • "emptyFallback" replaces empty translation terms (e.g.: "yes": "") with references for another language's translation.
  • "rootType" customize the type for the root entry of the langages (e.g: "Root" will generate English.root.someDialog.title).

Running

CLI

Just run npx i18n-json-to-elm.

Example

This is how a valid "i18n/English.json" would look like:

{
  "common": {
    "retry": "Retry",
    "loading": "Loading...",
    "username": "Username/Email",
    "password": "Password"
  },
  "dialogs": {
    "rename": {
      "title": "Renaming",
      "body": "From {{oldName}} to {{newName}}"
    }
  },
  "errors": {
    "httpFailure": "Network error.",
    "credInvalid": "Invalid credentials, please try again."
  }
}

This is how the resulting "src/I18n/Types.elm" will look like:

module I18n.Types exposing (..)


type alias Common =
    { retry : String
    , loading : String
    , username : String
    , password : String
    }


type alias DialogsRename =
    { title : String
    , body : { oldName : String, newName : String } -> String
    }


type alias Dialogs =
    { rename : DialogsRename
    }

type alias Errors =
    { httpFailure : String
    , credInvalid : String
    }


type alias Root =
    { common : Common
    , dialogs : Dialogs
    , errors : Errors
    }

This is how the resulting "src/I18n/English.elm will look like:

module I18n.Dummy exposing (..)

import I18n.Types exposing (..)


common : Common
common =
    { retry = "Retry"
    , loading = "Loading..."
    , username = "Username/Email"
    , password = "Password"
    }


dialogsRename : DialogsRename
dialogsRename =
    { title = "Renaming"
    , body = \{ oldName, newName } -> "From " ++ oldName ++ " to " ++ newName
    }


dialogs : Dialogs
dialogs =
    { rename = dialogsRename
    }

-- [...]

The src/I18n/MockLanguage.elm looks like this:

common : Types.Common
common =
    { retry = "common.retry"
    , loading = "common.loading"
    , username = "common.username"
    , password = "common.password"
    }

While the src/I18n/Decoders.elm will look like this:

type alias I18nTranslator =
    List ( String, String ) -> String -> String

common : I18nTranslator -> Types.Common -> Decoder Types.Common
common curlyTranslator fallback = -- [...]

dialogsRename : I18nTranslator -> Types.DialogsRename -> Decoder Types.DialogsRename
dialogsRename curlyTranslator fallback = -- [...]

dialogs : I18nTranslator -> Types.Dialogs -> Decoder Types.Dialogs
dialogs curlyTranslator fallback = -- [...]

errors : I18nTranslator -> Types.Dialogs -> Decoder Types.Dialogs
errors curlyTranslator fallback = -- [...]

root : I18nTranslator -> Types.Dialogs -> Decoder Types.Dialogs
root curlyTranslator fallback = -- [...]