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

hs-onedirect-translate

v0.0.14

Published

Used to easily translate texts used in hs ui extensions

Downloads

3

Readme

HS - Onedirect Translator Module

This is a module developed to be used for the Onedirect developers when adding translatable texts to HS ui extensions.

1. Installing

Go to your UI extension module and the following to the package.json:

{
  ...
  "dependencies": {
    ...
    "onedirect-hubspot-translations": "latest",
    ...
  },
  ...
}

Then run:

npm install

2. Usage

If the text used is already in our repo, it will be translated. In case it is a new text, please follow the step 3.

Import and initialize:

First import the module to your project file:

import { od } from "onedirect-hubspot-translations";

Then initialize the locale in the entry point of your code:

od.setLocale(context.user.locale);

Simple translation

To add a translatable text, use like this:

<Text>{od.t('Hello world.')}</Text>

Inside props

Or it can also be used as component props this:

<EmptyState title={od.t("Hello world.")} layout="vertical" reverseOrder={true}>

Using with functions

It can also be used within functions:


const handleErr = (msg, title, missingProperty = null) => {
    setIsSuccess(false);
    setErrorTitle(title);
    setErrorMessage(msg);
    setMissingProperty(missingProperty ? missingProperty : '');
    setIsLoading(false);
  }
  
const someFunction = () => {
    ...
    if (err) {
        return handleErr(
            od.t('Error message.'),
            od.t('Error Title')
        );
    }
    ...
} 

Using args to translate only parts of the string

If there are parts of the text that can't be translated, such like property names, for example, you can do it like the following:

od.t("The property $1 of the user $2 can't be updated", "contact_erp_code", "John Doe");
//Example output in Spanish: 
// La propiedad contact_erp_code del usuario John Doe no puede ser actualizada 

3. Generating translations

Dependencies

Before starting, install dependencies

sudo apt-get install jq
sudo apt-get install gh

Download project

First clone the project in your local environment using a personal GitHub token (replace with the token):

git clone https://<your-personal-token>@github.com/onedirect-webdev/hs-onedirect-translate.git

Adding Deepl Token

Create in the root of your project a .env file and add the Deepl token that will be used for translating:

DEEPL_AUTH_KEY=<your-deepl-token>

Prepare your environment

With the same token you have cloned the project, authenticate yourself using:

gh auth login

Make the release file executable:

chmod +x increment_version.sh

Generate translations

Within the repo there is a folder called translations_input. Any file inside this folder will be used to generate translations. You can use as many as files as needed.

The files can be named anyway you want and must be of type .txt

Each text translations must be in a new line

After added the texts, simply run the following command and wait

node translate.js

This command should generate all translations automatically and create a new release version automatically.

Wait a few minutes and got back to your HS module folder and run npm update so the newly generated translations will be available.

4. Bonus

If you want to select all contents that have od.t("xxx") in a fil, using the following regexp:

od\.t\("([^"]*)"