Skip to content

Commit

Permalink
documentation: Adjust README
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Oct 17, 2021
1 parent eb05ef1 commit 5f722f9
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ npm install @secjs/intl

### Sntl

> Format messages using json files inside resources/locales folder
> Is extremely important to create the folder resources/locales in the project root,
> and inside you need to create the folders for each language, example: resources/locales/en-us.
> Format messages using json files inside resources/locales folder. Is extremely important to create
> the folder resources/locales in the project root, and inside you need to create the folders for
> each language, example: resources/locales/en-us.
> resources/locales/en-us/messages.json
```json
{
"greeting": "Hello!, my name is {{name}}!"
}
```

> resources/locales/pt-br/messages.json
```json
{
Expand All @@ -55,17 +55,26 @@ import { Sntl } from '@secjs/intl'
// First set the defaultLocale and call load,
// to get all files inside resources folder.

// Now you can call Sntl anyware and use as you want.
// Now you can call Sntl anywhere and use as you want.
await new Sntl.setDefaultLocale('en-us').load()

Sntl.formatMessage('messages.greeting', { name: 'João' }) // { message: 'Hello!, my name is João!' }
Sntl.formatMessage('messages.greeting', { name: 'João' })
// { message: 'Hello!, my name is João!' }

// Use forLocale to call for a specific locale in runtime
Sntl.forLocale('pt-br').formatMessage('messages.greeting', { name: 'João' }) // { message: 'Olá!, meu nome é João!' }
Sntl.forLocale('en-us').formatMessage('messages.greeting', { name: 'João' }) // { message: 'Hello!, my name is João!' }
Sntl.forLocale('pt-br').formatMessage('messages.greeting', {
name: 'João',
}) // { message: 'Olá!, meu nome é João!' }

Sntl.forLocale('en-us').formatMessage('messages.greeting', {
name: 'João',
}) // { message: 'Hello!, my name is João!' }

// Use changeLocale to change the defaultLocale in runtime
Sntl.changeLocale('pt-br').formatMessage('messages.greeting', { name: 'João' }) // { message: 'Olá!, meu nome é João!' }
Sntl.changeLocale('pt-br').formatMessage('messages.greeting', {
name: 'João',
})
// { message: 'Olá!, meu nome é João!' }
```

---
Expand Down

0 comments on commit 5f722f9

Please sign in to comment.