# Masonite Lang

<p align="center">
    <img src="https://banners.beyondco.de/Masonite Lang.png?theme=light&packageManager=pip+install&packageName=masonite-lang&pattern=topography&style=style_1&description=Package description in one line displayed e.g. in README&md=1&showWatermark=1&fontSize=100px&images=https%3A%2F%2Fgblobscdn.gitbook.com%2Fspaces%2F-L9uc-9XAlqhXkBwrLMA%2Favatar.png">
</p>

<p align="center">
  <a href="https://docs.masoniteproject.com">
    <img alt="Masonite Package" src="https://img.shields.io/static/v1?label=Masonite&message=package&labelColor=grey&color=blue&logo=data:image/png;base64, ">
  </a>
  <img alt="GitHub Workflow Status (branch)" src="https://img.shields.io/github/workflow/status/chris1ding1/lang/Test%20Application">
  <img src="https://codecov.io/gh/chris1ding1/lang/branch/main/graph/badge.svg?token="/>
  <img alt="PyPI" src="https://img.shields.io/pypi/v/lang">
  <img src="https://img.shields.io/badge/python-3.11+-blue.svg" alt="Python Version">
  <img alt="GitHub release (latest by date including pre-releases)" src="https://img.shields.io/github/v/release/chris1ding1/lang?include_prereleases">
  <img alt="License" src="https://img.shields.io/github/license/chris1ding1/lang">
  <a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
</p>

## Introduction

Package description in one line displayed e.g. in README

## Features

- _Add your package main features here_
- _and here_

## Official Masonite Documentation

New to Masonite ? Please first read the [Official Documentation](https://docs.masoniteproject.com/).
Masonite strives to have extremely comprehensive documentation 😃. It would be wise to go through the tutorials there.
If you find any discrepencies or anything that doesn't make sense, be sure to comment directly on the documentation to start a discussion!

Have questions or want to talk? Be sure to join the [Masonite Discord Community](https://discord.gg/TwKeFahmPZ)!

## Installation

```bash
pip install masonite-lang
```

## Configuration

Add LangProvider to your project in `config/providers.py`:

```python
# config/providers.py
# ...
from lang import LangProvider

# ...
PROVIDERS = [
    # ...
    # Third Party Providers
    LangProvider,
    # ...
]
```

Then you can publish the package resources (if needed) by doing:

```bash
python craft package:publish lang
```

Set your application locale in `.env`:

```env
APP_LOCALE=en
```

defaults to 'en' if not set.

Create language files in the `/lang` directory:

```
/lang
    en.json
    es.json
    zh_CN.json
```

Example translation file (`en.json`):

```json
{
    "welcome": "Welcome to our application"
}
```

## Usage

### python

```python
from lang.facades import Lang

Lang.current_locale()
Lang.set_locale('en')
Lang.is_locale('en')
Lang.trans('trans')
```

### templates

In your templates, use the `__()` helper to display translated text:

```html
{{ __('not') }}
```

If the specified translation string does not exist, the __ function will return the translation string key.

## Contributing

Please read the [Contributing Documentation](CONTRIBUTING.md) here.

## Maintainers

- [Chris](https://www.github.com/chris1ding1)

## License

Masonite Lang is open-sourced software licensed under the [MIT license](LICENSE).
