Skip to main content

A language localization generator for Minecraft

Project description

Code style: black

Babelbox

Babelbox allows you to write your language files in .csv files and then generate Minecraft language.json files from them.
Creating translations in CSV gives you an easy overview over any errors or missing translations.

Table of contents

Installation

$ pip install babelbox

Usage

Reads translations from all sources and then generates minecraft language files for all language codes

$ # Single .csv file source
$ babelbox <file.csv>
$ # Directory containing .csv files as source
$ babelbox <directory>
$ # Multiple sources require output directory
$ babelbox <file1.csv> <directory> <file2.csv> -o <output_dir>

All options:

$ babelbox SOURCES...
    -o, --out                   The output directory of the generated files
    -p, --prefix-identifiers    Prefix identifiers with their path relative
                                to their SOURCES entry
    --dialect [excel|excel-tab|unix]
                                CSV dialect used to parse CSV. Dialect will
                                be automatically detected of omitted
    -d, --delimiter             CSV delimiter overwrite
    --quotechar                 CSV quote char overwrite
    -m, --minify                Minify generated files
    -i, --indent                Indentation used when generating files
    --dry                       Dry run. Don not generate any files
    -v, --verbose               Increase verbosity
    -q, --quiet                 Only output errors

Getting started

Single file source:

We have one .csv file containing translations:

resourcepack
⠇
└╴lang
  └╴ items.csv
Item en_us de_de
item.stick.name stick Stock
# You can create comments like this
item.snowball.name snowball Schneeball

Passing items.csv as a source to babelbox generates the language files en_us.json and de_de.json:

$ babelbox resourcepack/.../lang/items.csv
en_us.json
{
    "item.stick.name": "stick",
    "item.snowball.name": "snowball",
}

de_de.json
{
    "item.stick.name": "Stock",
    "item.snowball.name": "Schneeball",
}
resourcepack
⠇
└╴lang
  ├╴ items.csv
  ├╴ en_us.json
  └╴ de_de.json

Directory source

We have two .csv files containing translations:

resourcepack
⠇
└╴lang
  ├╴ items.csv
  └╴ blocks.csv

items.csv

Item en_us de_de
item.stick.name stick Stock

blocks.csv

Block en_us de_de
block.log.name log Holzstamm

Passing the lang directory as a source to babelbox generates the language files en_us.json and de_de.json:

$ babelbox resourcepack/.../lang
en_us.json
{
    "item.stick.name": "stick",
    "block.log.name": "log",
}

de_de.json
{
    "item.stick.name": "Stock",
    "block.log.name": "Holzstamm",
}
resourcepack
⠇
└╴lang
  ├╴ items.csv
  ├╴ blocks.csv
  ├╴ en_us.json
  └╴ de_de.json

Shorten variable names:

We can use the --prefix-identifiers flag to save ourselve some typing. If all identifiers share a common prefix, we can name the file to that prefix and let Babelbox prepend it.

resourcepack
⠇
└╴lang
  └╴ item.swords.csv
Swords en_us de_de
diamond.name Diamond Sword Diamantschwert
gold.name Gold sword Goldschwert
$ babelbox resourcepack/.../lang --prefix-identifiers
$ # Or abbreviated
$ babelbox resourcepack/.../lang -p
en_us.json
{
    "item.swords.diamond.name": "Diamond Sword",
    "item.swords.gold.name": "Gold sword",
}

de_de.json
{
    "item.swords.diamond.name": "Diamantschwert",
    "item.swords.gold.name": "Goldschwert",
}

All identifiers have been prefixed with item.swords.

Organize translations in folders

We can save ourselves even more typing and organize our translations files in a directory structure:

resourcepack
⠇
└╴lang
  ├╴ item
  │  └╴ swords.csv
  └╴ block
     └╴ heavy.csv

swords.csv

Swords en_us de_de
gold.name Gold sword Goldschwert

heavy.csv

Heavy Blocks en_us de_de
lead.name Lead Block Bleiblock
$ babelbox resourcepack/.../lang -p
en_us.json
{
    "item.swords.gold.name": "Gold sword",
    "block.heavy.lead.name": "Lead Block",
}

de_de.json
{
    "item.swords.gold.name": "Goldschwert",
    "block.heavy.lead.name": "Bleiblock",
}
resourcepack
⠇
└╴lang
  ├╴ item
  │  └╴ swords.csv
  ├╴ block
  │   └╴ heavy.csv
  ├╴ en_us.json
  └╴ de_de.json

Contributing

Contributions are welcome. Make sure to first open an issue discussing the problem or the new feature before creating a pull request. The project uses poetry. Setup automatically with invoke or manualy with poetry:

$ # Either
$ invoke install
$ # or
$ poetry install

You can run test with pytest:

$ poetry run pytest

The project follows black codestyle. Import statements are sorted with isort. Code formatting and type checking is enforced using pre-commit.

$ pre-commit install

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

babelbox-2.1.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

babelbox-2.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file babelbox-2.1.0.tar.gz.

File metadata

  • Download URL: babelbox-2.1.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Linux/5.4.0-1040-azure

File hashes

Hashes for babelbox-2.1.0.tar.gz
Algorithm Hash digest
SHA256 47f86f24ef055552a21248eed4fa418a8a031b8a4fa7d8a0a83c6ecbc3fe40c8
MD5 8f465e18573b6668d84b8a555fe9ab6f
BLAKE2b-256 9fc1c47701fb2969721993d3aa7b9b1dc107b5b9ad0084588248a8bc29ea5cc5

See more details on using hashes here.

File details

Details for the file babelbox-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: babelbox-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Linux/5.4.0-1040-azure

File hashes

Hashes for babelbox-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 384d49740851661d6dd7fd288455dffe72581b54a0b45f697f7702f139029a0d
MD5 c58bf89dd8defc4c767c2a9bf9f20df0
BLAKE2b-256 5c43ea30667044ef8874de02ddb2ed581b993fee801e971a27012a7c51d2d1c7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page