Skip to content
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

Switch Bedrock to using Django's own i18n mechanism #14327

Merged
merged 53 commits into from
Apr 17, 2024

Commits on Apr 17, 2024

  1. Configuration menu
    Copy the full SHA
    590bb46 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1c2d4f5 View commit details
    Browse the repository at this point in the history
  3. [Breaking] Use i18n_patterns to lang-code prefix relevant paths in mo…

    …zorg.urls
    
    This includes splitting mozorg.urls into two groups so we only use
    i18n_patterns with paths that need it. We've kept the main, localed, group's
    name to be urls.py to reduce the chance of merge conflicts, as this piece
    of work is likely to need rebasing against main quite a lot until it's ready.
    
    The decision about which get prefixed and which do not is based on the
    settings SUPPORTED_NONLOCALES and SUPPORTED_LOCALE_IGNORE that were used
    in our former i18n machinery. At the time of committing, they still exist,
    but both of should be able to be removed once this work is done (or at least
    moved to power some tests)
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    b768cb3 View commit details
    Browse the repository at this point in the history
  4. [Breaking] We now have /en-US/ resolving/rendering for the homepage, …

    …but not yet /fr/
    
    We use a prefixer for our i18n_urlpatterns so that when we reverse() and
    resolve() we allow for a custom prefix that is normalized to our mixed-case
    lang codes.
    
    Tests are needed.
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    34289ba View commit details
    Browse the repository at this point in the history
  5. Add middleware to fix up the lang code in the path

    This essentially replaces urlresolves.Prefixer.fix()
    
    Tests are needed.
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    5b8eda3 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    4438da2 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    404fa05 View commit details
    Browse the repository at this point in the history
  8. Ensure the request is annotated with the relevant lang_code, so that …

    …it's
    
    available in templates
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    bf3985a View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    e79df9c View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    1e33859 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    837df57 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    3fd9d94 View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    0ed076d View commit details
    Browse the repository at this point in the history
  14. Update tests for accepted locales

    Note that we no longer have a lowercase-to-mixed-case lang lookup, so this
    test changes but might become redundant later in the refactor
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    d50def3 View commit details
    Browse the repository at this point in the history
  15. Improve naming in helper

    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    de5b8ae View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    2a24e7d View commit details
    Browse the repository at this point in the history
  17. Extend Django's support for get_language_info to include our three-ch…

    …aracter lang names, which it doesn't have by default
    
    This is a part of ensuring three-letter country codes still work, but it might
    be redundant - TBC
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    07803dd View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    c7d7b7f View commit details
    Browse the repository at this point in the history
  19. Drop unnecessary work in custom locale middleware

    This was useful before we started using i18n_patterns, but now not all of it
    is needed. Some still is, though
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    07952b0 View commit details
    Browse the repository at this point in the history
  20. Fixup redirects behaviour (using /webvision/ as an example case)

    * Redirects don't need url prefixing via i18n_patterns, so we're moving them to
    nonlocale_urls instead.
    * When detecting a language, en-CA was being picked over en-US, which is
    avoided by ensuring en-US is at the start of the languages list
    * Note that for the webvision redirect we needed to add:
       * locale_prefix=True
       * prepend_locale=False
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    c541093 View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    59fe9a7 View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    919fd6f View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    5fdde80 View commit details
    Browse the repository at this point in the history
  24. Configuration menu
    Copy the full SHA
    f9e93df View commit details
    Browse the repository at this point in the history
  25. Move mozorg redirect() calls to redirects.py to avoid the routes havi…

    …ng lang codes prefixed to them
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    62dfd25 View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    74d3617 View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    4fcc522 View commit details
    Browse the repository at this point in the history
  28. Configuration menu
    Copy the full SHA
    201a98f View commit details
    Browse the repository at this point in the history
  29. Add tests for i18n helpers

    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    e972c9c View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    8736ecc View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    02f17e6 View commit details
    Browse the repository at this point in the history
  32. Configuration menu
    Copy the full SHA
    5765ec8 View commit details
    Browse the repository at this point in the history
  33. Move redirects out of urls.py so that they remain language agnostic -…

    … tweak _one_ test related to this
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    c3c4ed0 View commit details
    Browse the repository at this point in the history
  34. Avoid unnecessarily adding lang code to a reversed() url in our redir…

    …ector - we don't need it unless we explicitly ask for it
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    3baf110 View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    8f19837 View commit details
    Browse the repository at this point in the history
  36. Tidy up tests

    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    e7773e6 View commit details
    Browse the repository at this point in the history
  37. Fixing tests with settings=DEV

    * Contentful-related tests needed the dev-urls config wrapping in URLpatterns
    to make it work as per the real site; if we just specced dev_urls they did not
    work because they were not i18n-patterned
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    8b3771d View commit details
    Browse the repository at this point in the history
  38. Default a locale to '' not None - the latter causes Locale page to bl…

    …ow up and the former matches original behaviour better
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    3be47ce View commit details
    Browse the repository at this point in the history
  39. Ensure no-JS language changing works

    Fixes #5931
    See #5931 for context
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    e26dc61 View commit details
    Browse the repository at this point in the history
  40. Configuration menu
    Copy the full SHA
    fa03b0b View commit details
    Browse the repository at this point in the history
  41. Configuration menu
    Copy the full SHA
    f057e62 View commit details
    Browse the repository at this point in the history
  42. Monkeypatch Django's check_for_language() because it looks in the wro…

    …ng place for us
    
    By default check_for_language() seeks gettext-compatible files in locale/ directories
    in the project, but we don't have those because our l10n is handled using Fluent
    strings in the www-l10n-team directory, cloned from their git repo.
    
    So, instead, we just perform a light check to see whether a given lang is among the
    langs that shold be available. The actual decision about whether we have have (enough)
    Fluent strings available for that locale happens in lib.l10n_utils.render()
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    5c2b4b5 View commit details
    Browse the repository at this point in the history
  43. Configuration menu
    Copy the full SHA
    0fe343d View commit details
    Browse the repository at this point in the history
  44. Configuration menu
    Copy the full SHA
    429a9fa View commit details
    Browse the repository at this point in the history
  45. Configuration menu
    Copy the full SHA
    609eae3 View commit details
    Browse the repository at this point in the history
  46. Configuration menu
    Copy the full SHA
    1c2f119 View commit details
    Browse the repository at this point in the history
  47. Drop unnecessary-after-all patching of LANG_INFO - we found a differe…

    …nt route to making check_for_language work; this was the wrong direction
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    646bfbf View commit details
    Browse the repository at this point in the history
  48. Configuration menu
    Copy the full SHA
    8ea97e3 View commit details
    Browse the repository at this point in the history
  49. Minor test polishing

    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    85c2694 View commit details
    Browse the repository at this point in the history
  50. Support special-case showing of a locale list at / if no accept-lang …

    …header is present
    
    This changeset ensures we retain the existing behaviour where a robot/spider
    going to / with no accept-language header gets a 200 OK response but with a
    locale-picker page, NOT the homepage.
    
    The fix here was to avoid running Django's LocaleMiddleware when (and only
    when) we detect the special case of a request for the root path and no
    Accept-Language header - which is basically a call for the root page with
    no way to determine the client's locale. (We don't use sessions in Bedrock
    so Django will never find a language code in a session anyway)
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    3aef3c3 View commit details
    Browse the repository at this point in the history
  51. Improve naming to avoid confusion between polish (verb) and Polish in…

    … split_path_and_polish_lang
    stevejalim committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    53f94e2 View commit details
    Browse the repository at this point in the history
  52. Configuration menu
    Copy the full SHA
    19b5aad View commit details
    Browse the repository at this point in the history
  53. Configuration menu
    Copy the full SHA
    f968cb9 View commit details
    Browse the repository at this point in the history