
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
simple-translation
Advanced tools
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
For those who want to support multiple languages without a lot of complication, dependancies or ties to a framework.
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 string dynamically.
For dynamic strings it will take a list of variables and return a templated string.
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 is will default to the english translation file. Therefore an english translation file is required at a minimum.
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)
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)
translate.message('exampleString')
returns: Example string
translate.message('exampleFunction')('test')
returns: Example function that returns a string plus a variable of test
translate.message('exampleString', 'fr')
returns: Exemple de chaîne
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"]
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}`, }, }
author: Richard Bettridge (ssshake)
web: http://daggasoft.com
twitter: @richbettridge
FAQs
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
The npm package simple-translation receives a total of 1 weekly downloads. As such, simple-translation popularity was classified as not popular.
We found that simple-translation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.