Skip to content
This repository has been archived by the owner on Aug 1, 2019. It is now read-only.

Handle document URLs with no lang param #204

Closed
asaunier opened this issue Feb 26, 2016 · 4 comments · Fixed by #558
Closed

Handle document URLs with no lang param #204

asaunier opened this issue Feb 26, 2016 · 4 comments · Fixed by #558

Comments

@asaunier
Copy link
Member

In v5 documents [1] may contain other document URLs with no lang parameter (only the doc type and the doc id) [2].

Such URLs redirect to the "most appropriate" lang version (depending on the lang prefs and the available lang versions). A similar behaviour is needed in v6.

By the way document URLs should contain slugs (but the current version with no slug should also work). See #109

[1] for instance http://www.camptocamp.org/summits/37355/fr/mont-blanc
[2] for instance http://www.camptocamp.org/routes/55289

@tsauerwein
Copy link
Member

From the API this should already be ok: If a language is given as parameter, associated documents include the "best" language.

@asaunier
Copy link
Member Author

When such a URL is called, we would need to make a request to the API to get the list of available lang for the given document and make a 301 "Moved permanently" redirection to the URL with the most appropriate lang (+ slug). If there's only one lang available, the choice is easy. If several, we would take the priority listed here https://github.com/c2corg/v6_common/blob/master/c2corg_common/attributes.py#L2
Makes sense? Feasible?

@tsauerwein
Copy link
Member

This works already. For example when you request /waypoints/38575?l=fr, associations will include the French translation or the 2nd "best" translation.

{
  "waypoint_type": "summit",
  "associations": {
    "waypoints": [...],
    "recent_outings": {
      "total": 27,
      "outings": [{
        "locales": [{
          "lang": "fr",                         <-- outing in french
          "version": 1,
          "title": "Aiguilles de Chamonix (et envers des aiguilles)\u00a0: Travers\u00e9e des Aiguilles de Chamonix S-N"
        }],
        "activities": ["mountain_climbing"],
        "version": 1,
        "date_start": "2014-07-16",
        "author": {
          "user_id": 4960,
          "username": "pgatta"
        },
        "document_id": 543208,
        "date_end": "2014-07-16",
        "available_langs": null
      }, {
        "locales": [{
          "lang": "en",                    <-- outing in the 2nd best locale
          "version": 1,
          "title": "Aiguilles de Chamonix: Travers\u00e9e des Aiguilles de Chamonix S-N"
        }],
        "activities": ["mountain_climbing"],
        "version": 1,
        "date_start": "2010-07-26",
        "author": {
          "user_id": 230990,
          "username": "nielsvanveen"
        },
        "document_id": 231002,
        "date_end": "2010-07-26",
        "available_langs": null
      }, ..
      ]
    },
   ...
  "document_id": 38575
}

@tsauerwein
Copy link
Member

As discussed with @asaunier: When calling /{document_type}/{document_id} (without lang, for example /waypoints/123), a redirect should be made to the best locale. On the UI server-side, a request is made to the API to get the available locales for a document (such web-service has to be added to the API). Then using the cookie which contains the interface language, the best locale is chosen and a redirect to e.g. /waypoints/123/fr/slug is made.

To avoid problems with Varnish, this view is not cached.

@fjacon fjacon added this to the Alpha 2 milestone Jul 25, 2016
@asaunier asaunier mentioned this issue Aug 11, 2016
4 tasks
@fjacon fjacon modified the milestones: Alpha 2, Alpha 3 Aug 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants