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

use-localization

v1.2.6

Published

Custom Hook to support localization when locale changes. The hook will accept the locale and written the localization utilities.

Downloads

3

Readme

use-localization

Custom Hook to support localization when locale changes. The hook will accept the locale and return the localization utilities.

NPM npm

Install

npm install use-localization

Usage

import React, { useState, useMemo } from "react";
import useLocalization from 'use-localization';

function MyLocalizationComponent() {
  const [locale, setLocale] = useState('en-IN');
  const config = useMemo(() => ({ locale }), [locale]);
  const { formatNumber, formatCurrency, flag, isRTL } = useLocalization(config);
  return (
        <div>
            <div>Formatted Currency: {formatCurrency(783984.356)}</div>
            <div>Formatted Number: {formatNumber(783984.356)}</div>
            <div>Flag: {flag}</div>
            {isRTL && <div>{`${isRTL}`}</div>}
            <button type="button" onClick={() => setLocale(locale === 'en-IN' ? 'en-US' : 'en-IN')}>
                Switch to {locale === 'en-IN' ? 'US' : 'INDIA'}
            </button>
        </div>
  )
}

Examples

To play around with the hook, try these interactive sample apps

CodeSandbox

Parameters

| Param | Type | Optional | Default | Description | | --- | :---: | :---: | :---: | --- | | config | Object | No | - | Must have the locale property present |

Returns

An object containing below properties

| Prop | Return Type | Description | | --- | :---: | --- | | formatCurrency | Function | Takes any number as an argument and returns the formatted localized value with currency | | formatNumber | Function | Takes any number as an argument and returns the formatted localized value | | flag | Text | Text representation of the country flag based on the locale. For example, 🇮🇳 for en-IN | | isRTL | Boolean | True, if the passed locale is RTL. For example, Arabic, Hebrew, etc. |

Supported Locales

sq-AL, ar-DZ, ar-BH, ar-EG, ar-IQ, ar-JO, ar-KW, ar-LB, ar-LY, ar-MA, 
ar-OM, ar-QA, ar-SA, ar-SD, ar-SY, ar-TN, ar-AE, ar-YE, be-BY, bg-BG, 
ca-ES, zh-CN, zh-HK, zh-SG, zh-TW, hr-HR, cs-CZ, da-DK, nl-BE, nl-NL, 
en-AU, en-CA, en-IN, en-IE, en-MT, en-NZ, en-PH, en-SG, en-ZA, en-GB, 
en-US, et-EE, fi-FI, fr-BE, fr-CA, fr-FR, fr-LU, fr-CH, de-AT, de-DE, 
de-LU, de-CH, el-CY, el-GR, iw-IL, hi-IN, hu-HU, is-IS, in-ID, ga-IE, 
it-IT, it-CH, ja-JP, ko-KR, lv-LV, lt-LT, mk-MK, ms-MY, mt-MT, no-NO, 
pl-PL, pt-BR, pt-PT, ro-RO, ru-RU, sr-BA, sr-ME, sr-CS, sr-RS, sk-SK, 
sl-SI, es-AR, es-BO, es-CL, es-CO, es-CR, es-DO, es-EC, es-SV, es-GT, 
es-HN, es-MX, es-NI, es-PA, es-PY, es-PE, es-PR, es-ES, es-US, es-UY, 
es-VE, sv-SE, th-TH, tr-TR, uk-UA, vi-VN

License

MIT © mayank8aug