I want to localize a json object by variable. For this I want to insert a html given variable into a json path as string.
I have a json file with a list of actors
"actors":{
"Pete":{
"status": "dead",
},
"Anna":{
"status": "alive",
},
"Hans":{
"status": "alive",
},
"Fred":{
"status": "somewhat alive",
}}
This file is used for foundryvtt as language file.
Now I want to access the data of the users by using the json path with their html handlebar.
{{localize 'actors.Pete.status'}}
which pushes the json path as string to a method which returns the json element.
This works perfectly and outputs: dead
Now I am trying to input a variable into the path. Which would look something like this:
{{localize 'actors.Variable.status'}}
My problem is, that the Variable is called similar as the json element:
{{user.name}}
which would output one of the names in the list, of course inputting this directly into the handlebar doesn't work.
{{localize 'actors.{{user.name}}.status'}}
I would love a simple and lightweight solution to this problem. Or some comments on my solution ;)
At the moment I am using some script with their java handlebar.
<input id="lan-name" name="name" type="text" value= "{{user.name}}" placeholder="Missing Translation for {{user.name}}"/>
<script>
document.getElementById("lan-name").value = game.i18n.localize("actors.{{user.name}}.status");
</script>
But I only analyse code patterns and barely understand them. Happy about any comments and pointers. Thanks in advance :D