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-lokalise-import

v1.0.1

Published

This package is a tool to sync with Lokalise dictionaries.

Downloads

88

Readme

Blip Lokalise Import

This package is a tool to sync with Lokalise 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-lokalise-import

Usage

Environment Variable

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

Base Configuration File

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

{
    "projects": []
}

Project Configurations

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

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

Properties

  • id: This id can be found in your projects URL. (eg: https://app.lokalise.com/project/6317d22cedb4909dd689f39f.87865697/?view=multi)

  • 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.87865697",
        "name": "a-lokalise-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

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 Key (set in lokalise) "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-lokalise-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-lokalise-import project=a-lokalise-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": {
    "lokalise:pull": "npx blip-lokalise-import"
}

Then you can run it like this:

npm run lokalise:pull

Lokalise TLS problem

Some of you may face a certificate problem when running this script against Lokalise 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": {
        "lokalise:pull": "npx blip-lokalise-import",
        "lokalise:pull-no-tls": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 npx blip-lokalise-import"
    }
  • Then execute your new script:

    npm run lokalise:pull-no-tls