playground icon indicating copy to clipboard operation
playground copied to clipboard

Dictionary

Open rezoner opened this issue 10 years ago • 2 comments

Letting you know that I need multi language dictionary for my next game so I am working on one.

Leaving this open for discussion in case you expect some features.

Things so far:

Basic usage


/* dictionary.json */

{ 
  "reportDamage": "Your health is {health}"
}

/* app.js */

app.dictionary("reportDamage", { health: 70 });

> Your health is 70

Tree

{
  "items": {
    "weapon": "bron",
    "shield": "tarcza",
    "armor": "zbroja"
  }
}

app.dictionary("items/shield");

> tarcza

Access object properties

{
  "weaponDescription": "Deals {weapon.damage} damage each {weapon.cooldown} seconds"
}

app.dictionary("weaponDescription", {
  weapon: { damage: 4, cooldown: 6 }
});

> Deals 4 damage each 6 seconds

Self lookup and {nested{tags}}

{tags} are resolved in order from inside to outside

If tag is a slash separated path ex. "{path/to/something}" the tag will be replaced by dictionary entry If tag is a dot separated path ex. "{path.to.something}" the tag will be replaced by replace entry

Hence it is possible to create quite flexible dictionary entries

{
  "descriptions": {
    "weapon": "That is a weapon.",
    "shield": "It is some shield.",
    "armor": "That must be an armor."
  },

  "details": {
    "weapon": "Damage: {damage}"
  }, 

  "look": "Your are looking at the object. {descriptions/{type}} - {details/{type}}"
}

app.dictionary("look", { type: "weapon", "damage": 4 });

> You are looking at the object. That is a weapon. Damage: 4

Pulling random element from dictionary group

If the {tag} path ends with slash it will pull random entry from a group

{

  "insluts": [
    "you rebel scum",
    "you filthy hamster",
    "you worthless bum"
  ],

  "deathWish": "Die, {insults/}"

}

app.dictionary("deathWish");

> Die, you filthy hamster

rezoner avatar Dec 28 '15 12:12 rezoner

First concerns

Path resolving will probably change form from {path/to/entry} to {@path/to/entry} - that is because I want to introduce math mode Your dps is {damage / cooldown} which may also evolve into little less readable but safer form {{damage} / {cooldown}}

That is to give translator as much flexibility as possible (I value mod community more than translators per se)

There is also need for functions like upperCaseFirst()

rezoner avatar Dec 28 '15 15:12 rezoner

I suggest {path.to.entry} instead of {@path/to/entry} or {path/to/entry}

{
  "items": {
    "weapon": "bron",
    "shield": "tarcza",
    "armor": "zbroja"
  }
}

app.dictionary("items.shield");

> tarcza
{
  "weapon": {
    "description": "Deals {item.damage} damage each {item.cooldown} seconds"
  }
}

app.dictionary("weapon.description", {
  item: { damage: 4, cooldown: 6 }
});

> Deals 4 damage each 6 seconds

luizbills avatar Dec 28 '15 17:12 luizbills