Skip to main content

README.md

# Fakererer

[![build](https://github.com/manhvu/fakererer/actions/workflows/ci.yaml/badge.svg)](https://github.com/manhvu/fakererer/actions/workflows/ci.yaml)
[![Version](https://img.shields.io/hexpm/v/fakererer.svg?style=flat-square)](https://hex.pm/packages/fakererer)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/fakererer/)
[![License](https://img.shields.io/hexpm/l/fakererer.svg?style=flat-square)](https://github.com/manhvu/fakererer/blob/main/LICENSE)
[![Issues](https://img.shields.io/github/issues/manhvu/fakererer.svg?style=flat-square)](https://github.com/manhvu/fakererer/issues)
[![Downloads](https://img.shields.io/hexpm/dt/fakererer.svg?style=flat-square)](https://hex.pm/packages/fakererer)

> A pure Elixir library for generating fake data.

**Fakererer** is a rework of [Fakerer](https://github.com/artkay/fakerer) (which itself was a fork of [elixirs/faker](https://github.com/elixirs/faker)). It uses `Fakererer.*` module names with the OTP application name `:fakererer`.

- [Fakererer](#fakererer)
  - [Credit](#credit)
  - [Quickstart](#quickstart)
  - [Requirements](#requirements)
  - [Usage](#usage)
  - [Internationalization (i18n)](#internationalization-i18n)
  - [Troubleshooting](#troubleshooting)
  - [Tools](#tools)
  - [Templating](#templating)
  - [Contributing](#contributing)
  - [License](#license)

## Credit

Fakererer stands on the shoulders of the original [Faker](https://github.com/elixirs/faker) library by [Igor Kapkov (@igas)](https://github.com/igas) and contributors, and the [Fakerer](https://github.com/artkay/fakerer) fork by Art Kay. All locale data, generators, and patterns originate from their work. The MIT license is preserved.

## Quickstart

* add the dep to your `mix.exs`:

    ```elixir
    defp deps do
      [
        {:fakererer, "~> 0.2", only: :test}
      ]
    end
    ```

* run:

    ```
    mix deps.get
    ```

* add `Fakererer.start()` to `test/test_helper.exs`:

    ```elixir
    ExUnit.start()
    Fakererer.start()
    ```

* jump to [usage examples](#usage).

### Requirements

* OTP 26+
* Elixir 1.16+

## Usage

See [documentation](http://hexdocs.pm/fakererer/) and [usage examples](https://github.com/manhvu/fakererer/blob/main/USAGE.md).

## Internationalization (i18n)

Fakererer supports multiple locales with Vietnamese (vi) as a first-class citizen.

### Supported Locales

- `:en` - English (default)
- `:vi` - Vietnamese
- `:da` - Danish
- `:es` - Spanish
- `:fr` - French
- `:hy` - Armenian
- `:it` - Italian
- `:pt_br` - Brazilian Portuguese
- `:ru` - Russian
- `:de` - German
- `:pt_pt` - Portuguese
- `:en_us` - US English
- `:en_gb` - British English

### Setting the Locale

```elixir
# Start with a specific locale
Fakererer.start(:vi)

# Or set it at runtime
Fakererer.locale(:vi)
```

### Vietnamese Locale

The Vietnamese locale (`:vi`) provides localized data for:

- **Person**: Vietnamese names (Nguyễn Văn A, Trần Thị B, etc.)
- **Address**: Vietnamese cities, states, street names, zip codes
- **Color**: Vietnamese color names
- **Company**: Vietnamese company prefixes and buzzwords
- **Commerce**: Vietnamese product names and departments
- **Food**: Vietnamese dishes and ingredients
- **Beer**: Vietnamese beer brands
- **Vehicle**: Vehicle makes and models
- **Phone**: Vietnamese phone number formats
- **Cat**: Vietnamese cat names and breeds
- **Industry**: Vietnamese industry sectors

```elixir
Fakererer.start(:vi)

Fakererer.Person.name()
# => "Nguyễn Văn Minh"

Fakererer.Address.city()
# => "Thành phố Hà Nội"

Fakererer.Food.dish()
# => "Phở"
```

## Troubleshooting

* If you get a message like the one below when you call `Fakererer.Address.city/0`,
you need to add `:fakererer` to your application's mix file, in the `applications`
function, as above. (Yes, `:fakererer` - that's both the Hex package name and the OTP
application name.)

    ```
    ** (FunctionClauseError) no function clause matching in Fakererer.Address.city_count/1
    lib/fakererer/address.ex:48: Fakererer.Address.city_count(nil)
    lib/fakererer/address.ex:41: Fakererer.Address.city/0
    ```

## Tools

Fakererer was designed as a lightweight library, that's why it can be easily used
with other tools.

## Templating

You can build templates for testing purposes with the
[Blacksmith](https://github.com/batate/blacksmith) project. See the Blacksmith
[readme](https://github.com/batate/blacksmith#readme) for details.

## Contributing

Contributions are welcome - see [CONTRIBUTING.md](https://github.com/manhvu/fakererer/blob/main/CONTRIBUTING.md).

## [License](https://github.com/manhvu/fakererer/blob/main/LICENSE)

Released under the MIT License.

Original copyright © Igor Kapkov.