Open TheRealSeber opened 1 month ago
No, such functionality doesn't exist in Paraglide JS but isn't the $json
function just JSON.parse()
?
JSON.parse(message)
Example message that stores a JSON as string
blue_moon = '[{ iconName, title, description }]'
Calling the message and parse it as json
const features = JSON.parse(m.blue_moon())
for (const feature of features) {
feature.iconName
feature.title
// ...
}
Oh well, if that's just gonna work, then that's fair enough. However I think that it would be nice to have
thing as storing json values as strings is not pretty. Idk tho how everything works under the hood, so can't tell if it's even possible for you to add it.
A utility function could surely be added, but I am wary of implications in an end-to-end localization process.
If the workaround works, can you close the issue for now?
Reopening the issue as the workaround doesn't work @samuelstroschein
e.g. message snippet I used: "landing_page_features": "[{\"title\":\"Reliability and Security\",\"iconName\":\"shieldIcon\",\"description\":\"We prioritize (...)
Output function of paraglide js after compilation:
It makes sence as paraglide expects for the data in {}
to be a parameter
Yep certainly so. Good catch.
Small clarification: Paraglide JS compiles what a plugin imported. Hence, it's the message format plugin which interprets {}
as variable expressions. Expressions that Paraglide compiles.
I recommend to split the json properties into messages e.g. landing_page_feature_title
, landing_page_feature_icon_name
, etc.
Updating the message format plugin or Paraglide JS does not make sense atm as both are on a new major version in the dev branch waiting for lix 1.0 to be released.
Hey,
I am just curious if such functionalty as this exists in the paraglide-js
I would be interested in storing JSON structures which change dependingly on the language of course. Example use case:
Assuming I have
10
or more features seems to be pointless for me to store everyfeature
as standalone string