Skip to content

Handle hierarchy parent in flattening Loco resp #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

damienalexandre
Copy link
Contributor

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
Copy link
Member

Nyholm commented Mar 8, 2016

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
Copy link
Contributor Author

I tried a bit more, and this is heavier than I thought, JSON and YML are just not up to the task 😢

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
Copy link
Member

Nyholm commented Mar 21, 2016

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

@timwhitlock
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants