League-of-Foundry-Developers / torch

Simple torch module for Foundry VTT
10 stars 20 forks source link

Issue with translating light source name in a JSON file into another language #78

Closed Yatomeru closed 2 months ago

Yatomeru commented 5 months ago

• The essence of the problem is in the JSON file : original name of the file is torch, candle, but in my case it is “translated'' into a Russian language and looks something like this: “Факел / Torch”

Main question: How do I write the light sources names in the JSON file, since apparently the module only sees the files when they are written as they are on my system.

• Since the module itself with my JSON file refuses to see my lanterns, candles, lamps, etc. although they are in my inventory. The problem can be solved if I manually type in "inventory item name to use", but this will get you to the only one light source that it can see, but not the others, since '','' and ''|'' don't work for additional names that i add in a certain section.

Example:

https://github.com/League-of-Foundry-Developers/torch/assets/168934039/723e225e-1737-474a-b837-95df235d624c

• As an example, I'll send my JSON with the names of the torch, candle, etc. translated into another language [ RU ] next to the original file name, since that’s how they are written in my system.

• Perhaps everything is much simpler here, and I just need additional '']'' and ''}'' in my JSON, which I missed.

From the ''custom light source'' I added only the ghost torch.

{
    "dnd5e":   {
        "system": "dnd5e",
        "topology": "standard",
        "quantity": "quantity",
        "aliases": {
          "Фонарь / Lantern, (Обычный / Hooded)": "Фонарь обычный / Hooded Lantern",
          "Фонарь / Lantern, (Потайной / Bullseye)": "Фонарь потайной / Bullseye Lantern"
        },
        "sources": {
            "Свеча / Candle": {
                "name": "Свеча / Candle",
                "type": "equipment",
                "consumable": true,
                "states": 2,
                "light": [
                { 
                  "bright": 5, "dim": 10, "angle": 360, "color": "#91925d", "alpha": 0.5,
                  "animation": { "type": "Свеча / Candle", "speed": 5, "intensity": 5, "reverse": false } 
                ]
            },
            "Факел / Torch": {
                "name": "Факел / Torch",
                "type": "equipment",
                "consumable": true,
                "states": 2,
                "light": [
                {
                  "bright": 20, "dim": 40, "angle": 360, "color": "#a2642a", "alpha": 0.5,
                  "animation": { "type": "Факел / Torch", "speed": 5, "intensity": 5, "reverse": false }
                ]
            },
            "Призрачный Факел / Ghost Torch": {
                "name": "Призрачный Факел / Ghost Torch",
                "type": "equipment",
                "consumable": true,
                "states": 2,
                "light": [
                {  
                  "bright": 20, "dim": 40, "angle": 360, "color": "#91a4b6", "alpha": 0.5,
                  "animation": { "type": "Призрачный Факел / Ghost Torch", "speed": 5, "intensity": 5, "reverse": false }
                ]
            },
            "Создание пламени / Produce Flame": {
                "name": "Создание пламени / Produce Flame",
                "type": "cantrip",
                "consumable": false,
                "states": 2,
                "light": [
                {                    
                  "bright": 10, "dim": 20, "angle": 360, "color": "#c27a29", "alpha": 0.5,
                  "animation": { "type": "Создание пламени / Produce Flame", "speed": 5, "intensity": 5, "reverse": false }
                ]
            },
            "Лампа / Lamp": {
                "name": "Лампа / Lamp",
                "type": "equipment",
                "consumable": false,
                "states": 2,
                "light": [
                {
                  "bright": 15, "dim": 45, "angle": 360, "color": "#bea23c", "alpha": 0.5,
                  "animation": { "type": "Лампа / Lamp", "speed": 5, "intensity": 5, "reverse": false }
                ]
            },
            "Фонарь потайной / Bullseye Lantern": {
                "name": "Фонарь потайной / Bullseye Lantern",
                "type": "equipment",
                "consumable": false,
                "states": 2,
                "light": [
                {
                  "bright": 15, "dim": 45, "angle": 360, "color": "#776113", "alpha": 0.5,
                  "animation": { "type": "Фонарь потайной / Bullseye Lantern", "speed": 5, "intensity": 5, "reverse": false }
                ]
            },
            "Фонарь обычный / Hooded Lantern": {
                "name": "Фонарь обычный / Hooded Lantern",
                "type": "equipment",
                "consumable": false,
                "states": 2,
                "light": [
                {
                  "bright": 15, "dim": 45, "angle": 360, "color": "#b2921f", "alpha": 0.5,
                  "animation": { "type": "Фонарь обычный / Hooded Lantern", "speed": 5, "intensity": 5, "reverse": false }
                ]
            },
            "Призрачный фонарь / Ghost Lantern": {
                "name": "Призрачный фонарь / Ghost Lantern",
                "type": "equipment",
                "consumable": false,
                "states": 2,
                "light": [
                {
                  "bright": 15, "dim": 45, "angle": 360, "color": "#abcae8", "alpha": 0.5,
                  "animation": { "type": "Призрачный фонарь / Ghost Lantern", "speed": 5, "intensity": 5, "reverse": false }
                ]
            },
            "Фонарь отслеживания / Lantern of Tracking": {
                "name": "Фонарь отслеживания / Lantern of Tracking",
                "type": "equipment",
                "consumable": false,
                "states": 2,
                "light": [
                {
                  "bright": 15, "dim": 45, "angle": 360, "color": "#6db05e", "alpha": 0.5,
                  "animation": { "type": "Фонарь отслеживания / Lantern of Tracking", "speed": 5, "intensity": 5, "reverse": false }
                ]
            },
            "Фонарь разоблачения / Lantern of Revealing": {
                "name": "Фонарь разоблачения / Lantern of Revealing",
                "type": "equipment",
                "consumable": false,
                "states": 2,
                "light": [
                {
                  "bright": 15, "dim": 45, "angle": 360, "color": "#90ddfe", "alpha": 0.5,
                  "animation": { "type": "Фонарь разоблачения / Lantern of Revealing", "speed": 5, "intensity": 5, "reverse": false }
                ]
            } 
          ]
        }
      }
   }
}
lupestro commented 5 months ago

One trick to use to make sure JSON is correctly formed is to drag your file into Firefox - if the syntax is bad, it will give errors with line numbers. I use this both in my gaming and at work all the time.

As I had originally imagined when I added the alias capability, the sources.json would be left in the original source language and the alias list for localization would be applied to the original sources. This would be something like:

{
  "dnd5e": {
    "system": "dnd5e",
    "aliases": {
      "Свеча": "Candle",
      "Фонарь обычный": "Hooded Lantern",
      ... etc ...
    }
  }
}

Since it contains only a single system and aliases for its light sources, a localization json would be relatively short. Then torch would apply the same light settings to items with either name.

original name of the file is torch, candle, but in my case it is “translated'' into a Russian language and looks something like this: “Факел / Torch”

So, if I understand correctly, you have set the names of the items in the compendia or in local item definitions dragged onto characters to use the hybrid names? If so, the same use of the hybrid names in aliases would apply here as I just showed for the pure Russian names:

{
  "dnd5e": {
    "system": "dnd5e",
    "aliases": {
      "Свеча / Candle": "Candle",
     "Фонарь обычный / Hooded Lantern": "Hooded Lantern",
      ... etc ...
    }
  }
}

All of that is for the case where the only concern is for localization. Here, I can see that you've also applied fresh lighting with custom animations, etc. For this, as you have already done, you can supply the hybrid names as new light sources with all their settings and without reference to the originals. So what you did should have worked.

So, next step, I just brought your JSON up in VS Code and used the intellisense to look for problems. Besides a few spare close braces on the bottom, you had one pattern that consistently missed a close brace before the close square bracket:

               "light": [
                {
                  "bright": 15, "dim": 45, "angle": 360, "color": "#6db05e", "alpha": 0.5,
                  "animation": { "type": "Фонарь отслеживания / Lantern of Tracking", "speed": 5, "intensity": 5, "reverse": false }
                ]

The following corrected those:

                "light": [
                    {
                    "bright": 15, "dim": 45, "angle": 360, "color": "#6db05e", "alpha": 0.5,
                    "animation": { "type": "Фонарь отслеживания / Lantern of Tracking", "speed": 5, "intensity": 5, "reverse": false }
                    }
                ]

Here's the corrected JSON. See if it does what you want. Let me know if it works out, but especially let me know if there turns out to be a problem, as this is really supposed to work.

{
    "dnd5e":   {
        "system": "dnd5e",
        "topology": "standard",
        "quantity": "quantity",
        "aliases": {
          "Фонарь / Lantern, (Обычный / Hooded)": "Фонарь обычный / Hooded Lantern",
          "Фонарь / Lantern, (Потайной / Bullseye)": "Фонарь потайной / Bullseye Lantern"
        },
        "sources": {
            "Свеча / Candle": {
                "name": "Свеча / Candle",
                "type": "equipment",
                "consumable": true,
                "states": 2,
                "light": [
                    { 
                    "bright": 5, "dim": 10, "angle": 360, "color": "#91925d", "alpha": 0.5,
                    "animation": { "type": "Свеча / Candle", "speed": 5, "intensity": 5, "reverse": false } 
                    }
                ]
            },
            "Факел / Torch": {
                "name": "Факел / Torch",
                "type": "equipment",
                "consumable": true,
                "states": 2,
                "light": [
                    {
                    "bright": 20, "dim": 40, "angle": 360, "color": "#a2642a", "alpha": 0.5,
                    "animation": { "type": "Факел / Torch", "speed": 5, "intensity": 5, "reverse": false }
                    }
                ]
            },
            "Призрачный Факел / Ghost Torch": {
                "name": "Призрачный Факел / Ghost Torch",
                "type": "equipment",
                "consumable": true,
                "states": 2,
                "light": [
                    {  
                    "bright": 20, "dim": 40, "angle": 360, "color": "#91a4b6", "alpha": 0.5,
                    "animation": { "type": "Призрачный Факел / Ghost Torch", "speed": 5, "intensity": 5, "reverse": false }
                    }
                ]
            },
            "Создание пламени / Produce Flame": {
                "name": "Создание пламени / Produce Flame",
                "type": "cantrip",
                "consumable": false,
                "states": 2,
                "light": [
                    {                    
                        "bright": 10, "dim": 20, "angle": 360, "color": "#c27a29", "alpha": 0.5,
                        "animation": { "type": "Создание пламени / Produce Flame", "speed": 5, "intensity": 5, "reverse": false }
                    } 
                ]
            },
            "Лампа / Lamp": {
                "name": "Лампа / Lamp",
                "type": "equipment",
                "consumable": false,
                "states": 2,
                "light": [
                    {
                        "bright": 15, "dim": 45, "angle": 360, "color": "#bea23c", "alpha": 0.5,
                        "animation": { "type": "Лампа / Lamp", "speed": 5, "intensity": 5, "reverse": false }
                    }
                ]
            },
            "Фонарь потайной / Bullseye Lantern": {
                "name": "Фонарь потайной / Bullseye Lantern",
                "type": "equipment",
                "consumable": false,
                "states": 2,
                "light": [
                    {
                    "bright": 15, "dim": 45, "angle": 360, "color": "#776113", "alpha": 0.5,
                    "animation": { "type": "Фонарь потайной / Bullseye Lantern", "speed": 5, "intensity": 5, "reverse": false }
                    }
                ]
            },
            "Фонарь обычный / Hooded Lantern": {
                "name": "Фонарь обычный / Hooded Lantern",
                "type": "equipment",
                "consumable": false,
                "states": 2,
                "light": [
                    {
                    "bright": 15, "dim": 45, "angle": 360, "color": "#b2921f", "alpha": 0.5,
                    "animation": { "type": "Фонарь обычный / Hooded Lantern", "speed": 5, "intensity": 5, "reverse": false }
                    }
                ]
            },
            "Призрачный фонарь / Ghost Lantern": {
                "name": "Призрачный фонарь / Ghost Lantern",
                "type": "equipment",
                "consumable": false,
                "states": 2,
                "light": [
                    {
                    "bright": 15, "dim": 45, "angle": 360, "color": "#abcae8", "alpha": 0.5,
                    "animation": { "type": "Призрачный фонарь / Ghost Lantern", "speed": 5, "intensity": 5, "reverse": false }
                    }
                ]
            },
            "Фонарь отслеживания / Lantern of Tracking": {
                "name": "Фонарь отслеживания / Lantern of Tracking",
                "type": "equipment",
                "consumable": false,
                "states": 2,
                "light": [
                    {
                    "bright": 15, "dim": 45, "angle": 360, "color": "#6db05e", "alpha": 0.5,
                    "animation": { "type": "Фонарь отслеживания / Lantern of Tracking", "speed": 5, "intensity": 5, "reverse": false }
                    }
                ]
            },
            "Фонарь разоблачения / Lantern of Revealing": {
                "name": "Фонарь разоблачения / Lantern of Revealing",
                "type": "equipment",
                "consumable": false,
                "states": 2,
                "light": [
                    {
                    "bright": 15, "dim": 45, "angle": 360, "color": "#90ddfe", "alpha": 0.5,
                    "animation": { "type": "Фонарь разоблачения / Lantern of Revealing", "speed": 5, "intensity": 5, "reverse": false }
                    }
                ]
            } 
        }
    }
}
Yatomeru commented 5 months ago

Corrected JSON file that you sent at the last message works! Thank you!

image

''One trick to use to make sure JSON is correctly formed is to drag your file into Firefox - if the syntax is bad, it will give errors with line numbers. I use this both in my gaming and at work all the time.''

Thanks for the tip about this, didn't know about it.

So, next step, I just brought your JSON up in VS Code and used the intellisense to look for problems. Besides a few spare close braces on the bottom, you had one pattern that consistently missed a close brace before the close square bracket:

thanks again! classic code issues as usual x)

So, if I understand correctly, you have set the names of the items in the compendia or in local item definitions dragged onto characters to use the hybrid names? If so, the same use of the hybrid names in aliases would apply here as I just showed for the pure Russian names:

Youre correct on that one! I set the file names in the compendia in the format : [Russian name / original name], to be honest this is a module and not translated by myself and this module adds translations to files according to the original source, but it replaces the original names, so I corrected it a little, but I didn’t notice a slightly incorrect [Ru] translation in the module itself until a certain point. Like for example in this ''translated version of names'' - Hooded Lantern translated as Фонарь обычный which mean in [Ru] language Normal Lantern and correct version will be Скрытый Фонарь, another one Bullseye Lantern which translated as Потайной Фонарь which is [ this is funny ] Hooded lantern and the correct translate will be Луч направленного света a little bit long and not 100% accurate word for word but Bullseye is a word play and Фонарь направленного света will be a neater and nicer sounding version of the original title in [EN] it will be something like Directional Light Lantern.

lupestro commented 4 months ago

@Yatomeru I have done some work to make it easier to provide working additional light source JSON in Torch 2.13.0. I think it accomplishes what you were looking for when you raised this issue. Let me know if this looks like something that would have made this process easier or if there's something more it needs.

In the interest of avoiding tickets remaining open indefinitely, if I don't hear from you in a couple of weeks I will close this ticket.