Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elm-i18n

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elm-i18n

Get your elm app translated and generate localized versions of your app

  • 0.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

i18n localization for Elm as a pre-build phase

Travis

This is a proof of concept to illustrate how to localize an elm app.

The concept is to copy (or symlink) a root module for a language from the language directory ./Translation/{Language} to ./src/Translation. Your code imports modules under ./src/Translation and does not know about languages.

The index.js script takes care of the copying/symlinking, clears the elm artefacts cache, and provides an interface to build a localized version of your app.

Installation:

npm install elm-i18n -g

Usage:

cd example && elm-i18n-switch --output out -l En

Tools

This repository provides a few tools to extract string functions and constants from modules containing translations (where one language can consist of multiple modules, but each module only contains one language).

The tool is build using node.js with an Elm-Core. To build the elm backend of the node.js part (if developing locally): make dist.

Export: Generate CSV from Elm source

elm-i18n-generator --root example/Translation --language De --export

Result:

Module,Key,Comment,Supported Placeholders,Translation
"Translation.Main","greeting","A short greeting.","","Hi"
"Translation.Main","greetingWithName","A personalized greeting. Use placeholder name for the user's name.","name","Guten Tag, {{name}}"

Import: Generate Elm source code from CSV

elm-i18n-generator -l De --import export.csv

Result in import/DE/Translation/Main.elm:

module Translation.Main exposing (..)

{-| -}


{-| A short greeting.
-}
greeting : String
greeting =
    "Hi"


{-| A personalized greeting. Use placeholder name for the user's name.
-}
greetingWithName : String -> String
greetingWithName name =
    "Guten Tag, "
        ++ name

Advantages

  • Each build of your app only contains one language.
  • No need to handle the current language in your elm app's model or view functions.
  • You can use any logic you like for the text snippets: constants, functions...
  • Allows you to create sub modules for parts of your app.
  • Full type safety
  • Auto completion (if you run the script at least once before starting the IDE).
  • For testing you can add a Translation Test and set your code base to use that before running tests. This way your tests do not change if you change the wording of your buttons, labels and fallbacks.
  • Compile-time errors for incomplete translations.
  • Compile-time errors are limited to the incomplete language, so you can continue shipping updates and fixes for the other languages.

Disadvantages

  • Language is no longer part of your view model and cannot be changed dynamically from within the app.
  • Language selection has to be handled outside of the elm-app (by loading the appropriate js artefact).

Keywords

FAQs

Package last updated on 27 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc