Crates.io | nile-library |
lib.rs | nile-library |
version | 0.3.0 |
source | src |
created_at | 2024-04-25 17:54:47.166905 |
updated_at | 2024-05-02 18:35:33.407798 |
description | Library supporting nile |
homepage | |
repository | |
max_upload_size | |
id | 1220609 |
size | 135,076 |
This repository contains the library that supports OpenTTD's translation tool nile
.
This library for example validates if a translation is valid for a given base-string, and converts base-strings into a translatable form.
Have Rust installed.
For easy local development:
cargo run -- <base>
cargo run -- <base> <translation>
It will output the normalized string form, and whether the string is valid; and if not, what was wrong with it.
This tool also integrates with WASM, so validation can be done from any website. For this wasm-pack is used.
wasm-pack build --release
API method:
fn validate_base(config: LanguageConfig, base: String) -> ValidationResult
Input:
config.dialect
: One of openttd
, newgrf
, game-script
.config.cases
: Empty for base language.config.genders
: Empty for base language.config.plural_count
: 2
for base language.base
: Base string to validateOutput:
errors
: List of errors. If this is not empty, the string should not be offered to translators.normalized
: The normalized text to display to translators.
RAW_STRING
, STRING5
, ... are replaced with STRING
.Example:
>>> cargo run "{BLACK}Age: {LTBLUE}{STRING2}{BLACK} Running Cost: {LTBLUE}{CURRENCY}/year"
ERROR at position 61 to 71: Unknown string command '{CURRENCY}'.
>>> cargo run "{BLACK}Age: {LTBLUE}{STRING2}{BLACK} Running Cost: {LTBLUE}{CURRENCY_LONG}/year"
NORMALIZED:{BLACK}Age: {LTBLUE}{0:STRING}{BLACK} Running Cost: {LTBLUE}{1:CURRENCY_LONG}/year
LanguageConfig
to test for this, but it is not exported yet.API method:
fn validate_translation(config: LanguageConfig, base: String, case: String, translation: String) -> ValidationResult
Input:
config.dialect
: One of openttd
, newgrf
, game-script
.config.cases
: case
from nile-config
.config.genders
: gender
from nile-config
.config.plural_count
: Number of plural forms from nile-config
.base
: Base string the translation is for.case
: Case for the translation. Use "default"
for the default case.translation
: The text entered by the translator.Output:
errors
: List of errors.
severity
: Severity of the error.
error
: The translation is broken, and must not be committed to OpenTTD.warning
: The translation is okay to commit, but translators should fix it anyway. This is used for new validations, which Eints did not do. So there are potentially lots of existing translations in violation.position
: Byte position in input string. None
, if general message without location.message
: Error message.suggestion
: Some extended message with hints.normalized
: The normalized text to committed. In the normalized text, trailing whitespace and other junk has been removed.Example:
>>> cargo run "{BLACK}Age: {LTBLUE}{STRING2}{BLACK} Running Cost: {LTBLUE}{CURRENCY_LONG}/year" "{BLUE}Alter: {LTBLUE}{STRING}{BLACK} Betriebskosten: {LTBLUE}{0:CURRENCY_LONG}/Jahr"
ERROR at position 61 to 78: Duplicate parameter '{0:CURRENCY_LONG}'.
ERROR at position 61 to 78: Expected '{0:STRING2}', found '{CURRENCY_LONG}'.
ERROR: String command '{1:CURRENCY_LONG}' is missing.
WARNING: String command '{BLUE}' is unexpected. HINT: Remove this command.
>>> cargo run "{BLACK}Age: {LTBLUE}{STRING2}{BLACK} Running Cost: {LTBLUE}{CURRENCY_LONG}/year" "{BLACK}Alter: {LTBLUE}{STRING}{BLACK} Betriebskosten: {LTBLUE}{CURRENCY_LONG}/Jahr"
NORMALIZED:{BLACK}Alter: {LTBLUE}{0:STRING}{BLACK} Betriebskosten: {LTBLUE}{1:CURRENCY_LONG}/Jahr