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

@nimbos/i18n

v0.1.12

Published

Pacote de i18n para o projeto nimbos

Downloads

190

Readme

@nimbos/i18n

Internationalization

A função de internacionalização permite salvar as strings do sistema de maneira centralizada e manutenivel alem de permitir a mudança de linguagem em runtime.

Uso Básico

Após regisdtrar um conjunto de chaves

import t from '@nimbos/i18n';

//registrando
t.register('pt-BR', {
  hello_world: 'Olá Mundo'
});

O uso pode ser feito da seguinte forma

import t from '@nimbos/i18n';

const localized = t('hello_world');

console.log(localized); //Olá Mundo

Váriaveis

Para cenários onde existem váriaveis dentro das mensagem, elas podem ser definidas como váriaveis (nomeadas) e parametros (numerados).

Como no exemplo:

import t from '@nimbos/i18n';

//registrando
t.register('pt-BR', {
  hello_world: 'Olá {name}'
});

O uso pode ser feito da seguinte forma

import t from '@nimbos/i18n';

const localized = t('hello_world', { name: 'Mundo' });

console.log(localized); //Olá Mundo

Parametros

Exemplo de uso com parametros:

import t from '@nimbos/i18n';

//registrando
t.register('pt-BR', {
  hello_world: 'Olá {0}' //o nomero é sequencial, {1}, {2}, {3}...
});

O uso pode ser feito da seguinte forma

import t from '@nimbos/i18n';

let parametro = 'Mundo';
const localized = t('hello_world', parametro);

console.log(localized); //Olá Mundo

Esse modo é menos legivel e pode gerar confusões, use com cautela

Contagem Inteligente

Para cenários onde temos contagem de elementos, podemos usar a variavel ou parametro para contagem

Exemplo:

import t from '@nimbos/i18n';

//registrando
t.register('pt-BR', {
  items_count: ['Sem Items!', 'Apenas um Item!', 'São {count} Items!']
});

O uso pode ser feito da seguinte forma

import t from '@nimbos/i18n';

const localizedNone = t('hello_world', { count: 0 });
const localizedOne = t('hello_world', { count: 1 });
const localizedMany = t('hello_world', { count: 2 });

console.log(localizedNone); //Sem Items!
console.log(localizedOne); //Apenas um Item!
console.log(localizedMany); //São 2 Items!

O número de items acompanha os items do array, se existirem 4 items, por exemplo, será o primeiro para 0 o segundo para 1 o terceiro para 2 e o quarto para todos os outros O mesmo ocorreria para 2 itens, o primeiro para 0 e o segundo para todos os outros

A contagem inteligente funciona para as props com os seguintes nomes:

  • count
  • number
  • size
  • length
  • items

Ou para o primeiro item de um array

Mudança de linguagem

Exemplo de uso com varios idiomas:

import t from '@nimbos/i18n';

//registrando
t.register('pt-BR', {
  hello_world: 'Olá Mundo' //o nomero é sequencial, {1}, {2}, {3}...
});
//registrando
t.register('en-US', {
  hello_world: 'Hello World' //o nomero é sequencial, {1}, {2}, {3}...
});

O uso pode ser feito da seguinte forma

import t from '@nimbos/i18n';

let parametro = 'Mundo';
const localizedPTBR = t('hello_world');
t.lang('en-US');
const localizedENUS = t('hello_world');

console.log(localizedPTBR); //Olá Mundo
console.log(localizedENUS); //Hello World

Exemplo no React

Pode ser usado como função:

import t from '@nimbos/i18n'


<div>
    <h1>{t`view.title`}</h1>
    <p>{t('view.present', { name: user.name, email: user.email })}</p>
    <span>{t('statistics.online_users', onlineUsers)}</span>
</div>

Ou como componente:

import {T} from '@nimbos/i18n'
// ou
//import {I18n} from '@nimbos/i18n'

<div>
    <h1><T>view.title</T></h1>
    <p>
        <T
            name={user.name}
            email={user.email} >
            view.present
        </T>
    </p>
    <span><T params={[onlineUsers]}>statistics.online_users</T> </span>
</div>