GithubHelp home page GithubHelp logo

galatajs / i18n Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 284 KB

Internationalization packages of galatajs framework

Home Page: https://www.npmjs.com/package/@galatajs/i18n

License: MIT License

TypeScript 52.77% JavaScript 47.23%
i18n internationalization typescript acikkaynak

i18n's Introduction


@galatajs/i18n

Internationalization package of galatajs framework.

What Is It?

This package is the i18n package of the galatajs framework.

With this package, you can perform http requests, websocket requests or anything else with i18n support.

Features:

  • %100 support wherever galatajs works. (Websocket, Http, Microservice, Cli and more)
  • Fast and parametric usage
  • Customizable settings
  • %100 support for modular development with dynamic module support.
  • Fully tested, reliable.

Installation

Note: This package is 1st degree dependent on galatajs to work. Please take a look at @galatajs/app first if you haven't.

npm install @galatajs/i18n

or with yarn

yarn add @galatajs/i18n

Basic Usage

import { createApp } from '@galatajs/app';
import { createI18n } from "@galatajs/i18n";

const app = createApp();
const i18n = createI18n();
app.register(i18n);

(async() => {
  await app.start();

  const msg = i18n.translate({
    key: 'hello',
  })
  console.log('msg -> ', msg); // msg -> hello
})()

Usage With Custom Config

The i18n package comes with some default settings that will probably apply to everyone, but you can change this.

Options

type I18nConfigParams = {
  localesDir?: string; // folder path for language files
  separator?: string; // separator to separate each keys
  fallback?: string; // fallback language
  options?: I18nOptions[]; // options for to catch the default language
};

Default Options

const defaultConfig: I18nConfig = {
  fallback: "en",
  localesDir: path.resolve(__dirname, "locales"),
  options: [I18nOptions.AcceptLanguage, I18nOptions.Query, I18nOptions.Cookie],
  separator: ".",
};

Custom Options Example

const i18n = createI18n({
  fallback: 'tr'
})
const i18n = createI18n({
  fallback: 'tr',
  localesDir: path.resolve(__dirname, "i18n"),
})
const i18n = createI18n({
  separator: '_'
})

In this way, examples can be increased.

With Parameters

The i18n package allows you to work parametrically with performance.

Example

json:

// locales/en.json

{
  "greeting": "Hello, {name}!"
}

ts:

import { createApp } from '@galatajs/app';
import { createI18n } from "@galatajs/i18n";

const app = createApp();
const i18n = createI18n();
app.register(i18n);

(async() => {
  await app.start();

  const msg = i18n.translate({
    key: 'greeting',
    params: {
      'name': 'John Doe'
    }
  })
  console.log('msg -> ', msg) // Hello, John Doe!
})()

Load Dynamic Module

The I18n package has been developed for the galatajs framework. galatajs framework supports modular development %100. However, we cannot develop language files modularly in similar modular frameworks. galatajs differs from its competitors here. If you want, you can externally host and load the language files of the product module!

In addition, dynamic loading operations can be performed with this feature. Because no installation is performed until you call the code.

Example

import { createApp } from '@galatajs/app';
import { createI18n } from "@galatajs/i18n";

const app = createApp();
const i18n = createI18n();
app.register(i18n);

(async() => {
  await app.start();

  // product.module.ts
  i18n.loadModule({
      dir: path.resolve(__dirname, "./locales"),
      key: "product",
  })

  const msg = i18n.translate({
    key: 'product.title',
  })
})()

i18n's People

Contributors

9ssi7 avatar

i18n's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.