npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

i18next-countable-postprocessor

v1.0.3

Published

postProcessor for applying advanced count dependent rules

Downloads

4

Readme

i18next-countable-postProcessor

Introduction

This is i18next plugin enabling advanced translations, required by some languages.

Getting started

# npm package
$ npm install i18next-countable-postprocessor

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

Minimal configuration

import i18next from 'i18next';
import countable from 'i18next-countable-postprocessor';

i18next
  .use(countable)
  .init({ /* your i18next configuration */ });

Translation resource

Create additional rule keys in translation resource for language that requires more that one plural form. Example is Polish language, there are 2 forms for plural version, and the rules are:

  • FORM 1: when number ends with digit 2, 3 or 4 digit, except when it ends with 12, 13 and 14. Eg. 2, 11, 22, 142, 1054, and so on.
  • FORM 2: when number don't end with 2, 3 or 4 digit, except for 12, 13, 14. Eg. 5, 113, 5528.

Example resource

{
    "records_found_0": "Nie znaleziono rekordów",
    "records_found_1": "Znaleziono 1 rekord",

    // (1) rule for count numbers ending with "2"
    "records_found_*2": "Znaleziono {{count}} rekordy",
    // (2) rule for count numbers ending with "3"     
    "records_found_*3": "Znaleziono {{count}} rekordy",
    // (3) rule for count numbers ending with "4"   
    "records_found_*4": "Znaleziono {{count}} rekordy", 
    // (4) exception from rule (1) for count numbers ending with "12"     
    "records_found_*12": "Znaleziono {{count}} rekordów",
    // (5) exception from rule (2) for count numbers ending with "13" 
    "records_found_*13": "Znaleziono {{count}} rekordów",
    // (6) exception from rule (3) for count numbers ending with "14"  
    "records_found_*14": "Znaleziono {{count}} rekordów",    
    
    // additionally at least one of following fallback rules for other numbers should be defined
    "records_found_plural": "Znaleziono {{count}} rekordów", // higher priority fallback translation, only for numbers > 2
    "records_found": "Znaleziono {{count}} rekordów",        // lower priority fallback translation, but will handle 0 and 1 if no specific rule for those numbers is provided
}

Translating using native t function

import i18next from "i18next";

const translation = i18next.t('records_found', { postProcess: 'countable', count: 5 }); 

Translating using react-i18next

import { useTranslation } from "react-i18next";

const { t } = useTranslation(); 
const translation = t('records_found', { postProcess: 'countable', count: 5 });

Extended configuration

import i18next from 'i18next';
import countable from 'i18next-countable-postprocessor';

countable.setOptions({
  variantSeparator: "-",
  countVariableName: "number"
});

i18next
  .use(countable)
  .init({ /* your i18next configuration */ });

Options available

  • variantSeparator - separator between resource key and number rule suffix. Define "-" for example to replace pattern "key_*1" with "key-*1"

  • countVariableName - postProcessor will "active" only if count variable is provided as option for "t" function, but it doesn't need to be named "count". Define other string, e.g. "number" to resorve translation like "Znaleziono {{number}} rekordy" from example above.

Credits

This project's structure is based on great intervalPlural processor library.