Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Switch to path-based i18n routing #701

Merged
merged 7 commits into from
Feb 1, 2022
Merged

Switch to path-based i18n routing #701

merged 7 commits into from
Feb 1, 2022

Conversation

zackkrida
Copy link
Member

Fixes

Fixes #700 by @zackkrida

Description

This PR switches Openverse to use the url path instead of a cookie for setting translations. This has a few benefits:

  1. Don't have to worry about cookie values being set correctly when switching from one locale to another
  2. Makes it easy for developers to test different locales, just modify the url path
  3. Allows for much more aggressive front-end caching (currently the site is 'dynamic' in the sense that the same page with the same url should show different contents based on a cookie). This makes each page infinitely cacheable by url.
  4. Fixes the issue in Translations aren't shown on localized homepages #700

To use this PR, we need an accompanying PR in the Openverse WordPress theme that prefixes the iframe url with the correct locale string.

Testing Instructions

  1. Run the app locally
  2. Try different locale-based paths like localhost:8443/es, localhost:8443/ru and so on.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@zackkrida zackkrida requested a review from a team as a code owner January 25, 2022 03:33
@zackkrida zackkrida requested review from obulat and dhruvkb January 25, 2022 03:33
@zackkrida zackkrida added ♿️ aspect: a11y Concerns related to the project's accessibility 🛠 goal: fix Bug fix 🟥 priority: critical Must be addressed ASAP labels Jan 25, 2022
@dhruvkb
Copy link
Member

dhruvkb commented Jan 25, 2022

Wouldn't having translations in the URL allow entering invalid combinations like https://ru.wordpress.org/openverse/es?

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great, and will prevent the problems with mismatch with the outer frame we sometimes have (Openverse in French with outer frame in English).
I've scanned the repo for paths, and there is one place where we need to change path to localePath:

:to="{ path: `/search/${key}`, query: $route.query }"

I don't think this change should affect the urlChange message exchange with the outer frame in sendWindowMessage, but it would be nice to check.

@obulat
Copy link
Contributor

obulat commented Jan 25, 2022

Wouldn't having translations in the URL allow entering invalid combinations like https://ru.wordpress.org/openverse/es?

I guess we could add a redirect to URLs like this. Is it possible to detect the mismatch between the ru and es locales in the URL https://ru.wordpress.org/openverse/es, and then set the iframe locale to ru, in this case?

@zackkrida
Copy link
Member Author

@dhruvkb it what scenario would a url like ru.wordpress.org/openverse/es be produced? What would be adding the /es to the end of the path?

@dhruvkb
Copy link
Member

dhruvkb commented Jan 25, 2022

It wouldn't be occurring naturally, that's just my imagination of someone trying to mess with the system by intentionally entering such a mismatched, incorrect URL into the address bar.

@zackkrida
Copy link
Member Author

Got it! In this case, I think it would just 404 and that's okay.

@zackkrida zackkrida requested a review from obulat January 25, 2022 13:13
@zackkrida
Copy link
Member Author

Thanks @obulat I also fixed the 'back to search results' links; I would've missed that without your suggestion!

@zackkrida
Copy link
Member Author

Oh also @dhruvkb, only folks using the non-english site who would know to inspect the iframe would even think to look at the url there, notice we're using a base path for locales, and then try to manipulate, where it would only effect their local browsing experience.

Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of things/minor logic bugs.

Otherwise this LGTM. We'll still need one more fix to the homepage to fully fix the internationalization of it as #765 still needs to be addressed.

nuxt.config.js Show resolved Hide resolved
src/composables/use-match-routes.js Outdated Show resolved Hide resolved
src/pages/image/_id.vue Outdated Show resolved Hide resolved
zackkrida and others added 3 commits February 1, 2022 11:29
Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>
Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>
Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the fixes 🎉

@zackkrida zackkrida merged commit b1f58d2 into main Feb 1, 2022
@zackkrida zackkrida deleted the route-based-i18n branch February 1, 2022 17:14
rbadillap added a commit that referenced this pull request Feb 2, 2022
* main: (73 commits)
  Make audio/image pages without ids show a 404 (#768)
  Fix logo button paddings and simplify implementation (#767)
  Fix global audio rtl close placement (#780)
  Check for `null` localStorage explicitly (#763)
  Truncate global audio text to two lines (#773)
  New image details page (#682)
  Switch to path-based i18n routing (#701)
  Enable source maps in production (#755)
  Remove Jamendo and Wikimedia Commons from audio meta sources (#747)
  Use jed1x json format to correctly handle pluralization (#753)
  Fix logo color on error page layout (#752)
  Add homepage content switcher for mobile screens (#716)
  Add inline-start border to filters on desktop (#748)
  Fix header items not fitting in (#718)
  Expose `close` to popover content via slot props (#736)
  Truncate row layout audio titles (#735)
  Stop blocking on analytics requests (#715)
  Style links globally (#727)
  Refactor the usage of i18n result count computation (#707)
  Use `VPopover` for the content report form (#719)
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
♿️ aspect: a11y Concerns related to the project's accessibility 🛠 goal: fix Bug fix 🟥 priority: critical Must be addressed ASAP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Translations aren't shown on localized homepages
4 participants