Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wesleyhf/laravel-localization-js
Easy way to handle Laravel's lang.json in Javascript :earth_americas:
https://github.com/wesleyhf/laravel-localization-js
Last synced: about 2 months ago
JSON representation
Easy way to handle Laravel's lang.json in Javascript :earth_americas:
- Host: GitHub
- URL: https://github.com/wesleyhf/laravel-localization-js
- Owner: wesleyhf
- License: mit
- Created: 2020-05-01T03:07:22.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T15:50:35.000Z (almost 2 years ago)
- Last Synced: 2024-11-01T20:13:33.460Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.97 MB
- Stars: 9
- Watchers: 3
- Forks: 1
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# laravel-localization-js
![CI](https://github.com/wesleyhf/laravel-localization-js/workflows/CI/badge.svg?branch=master)
Easy way to handle Laravel's lang.json in Javascript. :earth_americas:
Inspired by [Ziggy](https://github.com/tightenco/ziggy) and based on Laravel way to [Retrieving Translation Strings](https://laravel.com/docs/7.x/localization#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](#installation)
- [Setup](#setup)
- [Usage](#usage)
- [License](#license)## Installation
Just run:
```sh
npm install @wesleyhf/laravel-localization-js --save# or using yarn
yarn add @wesleyhf/laravel-localization-js
```## Setup
```js
import { createLaravelLocalization } from 'laravel-localization-js';
import lang from '../../lang/pt-br.json';const __ = createLaravelLocalization(lang);
console.log(__('Hello world')); // output: Olá mundo
```## Usage
```js
// 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](LICENSE) © Wesley Francisco