1.0.6 • Published 5 months ago

@drawilet/i18n v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

:globe_with_meridians: 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

Nameapi keylimitsProxy agent
Google:heavy_check_mark:
  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. :star2:

    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.

1.0.6

5 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago

0.1.4

6 months ago

0.1.3

6 months ago

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago

0.0.15

6 months ago

0.0.14

6 months ago

0.0.13

6 months ago

0.0.12

6 months ago

0.0.11

6 months ago

0.0.10

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago