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

cimpress-translations

v2.1.8

Published

Lightweight client for the Translations Service

Downloads

51

Readme

cimpress-translations

npm version

cimpress-translations is a convenient client for Cimpress' Translations service.

Features:

  • list and describe services; modify a service structure; get and put language blobs for a language
  • pick language using ISO-639-2 ('eng', 'fra') or by passing the language's English name ('English', 'French')
  • supply authorization statically (using a hard-coded string) or dynamically (with a custom method)
  • convenience of a default service URL with the possibility of an override

Getting Started

Include cimpress-translations in your project using npm or yarn:

npm install --save cimpress-translations

Require the module with:

const { CimpressTranslationsClient } = require("cimpress-translations");

Consuming the API

new CimpressTranslationsClient(url, auth)

Instantiates a new client. Pass null for url to use the default service URL. auth may be a string or a synchronous/asynchronous function returning a string. If it's a string, it should follow the format Bearer .

client.listServices()

Lists all services for which you can access translations.

let services = await client.listServices();
console.log(services);
/**
 * {
 *   "services": [
 *     {
 *       "serviceId": "28b1f0d2-9366-40cb-95bd-14de8c3adb9b"
 *       "name": ...
 *
client.describeService(serviceId)

Returns details about a service.

let services = await client.describeService("28b1f0d2-9366-40cb-95bd-14de8c3adb9b");
console.log(service);
/**
 * {
 *   "serviceId": "28b1f0d2-9366-40cb-95bd-14de8c3adb9b"
 *   "name": "My Cimpress Service",
 *   "configuration": ...
 *
client.getLanguageBlob(serviceId, language)

Retrieves the translation for a service in a given language. The language may be specified using ISO-639-2 ('eng', 'fra') or selected using its English name ('English', 'French').

let services = await client.getLanguageBlob("28b1f0d2-9366-40cb-95bd-14de8c3adb9b", "French");
console.log(service);
/**
 * {
 *   "blobId": "8a27db52-3245-4466-be94-5e9f39283a3b",
 *   "data": ...
 *
client.putLanguageBlob(serviceId, language, blob)

Creates or updates the translation for a service in a given language. The language may be specified using ISO-639-2 ('eng', 'fra') or selected using its English name ('English', 'French').

let blob = {
  pages: {
    home: "Home page"
  }
};
await client.putLanguageBlob("28b1f0d2-9366-40cb-95bd-14de8c3adb9b", "English", blob);
client.patchStructure(serviceId, structurePatches)

Patches the translations structure of a service. The patch should be in JSON Patch format. The supported operations are add and remove.

let structurePatches = [
  {
    op: "add",
    path: "/pages",
    value: {
      contact: {
        name: "Contact page",
        description: "The title of the contact page",
        type: "singular"
      }
    }
  },
  {
    op: "remove",
    path: "/pages/home"
  }
];
await client.patchStructure("28b1f0d2-9366-40cb-95bd-14de8c3adb9b", structurePatches);
client.removeKeysFromStructure(serviceId, blob)

Removes keys from the translations structure of a service. The keys to remove are determined based on the difference between the blob passed as the parameter and its remote counterpart stored in Cimpress' Translations service. Any keys which are not present in the passed blob will be removed from the translations structure.

/**
 * Remote blob
 * {
 *   blobId: "eng",
 *   data: {
 *     pages: {
 *       home: "Home Page",
 *       contact: "Contact Page"
 *     }
 *   }
 * }
 */

let localBlob = {
  data: {
    blobId: "eng",
    pages: {
      home: "Home page"
    }  
  }
};
await client.removeKeysFromStructure("28b1f0d2-9366-40cb-95bd-14de8c3adb9b", localBlob);

/** generates and applies the following patch to the service structure :
 * [
 *   {
 *     op: "remove",
 *     path: "/pages/contact"
 *   }
 * ]
 */

Error handling

Identify errors by checking their name property.

EGENERIC

An unspecified error has occured.

ENOACCESS

You are not authenticated or authorized to read this information.

ENOTFOUND

The service was not found of does not support this language.

ENOLANG

The requested language was not found amongst languages specified in ISO-639-2.

EBADREQUEST

The provided body of the request contains one or multiple errors.

Built With

Contributing

Have you benefited from this library? Have you found or fixed a bug? Would you like to see a new feature implemented? We are eager to collaborate with you on GitHub.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the Apache 2.0 license - see the LICENSE file for details.