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

@phdulac/ai18n

v1.3.8

Published

AI powered translation tool

Downloads

297

Readme

Documentation for the ai18n library

Introduction

ai18n is an AI-driven translation tool designed to facilitate the management and generation of translations for your projects. It offers integration with multiple AI services to automate the translation of textual content found in your source files.

Before starting

ai18n suppose that you already have installed a translation library like i18next or react-i18n.

When you are coding a new page or component, instead of having to choose a translation key that fits the string you want to translate, and go manualy update all your translation files, you just have to write the string in your component in the language you want,

...and let ai18n do the work.

Example:

import { useTranslation } from 'react-i18next';

const MyComponent = () => {
  const { t } = useTranslation();

  return <div>{t('Bonjour tout le monde')}</div>;
};

ai18n will choose a key for you and update your translation files and your code.

import { useTranslation } from 'react-i18next';

const MyComponent = () => {
  const { t } = useTranslation();

  return <div>{t('hello_world')}</div>;
};

Installation

Install ai18n using npm:

npm install ai18n

Configuration

Create a configuration file named ai18n.config.js in the root of your project. This file allows you to customize the behavior of the ai18n tool. Here's an example configuration:

module.exports = {
  // Supported languages for the application
  "languages": [
    "fr", 
    "es", 
    "de"
  ],
  // Path to the translation files. {lang} will be replaced by the language code
  "localesPath": "./locales/{lang}/translation.json",
  // Source directories to scan for translation keys
  "sourceDirectories": [
    "./examples"
  ],
  // Regular expressions to capture translation keys
  "catchRegexes": [
    `t\\(['"]+(.*?)['"]+\\)`,
    'Trans\\s*i18nKey\\s*=\\s*"(.*?)"',
    `translate\\(['"]+(.*?)['"]+\\)`,
    `translate\\(['"]+(.*?)['"]+,\\s*\\{\\s*(.*?)\\s*\\}`,
    `t\\(['"]+(.*?)['"]+,\\s*\\{\\s*(.*?)\\s*\\}`,
    `\\$\\{\\s*t\\(['"]+(.*?)['"]+\\)\\s*\\}`
  ],
  // Regular expressions to exclude certain translation keys
  "excludeRegexes": [
    "document.createElement\\(['\"]+(.*?)['\"]+\\)"
  ]
};

Usage

To initialize the tool, run the following command:

ai18n init

This will scan your source directories for guessing translation regexes and update your configuration file with it.

To generate the translation files, run the following command:

ai18n parse

This will parse the files and extract the non-translated strings Then it will translate them into the supported languages Then it will use IA to choose appropriate keys for the translations Then it will update the translation files with the new translations Then it will replace the non-translated strings with the new keys