Skip to main content

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.

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

Beet plugin

Babelbox can be used as a beet plugin. Here is a example beet project using babelbox:

beet.json
resourcepack
  ⠇
  └╴lang
    └╴item.swords.csv

swords.csv

Swords en_us de_de
gold.name Gold sword Goldschwert

beet.json

{
  "output": "build",
  "resource_pack": {
    "load": ["resourcepack"]
  },
  "pipeline": [
      "babelbox.integration.beet"
  ],
  "meta": {
      "babelbox": {
          "load": ["resourcepack/assets/minecraft/lang"],
          "prefix_identifiers": true
      }
  }
}

Running beet build generates the language files:

beet.json
resourcepack
  ⠇
  └╴lang
    └╴item.swords.csv
build
  ⠇
  └╴lang
    ├╴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 dev environment with invoke:

$ invoke install

Run tests:

$ invoke test

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

Release files for babelbox 2.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for babelbox 2.1.2
File Size Uploaded
babelbox-2.1.2.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for babelbox 2.1.2
File Interpreter ABI Platform
babelbox-2.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.8 kB

Release files / babelbox-2.1.2.tar.gz

Download URL babelbox-2.1.2.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b9e16b78abe0ae60ccbdef494404fd60efa6c3a67913f3069a9437cc3ac3fb01
BLAKE2b-256 checksum
How to use checksums
6fe5b9e2b267ad72cf6d3f614edc476ae64d1725355eb199586d8297df23cb0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

Release files / babelbox-2.1.2-py3-none-any.whl

Download URL babelbox-2.1.2-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc585a50792802360e0d5492176e87142245d17848c6dd0afe2476aa145df654
BLAKE2b-256 checksum
How to use checksums
346d5bf3c633758e19c614de4209e1c4df4bdef2d4d699adb26423a527b79ce3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

Release history Release notifications | RSS feed

This release

2.1.2 This release

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page