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

localize-joi

v1.3.1

Published

> Translate your JSON using joi

Downloads

55

Readme

localize-joi

Translate your JSON using joi

###Build Status - Master Codeship Status for monscierge/cms

Add localizable string objects in your joi schema:

  • translate, is_machine_translated, is_dirty, value, and language are all required properties
  • localizedString is a required tag in order for translation to occur
...
name: Joi.object().keys({
         translate: Joi.boolean().required(),
         is_machine_translated: Joi.boolean().required(),
         is_dirty: Joi.boolean().required(),
         value: Joi.string().required(),
         language: Joi.string().allow(null).required()
       }).tags(['localizedString'])
...

translate

a boolean indicating whether the localizableString should be translated

is_machine_translated

a boolean indicated whether the localizableString should be translated by the translationProvider (i.e. Google)

is_dirty

a boolean flag indicating whether the text has been changed since last translation

value

string value to be translated

language

source language (i.e. 'en') of the text to translate

Provide configuration

(only Google Translate API is supported at this time)

var config = {
  translationProvider: 'google',
  apiKey: 'yourGoogleApiKey'
};

Initialize instance

var Localize = require('localize-joi');
var localize = new Localize(config);

Run translation

localize.translate(joiSchema, jsonObject, 'zh-CN', (err, result) => {

  // result is your jsonObject with localizableString objects translated in Chinese

});

Full example

var config = {
  translationProvider: 'google',
  apiKey: 'yourGoogleApiKey'
};

var Localize = require('localize-joi');
var localize = new Localize(config);
var joi = require('joi');

var joiSchema = Joi.object().keys({
   id: Joi.string().guid(),
   data: Joi.object().keys({
       name: Joi.object().keys({
         translate: Joi.boolean().required(),
         is_machine_translated: Joi.boolean().required(),
         is_dirty: Joi.boolean().required(),
         value: Joi.string().required(),
         language: Joi.string().allow(null).required()
       }).tags(['localizedString']).required(),
       nested: Joi.object().keys({
         nested_name: Joi.object().keys({
           translate: Joi.boolean().required(),
           is_machine_translated: Joi.boolean().required(),
           is_dirty: Joi.boolean().required(),
           value: Joi.string().required(),
           language: Joi.string().allow(null).required()
        }).tags(['localizedString']).required(),
       }),
       description: Joi.object().keys({
         translate: Joi.boolean().required(),
         is_machine_translated: Joi.boolean().required(),
         is_dirty: Joi.boolean().required(),
         value: Joi.string().required(),
         language: Joi.string().allow(null).required()
       }).tags(['localizedString']),
       is_active: Joi.boolean(),
       message: Joi.object().keys({
         translate: Joi.boolean().required(),
         is_machine_translated: Joi.boolean().required(),
         is_dirty: Joi.boolean().required(),
         value: Joi.string().required(),
         language: Joi.string().allow(null).required()
       }).tags(['localizedString']),
       images: Joi.array().items(Joi.string().guid()),
       ordinal: Joi.number().integer().min(0),
   }).required().meta({ className: "DataModel"}),
   created_on: Joi.date().timestamp(),
   updated_on: Joi.date().timestamp()
}).meta({ className: "DataRecord"});

var jsonObject = {
    id: '97170e81-8b55-4cad-8748-5a94658b91d6',
    data: {
      name: {
        translate: false,
        value: 'testing model name',
        is_dirty: false,
        is_machine_translated: true,
        language: 'en'
      },
      nested: {
        nested_name: {
          translate: true,
          value: 'testing model nested name',
          is_dirty: false,
          is_machine_translated: true,
          language: 'en'
        }
      },
      description: {
        translate: true,
        value: 'this is a description of the testing model',
        is_dirty: false,
        is_machine_translated: true,
        language: null
      },
      is_active: true,
      message: {
        translate: true,
        value: 'this is the message of the testing model',
        is_dirty: false,
        is_machine_translated: false,
        language: 'en'
      },
      images: [
        '1892d407-28db-4c91-ad5b-bd2c596a201d',
        'edc9593f-6441-4e0d-94c3-c1b4ccd7d25d',
        'cdcd0518-86ba-45e8-a7d2-675867cab29a'
      ],
      ordinal: 0
    },
    created_on: new Date().getTime(),
    updated_on: new Date().getTime()
};

localize.translate(joiSchema, jsonObject, 'zh-CN', (err, result) => {

  console.log(result);
  // =>
  //  { name:
  //   { translate: false,
  //     value: 'testing model name',
  //     is_dirty: false,
  //     is_machine_translated: true,
  //     language: 'en' },
  //  nested:
  //   { nested_name:
  //      { translate: true,
  //        value: '测试模型嵌套名',
  //        is_dirty: false,
  //        is_machine_translated: true,
  //        language: 'zh-CN' } },
  //  description:
  //   { translate: true,
  //     value: '这是测试模型的描述',
  //     is_dirty: false,
  //     is_machine_translated: true,
  //     language: 'zh-CN' },
  //  is_active: true,
  //  message:
  //   { translate: true,
  //     value: 'this is the message of the testing model',
  //     is_dirty: false,
  //     is_machine_translated: false,
  //     language: 'en' },
  //  images:
  //   [ '1892d407-28db-4c91-ad5b-bd2c596a201d',
  //     'edc9593f-6441-4e0d-94c3-c1b4ccd7d25d',
  //     'cdcd0518-86ba-45e8-a7d2-675867cab29a' ],
  //  ordinal: 0 }

});