Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

A conditional ability that make i18next more powerful.

License

Notifications You must be signed in to change notification settings

soc221b/i18next-select-post-processor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

npm version visitors

A conditional ability that make i18next more powerful.

Getting Started

# npm package
$ npm install i18next-select-post-processor

Usage

We could using Boolean, String, Number, and Null type to check values.

import i18next from 'i18next';
import SelectPostprocessor from 'i18next-select-post-processor';

i18next
  .use(SelectPostprocessor)
  .init(i18nextOptions);
const translation = {
  example: {
    basic: `$s(female,true,She is a lady.);`,
    nesting: `$s(cond1,true,She $s(cond2,true,is $s(cond3,true,a $s(cond4,true,lady.););););`,
    concatenation: `$s(cond1,true,She );$s(cond2,true,is );$s(cond3,true,a );$s(cond4,true,lady.);`
  }
};
i18next.t(example.basic, { "postProcess": "select" });
// => She's a lady.
i18next.t(example.nesting, {"postProcess": "select", "cond1": true, "cond2": true, "cond3": true, "cond4": true});
// => She's a lady.
i18next.t(example.concatenation, {"postProcess": "select", "cond1": true, "cond2": true, "cond3": true, "cond4": true});
// => She's a lady.

Online Demo

CodeSandbox

Change Default Options

import i18next from 'i18next';
import SelectPostprocessor from 'i18next-select-post-processor';

SelectPostprocessor.updateOptions({
  // this are the defaults
  regex: /\$s\(([a-zA-Z0-9_\$]+),([^,]+),([^(;\))]*)\);/,
  maxReplacementCount: 1000,
});

i18next
  .use(SelectPostprocessor)
  .init(i18nextOptions);

About

A conditional ability that make i18next more powerful.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published