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

language-translator

v1.2.6

Published

Language localization and text translation module for NodeJS Express framework

Downloads

33

Readme

language-translator

Text localization and translation module for NodeJS Express Framework.

Install

npm install language-translator --save

Load

var  languageTranslator = require('language-translator');
app.use(languageTranslator.init(
  {
    langs          : ["tr", "en", "fr", "de", "es"], // ... And other languages
    defaultLang    : "en",
    cookieName     : "lang",
    translate      : "true",
    translationApiKey: "{{your_yandex_translate_api_key}}"
}));

Configuration Parameters

langs

The module creates folders which takes an json array from configuration json. The array is required.

defaultLang

The module choose a language to choose a language folder as a default when cookie language is not be set. The defaultLang is required.

langDir

The module creates a root folder which takes its name from configuration json. The langDir is optional. Default value is language.

cookieName

The module creates a cookie to know user's language preference which requested before. Default cookie name is language.

equalizeKeys

The module offer an option to equalize keys of default language's json files with other languages. For example, you created a json file in default language folder but not in other language folders. When you restart node server, module creates all files and keys in other language folders for you. Default value is true. (Recommended)

translate

The module offer translate default language files to another language by using Yandex Translator API. Default value is true. (Recommended)

translationApiKey :

If you want translate all texts in default language folder's json files, you have to create API key in Yandex Developers Page. (https://translate.yandex.com/developers/keys) . It's free. This parameter is required if parameter translate is true.

Notice: If you use translation, you have to define items in langs array like below:

Supported Language List:

Usage

When your app started, firstly the module creates language folder in root directory. Then, it creates folders which names are in langs array. Then, it creates a json file which name is same as its folder name for common texts. And it creates a mapping.json file which is used to match route paths and language files.

For example:

langs : ["tr", "en"]

 your_app_folder
     -> language
	      -> tr
	        -> tr.json // It creates for common texts
		-> And your other language files...
	      -> en
		-> en.json // It creates for common texts
		-> And your other language files...

-- en.json file content:

{
	"example"           : "Example Text",
	"example_with_param": "Example %s"
}

On view file usage (Example for .ejs):

<%=  _lt.get('example')  %>

Formatted:

<%=  _lt.get(example_with_param, "Param value")  %>

--

On js file usage

 var _lt = res.locals._lt;
 _lt.load("home");
 console.log(_lt.get("example_with_param", "Param value"));

Example:

Your Application directory:

 your_app_folder
     -> language
	      -> tr
	        -> tr.json // It is used for common texts
		-> home.json
		-> about.json
		-> users.json
	      -> en
		-> en.json // It is used for common texts
		-> home.json
		-> about.json
		-> users.json   

Please STAR and WATCH the project! :)

References: “Medium.com - Nodejs text localization module” https://medium.com/@hkaraoglutr/nodejs-text-localization-module-687d3d285c3a