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

mlc-translate-server

v1.3.3

Published

expressjs API to store translations, make cache files. Made to be used with mlc-angularjs-translate.

Downloads

9

Readme

mlc-translate-server

mlc-translate-server is a minimal server which stores translations. It is designed to work with mlc-angularjs-translate.

How to use it

This server is supposed to be accessible only for admins/translators on your website.

This server is not designed to be accessible from any user. You should implement a proxy system from your website to cache the translations fetched via /query.

Example:

  • I assume your website consist of 2 projects admin and website
  • At each deployment you can use /query to download both translations
  • Store the translations in files, 1 translation file per locale per group per project. For example:
    • translations/admin/group1/locale1.json
    • translations/website/login/en_GB.json
    • translations/website/login/fr_FR.json
    • translations/website/signup/en_GB.json
  • Store the timestamps in translations/admin_timestamps.json and translations/website_timestamp.json
  • Write a POST endpoint /query in your backend, which takes the parameters locale, project and group, and returns the content of the file translations/$project/$group/$locale.json.
  • Now you can add custom rules, to forbid specific users to fetch some translations groups / projects:
    • only admin users should fetch the /admin translation groups, excepted the login group available for anyone, else you cannot translate the login page ..
    • you could store the translations of your emails in a group emails, and it should be accessible only from the backend, not on the frontend.

An upgrade could be to update the translations:

  • periodically, using cron for example
  • at each saved translation: this server could make a POST request on a specific endpoint of your backend, to inform it that there is a new translation available in a specific project/group.

Translation definition

A translation is made of several fields:

  • locale: the locale of that translation (en_GB, fr_FR ...)
  • project: in your website, you may have several distinct areas. You may wanna separate them, if so, use different projects names.
  • group: in a project, the translation keys are stored in groups too. Helps to structure the translations inside a single project.
  • key: the key to translate.
  • value: the translation

Note: The database schema is clearly optimizable.

Features

  • Stores the translations in a sqlite3 database.
  • Each translation is stored by default, in order to show the different versions of a single translation through the time
  • Has api endpoints to:
    • create a translation
    • remove a translation
    • make a query to fetch the translations which interest us (can select a locale, a project, a group etc...), with or without the history of each translation. Each group can be combined with its timestamp, to only fetch the groups that have expired.
  • stores the creation date in the translations for cache support

TODO

  • store in a cache file the timestamps, currently the timestamps are rebuilt by using the endpoints of the API.

Installation

Via Git

git clone https://github.com/moonlight-coding/mlc-translate-server.git
cd mlc-translate-server
npm i
# if you wanna use `mlc-translate-server` command
sudo npm link

Via NPM

npm install --save mlc-translate-server

Usage

mlc-translate-server server [config_path]
mlc-translate-server list <config_path>
mlc-translate-server export <config_path> <locale> <project> [outfile]
mlc-translate-server import <config_path> <locale> <project> <translationsFile>

Git installation

By default, you can create a config.js in this folder, use config.example.js. The command mlc-translate-server server uses that default config.js.

NPM installation

First, you need to create the config file from config.example.js. I suggest to name it mlc-translate-server.config.js.

You can run it via ./node_modules/.bin/mlc-translate-server mlc-translate-server.config.js.

Another way is to add in package.json a script command to do it:

"scripts": {
  "translate-server": "mlc-translate-server mlc-translate-server.config.js"
},

Doing so, you just need to use npm run translate-server to start the mlc-translate-server.