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

blip-ditto-import

v1.0.5

Published

This package is a tool to sync with Dittowords dictionaries.

Downloads

2

Readme

Blip Ditto Import

This package is a tool to sync with Dittowords dictionaries.

Installation

This package is meant to be used with npx command, which by default, will ask you to install it to your user context on the first run.

If you prefer to have the package inside your project's node_modules you can execute the following:

npm i -D blip-ditto-import

Usage

Environment Variable

Before invoke the sync method you need to set DITTO_API_KEY environment variable with your KEY.

Base Configuration File

Create a file called ditto-import-conf.json in the source of your project with this basic structure:

{
    "base_variant": "pt",
    "projects": []
}

Change the value of your default language variant in the base_variant property if pt does not suit you.

Project Configurations

For each ditto project you want to sync you need to add an entry inside the projects array like this:

{
    "base_variant": "pt",
    "projects": [
        {
            "id": "6317d22cedb4909dd689f39f",
            "name": "a-ditto-project",
            "destination": "output/dictionary.ts"
        }
    ]
}

Properties

  • id: This id can be found in your projects URL. (eg: https://app.dittowords.com/projects/6317d22cedb4909dd689f39f/page/0:1)

  • name: A human readable identifier. It's used to name the output file if not defined in destination field and to sync a specific project through command options.

  • destination: The output path for the generated file(s).

    • You can use the __variant replacer to break the output into subfolders or multiple files.
    {
        "id": "6317d22cedb4909dd689f39f",
        "name": "a-ditto-project",
        "destination": "output/__variant/i18n.ts"
    }

Output Files

Formats

You can choose between .json and .ts files.

If you choose .ts files the script will perform an TypeScript transpile and message you if the output is not valid.

Nested Terms and Breaking Convention

The Ditto platform has some limitations to deliver multi-level term trees. In order to overcome this characteristic, a convention was implemented to the script.

If you want to break your term into a nested structure all you have to do is to identify the term with dots. Eg.:

A Text Item ID (set in ditto) "main.header.title" will be outputed as:

export const translations = {
    main: {
        header: {
            title: "My text in american english"
        }
    }
};

Executing

In order to perform a sync you can run the following command:

npx blip-ditto-import

The script will generate files for all projects in your config file. If you want to sync a single project you can specify the project's name as an argument like this:

npx blip-ditto-import project=a-ditto-project

NPM Scripts Shortcut

If you find more suitable you can add an npm script in your package.json file to create an alias to the executing command:

"scripts": {
    "ditto:pull": "npx blip-ditto-import"
}

Then you can run it like this:

npm run ditto:pull

Dittowords TLS problem

Some of you may face a certificate problem when running this script against Ditto API. In order to fix it you have to set the NODE_TLS_REJECT_UNAUTHORIZED environment variable to 0.

Because this is highly not recommended, you can set it just for this command execution in particular.

A cross OS solution is:

  • Add cross-env package to your project:

    npm i -D cross-env
  • Create a npm script in your package.json:

    "scripts": {
        "ditto:pull": "npx blip-ditto-import",
        "ditto:pull-no-tls": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 npx blip-ditto-import"
    }
  • Then execute your new script:

    npm run ditto:pull-no-tls