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

simple-translation

v1.0.9

Published

A super basic and simple way to do language translations. Auto detects language from the browser. Supports compiled strings. Aims to be an uncomplicated translation package

Downloads

4

Readme

Simple-Translations

For those who want to support multiple languages without a lot of complication, dependancies or ties to a framework.

Features

  • Automatically detects and uses the browser's language settings by default
  • Falls back to default language if there is no translation file for the user's language
  • Easily override default language
  • Supports static and dynamic strings (can pass variables into text)
  • Basic error handling
  • Minimal, you should be able to fork it and modify it without much investment

Structure of a language file


export default {
  language: "english",
  languageCode: "en",
  messages: {
    exampleString: "Example string",
    exampleFunction: variable => `Example function that returns a string plus a variable of ${variable}`,
  },
}

Simply populate your translations in the messages object seen in the example above and save the file somewhere in your project, such as in ./translations/english.js

  • language: A human readable word for the language
  • languageCode: The IOS 639-1 code for a language (see: https://www.w3schools.com/tags/ref_language_codes.asp)
  • messages: An object contain key:value pairs of the string to translate

Messages can either be a string or a function so that you can generate strings dynamically.

For dynamic strings it will take a list of variables and return a templated string.

Usage

see ./examples/index.html

The example file shows various uses and error handling.

The translations will default to user's browser's language. If there is no translation file for that language it will default to the english translation file. Therefore an english (or other default) translation file is required at a minimum.

Getting Started

  • import the simple-translation.js file
  • import your supplied translation files
  • register each language
  • call the message() method to get a translated string
    import SimpleTranslation from '../simple-translation.js'

    import english from '../languages/english.js'
    import french from '../languages/french.js'

    let translate = new SimpleTranslate()

    translate.registerLanguage(english)
    translate.registerLanguage(french)

Registering language files

Option A - specify each language file individually using the registerLanguage() method

translate.registerLanguage(english)

Option B - specify the language files upon new translate, which will be automatically registered

let translate = new SimpleTranslation(english, french)

Render a static translation

translate.message('exampleString')

returns: Example string

Render a dynamic translation

translate.message('exampleFunction')('test')

returns: Example function that returns a string plus a variable of test

Override auto-detected language with optional argument

translate.message('exampleString', 'fr')

returns: Exemple de chaîne

Additional Helper Methods

Change the default language

This package sets 'en' as the default / fallback language. If you wanted to use a different default language you can simply modify the property after instantiating simple-translation.

translate.defaultLanguage = 'de'

from the top...


import SimpleTranslation from '../simple-translation.js'

import german from '../languages/german.js'
import french from '../languages/french.js'

let translate = new SimpleTranslate(german, french)

translate.defaultLanguage = 'de'

Get list of supported Languages

This method would be handy if you want to, for example, render a drop down list of supported languages in your app and then allow the user to choose which language to display.

translate.getSupportedLanguages()

returns: ["en", "fr"]

Is A Language Supported?

This method is used internally to see if the user's default language matches any of the registered language files.

translate.isLanguageSupported('en')

returns: true / false

Get entire language object

translate.getLocale('en')

returns: { language: "english", languageCode: "en", messages: { exampleString: "Example string", exampleFunction: variable => `Example function that returns a string plus a variable of ${variable}`, }, }

Tests

No tests have been written yet but the obvious first one is a test which you would include in your build process to ensure that for each language they all have the same keys. A likely bug to enter production would be missing translations for a given language file.


author: Richard Bettridge (ssshake)

web: http://daggasoft.com

twitter: @richbettridge