Skip to content

Effortlessly internationalize your app with our npm i18n package. Easily manage translations for diverse audiences, ensuring a user-friendly, global experience.

License

Notifications You must be signed in to change notification settings

Drawilet/node-i18n

Repository files navigation

🌐 node-i18n

Effortlessly internationalize your app with our npm i18n package. Easily manage translations for diverse audiences, ensuring a user-friendly, global experience.

Installation

# npm
npm install @drawilet/i18n

# yarn
yarn add @drawilet/i18n

Getting started

As a first step, you must choose a translation strategy.

Avaiable strategies

Name api key limits Proxy agent
Google ✔️
  1. Execute the following command to create the configuration file.

    npx i18n init

    This should generate a configuration file i18n.config.js similar to this:

    const GoogleStrategy = require("@drawilet/i18n/strategies/google").default;
    
    module.exports = {
      strategy: new GoogleStrategy(),
      locales: ["es", "en"],
      defaultLocale: "en",
    
      output_path: __dirname + "/src/locales/",
      cache_path: __dirname + "/cache/i18n.json",
    
      output_mode: "separated",
    
      inputs: [__dirname + "/src/routes"],
    };

    Configure it according your project requirements.

  2. In each file (page, route) of your project, you should export _i18n in this way:

    export const _i18n = {
      key: "value",
    };
  3. Run npx i18n generate to generate the files.

  4. Use the i18n client to get the translations.

    Pro tip

    Use our clients for a native-like experience. 🌟

    import I18nClient from "@drawilet/i18n/Client";
    const I18N = new I18nClient();
    const I18nRoutes = I18N.instance() // type (optional)
    
    // You can get the translations using the "get" method
    I18nRoutes.get("locale", "path", "key");
    
    // or creating a controller (ideal for pages or routes)
    const i18n = I18nRoutes.Controller("locale", "path");
    
    // and use it infite times
    i18n.get("title");
    i18n.get("description");


Strategies

Google

new GoogleStrategy("proxy_url");
  • proxy_url (optional): It is the proxy that will be used to avoid rate limits.
    You can obtain one here .
    WARNING: Use this only for personal projects.

Clients

More clients are being created.

About

Effortlessly internationalize your app with our npm i18n package. Easily manage translations for diverse audiences, ensuring a user-friendly, global experience.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published