Happyr / TranslationBundle

[DEPRECATED] A bundle to integrate with third party translation platforms
MIT License
50 stars 22 forks source link

Handle hierarchy parent in flattening Loco resp #27

Open damienalexandre opened 8 years ago

damienalexandre commented 8 years ago

When having keys like this:

navigation.dropdown.rent
navigation.dropdown.rent.service
navigation.dropdown.rent.luxury

Loco return a response like this:

image

One of the keys is zero, and my translation file is populated with navigation.dropdown.rent.0.

This PR fix this issue.

Nyholm commented 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?

damienalexandre commented 8 years ago

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>&nbsp;<\/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>&nbsp;</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...).

Nyholm commented 8 years ago

I would like to include @timwhitlock here. What is your input? Should we start using .INI files instead?

timwhitlock commented 8 years ago

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)

timwhitlock commented 8 years ago

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).