1.2.2 • Published 4 years ago

@ulule/localize v1.2.2

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

localize

Localize is a tiny library to manage translations in your javascript application. It is based on React and uses Jed(https://github.com/messageformat/Jed) and the Gettext message format.

To use Localize you need first to initialize the library with your gettext strings (as json).

import { setTranslations } from 'localize'

setTranslations(your_translations)

Localize is composed of 4 functions:

  • t()
  • tn()
  • tc()
  • tnc()

t()

t() allows you to include a single translation

import { t } from 'localize'

t('Anonymous')
t('Your are on %(username)s’s profile', { username: 'Ulule' })

tp()

tp() allows you to include a translation with context, usually for translate same translation. It will use context as key.

import { tp } from 'localize'

tp('remind-me', 'Listed')
tp('coming-soon', 'Listed') // could be translate differently
tp('%(username)s’s profile', { username: 'Ulule' })

tn()

t() allows you to include a single translation and the plural version

import { tn } from 'localize'

tn('%d supporter', '%d supporters', 1)
tn('%(num)d supporter', '%(num)d supporters', 1, {num: 1})

tc()

tc() allows you to include some html tag in a single translation

import { tc } from 'localize'

tc('Include a [br] br element', {br: <br />})

tc('You already have an account? [link: Sign in!]', {link: <a href="#" />})

tnc()

tnc() allows you to include some html tag in a single translation and the plural version

import { tnc } from 'localize'

tnc(
  'Already %(count)d [strong: comment]. Something more?',
  'Already %(count)d [strong: comments]. Something more?',
  20,
  {
    count: 20,
    strong: <strong />,
  }
)
1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

6 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.6-dev

7 years ago

0.0.5-dev

8 years ago

0.0.4-dev

8 years ago

0.0.3-dev

8 years ago

0.0.2-dev

8 years ago

0.0.1-dev

8 years ago