0.1.4 • Published 4 years ago

dumb-i18n v0.1.4

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

dumb-i18n

a (very) dumb i18n hook for react. it translates stuff.

before we begin

is this production-ready?

no! absolutely not.

why no tests / type def / …?

time. soon, there will be tests and all.

i could do this much better.

cool, prs and issues welcome!

surely you’ll have emojis in the readme?

ok, ok. here’s a sloth. 🦥

usage

setup

in your function component:

const { t, setLang } = useI18n({ languages });

languages is just a simple object:

const languages = {
  en: {
    account: {
      title: 'Account',
      changePassword: 'Change password',
    },
  },
  fr: { ... },
};

t(string)

<h1>{t('account.title')}</h1>
<a href="/change-password">{t('account.changePassword')}</a>

// renders as
<h1>Account</h1>
<a href="/change-password">Change password</a>

setLang(code)

<button onClick={() => { setLang('fr') }}>français</button>
0.1.2

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago