Reputation: 2894
I'm using a .json file to hold font/text information for an application. Now that I'm adding different languages I need to be able to specify different sizes for certain fonts due to the varying sizes of the words in that language for example German words tend to be longer than English, so I might want a smaller font.
My problem is that there will be a ton of duplicate data in my .json file, as most fonts will remain the same for each language. Here's an example of the duplicate data that I want to reduce somehow, I just don't know how to format my .json file to do so (note that I've stripped out a lot of details so this will read easier):
"styles":
{
"en":
{
"main_title" :
{
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 18,
},
},
"de":
{
"main_title" :
{
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 16,
},
},
"fr":
{
"main_title" :
{
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 18,
},
}
}
Notice that in the above example that I have three languages, and all use identical font information with the exception of deutsche using a smaller "heading" font. What I'd like to do is something like this:
"styles":
{
"en", "de", "fr":
{
"main_title" :
{
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 18,
},
},
"de":
{
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 16,
},
},
}
In this example I have all three languages use the same information, but am able to define one change in the deutsche language font. Obviously my second example won't read properly because it's not correct syntax, but hopefully this gets across what I'm trying to achieve. Is there any syntax in JSON that will allow me to do something like this?
Upvotes: 0
Views: 466
Reputation: 1686
I don't believe that JSON will do this, but you could have a 'default' object which consumers of this data can look at for any values missing from other language objects:
"styles": {
"default": {
"main_title" : {
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" : {
"font" : "font://verdana-bold.ttf",
"size" : 18,
},
},
"de": {
"heading" : {
"size" : 16,
}
}
}
If you need to specify which languages are permissible, just add that as another attribute on the object:
"styles": {
"languages": ["en", "de", "fr"],
...
}
Upvotes: 1