GithubHelp home page GithubHelp logo

isabella232 / i18next-intervalplural-postprocessor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from i18next/i18next-intervalplural-postprocessor

0.0 0.0 0.0 97 KB

post processor for i18next enabling interval plurals

License: MIT License

JavaScript 100.00%

i18next-intervalplural-postprocessor's Introduction

i18next-intervalPlural-postProcessor

Introduction

Travis Coveralls npm version Bower David

This is a i18next postProcessor enabling interval based plurals.

Getting started

Source can be loaded via npm, bower or downloaded from this repo.

# npm package
$ npm install i18next-intervalplural-postprocessor

# bower
$ bower install i18next-intervalplural-postprocessor
  • If you don't use a module loader it will be added to window.i18nextIntervalPluralPostProcessor

Wiring up:

import i18next from 'i18next';
import intervalPlural from 'i18next-intervalplural-postprocessor';

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

Usage sample

// given loaded resources
// translation: {
//   key1: '{{count}} item',
//    key1_plural: '{{count}} items',
//    key1_interval: '(1)[one item];(2-7)[a few items];(7-inf)[a lot of items];',
//    key2: '{{count}} item',
//    key2_plural: '{{count}} items',
//    key2_interval: '(1)[one item];(2-7)[a few items];'
// }

i18next.t('key1_interval', { postProcess: 'interval', count: 1 }); // -> one item
i18next.t('key1_interval', { postProcess: 'interval', count: 4 }); // -> a few items
i18next.t('key1_interval', { postProcess: 'interval', count: 100 }); // -> a lot of items

// if a interval is not specified i18next fallbacks to classic plural
i18next.t('key2_interval', { postProcess: 'interval', count: 1 }); // -> one item
i18next.t('key2_interval', { postProcess: 'interval', count: 4 }); // -> a few items
i18next.t('key2_interval', { postProcess: 'interval', count: 100 }); // -> 100 items

Setting own options

import i18next from 'i18next';
import intervalPlural from 'i18next-intervalplural-postprocessor';

intervalPlural.setOptions({
  // these are the defaults
  intervalSeparator: ';',
  intervalRegex: /\((\S*)\).*?\[((.|\n)*)\]/, // pre 3.0 /\((\S*)\).*{((.|\n)*)}/,
  intervalSuffix: '_interval'
});

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

Gold Sponsors

i18next-intervalplural-postprocessor's People

Contributors

adrai avatar greenkeeperio-bot avatar jamuhl avatar seleb avatar tsugami avatar

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.