nanostores / i18n

A tiny (≈600 bytes) i18n library for React/Preact/Vue/Svelte
MIT License
229 stars 12 forks source link

Add preprocessors #9

Closed zumkorn closed 2 years ago

zumkorn commented 2 years ago

Issue #1 I added the createPreprocessor function to create a preprocessor. The developer can specify any store to listen for changes and re-render translations.

import { createPreprocessor } from '@nanostores/i18n'
const screenSize = atom('big')
const sizePreprocessor = createPreprocessor(screenSize)

Add preprocessor:

export const i18n = createI18n(locale, {
  get: …,
  preprocessors: [
    sizePreprocessor
  ]
})

Create messages:

export const messages = i18n({
  send: sizePreprocessor.process({
    big: 'Send message',
    small: 'send'
  }),
  name: 'User name'
})

Return translate:

export const SendLabel = () => {
  const t = useStore(messages)
  return t.send()
}
ai commented 2 years ago

Can you update size limit in package.json and add TSDoc to createPreprocessor?

zumkorn commented 2 years ago

Can you update size limit in package.json and add TSDoc to createPreprocessor?

Added

ai commented 2 years ago

Size Limit is still invalid. You can run pnpm test to run all tests.

zumkorn commented 2 years ago

Size Limit is still invalid. You can run pnpm test to run all tests.

Fixed. Sorry, my mistake.

ai commented 2 years ago

Looks good. Thanks.