kotoba

A lightweight Haxe library for XML-based language configuration and translation management.
https://github.com/MAJigsaw77/kotoba

To install, run:

haxelib install kotoba 1.0.0 

See using Haxelib in Haxelib documentation for more information.

README.md

kotoba

A lightweight Haxe library for XML-based language configuration and translation management.

Installation

Using Haxelib:

haxelib install kotoba

Using Git (for latest changes):

haxelib git kotoba https://github.com/MAJigsaw77/kotoba.git

How It Works

Kotoba loads translation files defined in a config.xml. You can organize your folders however you like — just make sure Kotoba.initialize(path) points to the directory containing config.xml, and the config lists your language folders and file IDs.

Example File Structure

assets/
└── translations/
	├── config.xml
	├── en-US/
	│   └── example_file.xml
	└── ro-RO/
		└── example_file.xml

config.xml

<kotoba-config>
	<file id="example_file" />
	<language name="en-US" />
	<language name="ro-RO" />
</kotoba-config>

🇺🇸 en-US/example_file.xml

<kotoba-file>
	<string key="example_id" value="You earned $money!" />
</kotoba-file>

🇷🇴 ro-RO/example_file.xml

<kotoba-file>
	<string key="example_id" value="Ai câștigat $money lei!" />
</kotoba-file>

Usage

import kotoba.Kotoba;
import kotoba.KotobaLoader;
import kotoba.KotobaReplacer;

import sys.FileSystem;
import sys.io.File;

class Main
{
	public static function main():Void
	{
		// Hook Kotoba into your file loading logic
		KotobaLoader.exists = FileSystem.exists;
		KotobaLoader.getContent = File.getContent;

		// Choose a language
		Kotoba.language = 'ro-RO';

		// Load translations from folder
		Kotoba.initialize('assets/translations');

		// Fetch and format a translated string
		final raw:String = Kotoba.getString('example_file', 'example_id', 'Fallback text');

		final result:String = KotobaReplacer.replace(raw, { money: 20 });

		trace(result); // → Ai câștigat 20 lei!
	}
}

License

kotoba is released under the MIT License. See LICENSE for details.

Contributors
MAJigsaw77
Version
1.0.0
Published
1 year ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub