Open damienalexandre opened 8 years ago
Im.. But what if you have keys like
navigation.dropdown.rent.0
navigation.dropdown.rent.1
navigation.dropdown.rent.2
Wouldn't that break everything? Or are we sure that that will return string "0", "1" and "2"?
Also, if it not too much to ask, would you mind adding a small test for that function?
I tried a bit more, and this is heavier than I thought, JSON and YML are just not up to the task :cry:
Here is what Loco respond with JSON and YML:
{
"navigation": {
"dropdown": {
"home": "Home",
"rent": {
"all_furnished": "All furnished rentals",
"luxury": "Luxury rentals",
"0": "Rentals",
"by_district": "Apartments by district",
"renting": "Renting in Paris",
"services": "Services and fees",
"more": "More informations"
}
}
},
"test": "<p>test<\/p>\n<p>qsd<\/p>\n<p>qsd<\/p>\n<p>qsd<\/p>\n<p> <\/p>"
}
If I use INI, it's much better, no extra stuffs are added to my keys:
;; Loco php export: INI file (Symfony style)
;; Release: Working copy
;; Locale: en-GB,
;; Status: Translated
;; Exported by: Damien A
;; Exported at: Tue, 08 Mar 2016 17:23:40 +0000
navigation.dropdown.home = "Home"
navigation.dropdown.rent.all_furnished = "All furnished rentals"
navigation.dropdown.rent.luxury = "Luxury rentals"
navigation.dropdown.rent = "Rentals"
navigation.dropdown.rent.by_district = "Apartments by district"
navigation.dropdown.rent.renting = "Renting in Paris"
navigation.dropdown.rent.services = "Services and fees"
navigation.dropdown.rent.more = "More informations"
test = "<p>test</p>
<p>qsd</p>
<p>qsd</p>
<p>qsd</p>
<p> </p>"
We need to ditch JSON for this API, or tell Loco to stop trying to "unflatten" translation keys, I didn't any option for this in the API. You are right about this PR we can't merge it like this.
I started adding tests, but it doesn't help (oh goes puli is such a pain, it's needed when installing httplug/mock client...).
I would like to include @timwhitlock here. What is your input? Should we start using .INI files instead?
You can avoid key folding by dropping the ?format=symfony
parameter. The default Yaml output is full keys like the INI example. (Be aware that generic Yaml output won't convert Loco plural forms into Symfony's plural syntax)
To avoid key folding in JSON you can specify format=script
. (This isn't documented as such) It's asking Loco to export JSON for use in JavaScript. Hence no folding. (Again the same point as above that output won't be Symfony specific).
When having keys like this:
Loco return a response like this:
One of the keys is zero, and my translation file is populated with
navigation.dropdown.rent.0
.This PR fix this issue.