From 5f722f9661d25d794ae1835739bc4b5533d049be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Sun, 17 Oct 2021 01:59:29 -0300 Subject: [PATCH] documentation: Adjust README --- README.md | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1c5d2a3..e2c2492 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,9 @@ 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 @@ -42,6 +41,7 @@ npm install @secjs/intl "greeting": "Hello!, my name is {{name}}!" } ``` + > resources/locales/pt-br/messages.json ```json { @@ -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!' } ``` ---