0.0.2 • Published 4 years ago

@wesleyhf/laravel-localization-js v0.0.2

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

laravel-localization-js

CI

Easy way to handle Laravel's lang.json in Javascript. :earth_americas:

Inspired by Ziggy and based on Laravel way to Retrieving Translation Strings.

Why

Manipulating translations strings at Javascript when you are using Laravel should not be so tricky. So, why not use the lang.json file that is already at your back-end?

Contents

Installation

Just run:

npm install @wesleyhf/laravel-localization-js --save

# or using yarn

yarn add @wesleyhf/laravel-localization-js

Setup

import { createLaravelLocalization } from 'laravel-localization-js';
import lang from '../../lang/pt-br.json';

const __ = createLaravelLocalization(lang);

console.log(__('Hello world')); // output: Olá mundo

Usage

// example of lang.json
{
    'My name is Wesley': 'Meu nome é Wesley',
    'My name is :name': 'Meu nome é :name',
};

// undefined key
__('Hello world'); // 'Hello world'

// defined key
__('My name is Wesley'); // 'Meu nome é Wesley'

// peplacing parameters
__('My name is :name', { 'name': 'Wesley' }); // 'Meu nome é Wesley'

License

MIT License © Wesley Francisco