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

fix(legal): fix rendering of legal pages when loaded directly via url #1376

Merged
merged 2 commits into from Jul 14, 2014

Conversation

zaach
Copy link
Contributor

@zaach zaach commented Jul 9, 2014

I refactored the template fetching so that we can use it from the route handler when rendering pages dynamically and from the grunt task when generating pages statically.

Fixes #1372.

@shane-tomlinson r?

// Create a cache of the templates so we can reference them synchronously later
Promise.settle(supportedLanguages.map(function (lang) {

return getTemplate('terms', lang, defaultLang)

Choose a reason for hiding this comment

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

Since getTemplate returns a promise, could you do something like:

   return Promise.all([
     getTemplate('terms', lang, defaultLang),
     getTemplate('privacy', lang, defaultLang)
   ]).then(allTemplates) {
    templates[lang] = {
       terms: allTemplates[0],
       privacy: allTemplates[1]
    }
   }).then(...

It might be marginally faster since the runtime loop can continue while waiting for the filesystem?

Choose a reason for hiding this comment

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

never mind, my idea blows up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really? It seems to work for me. Thanks for the suggestion!

@shane-tomlinson
Copy link

@zaach - Huurah! It works, but I am concerned at the amount of voodoo that is going on with our l10n build step, or at least lack of documented steps. Wanna put our heads together and come up with a legacy new developers can use to learn what is going on, or just as a refresher for 6 months from now when both of us are scratching our heads saying WTF?

@zaach
Copy link
Contributor Author

zaach commented Jul 11, 2014

@shane-tomlinson I added more comments! I began mapping out all of the flows in a diagram. It's not pretty, but I'll try to create a lucid chart next week.

@shane-tomlinson
Copy link

@zaach - Thanks for all the documentation. Now we have one final strangeness - requesting non-english locales always serves english privacy policy, even though the templates are clearly translated to to language. Here is German:

Rendered text

screen shot 2014-07-14 at 09 59 11

Template that should be served

screen shot 2014-07-14 at 09 59 16

Reproducible when running the server using grunt server:dist

@shane-tomlinson
Copy link

@zaach - I believe the above noted problem is because server/lib/localized-render replaces res.render with a function that renders the template for the locale specified in req.locale, which for me is set to en.

If I add:

            req.locale = i18n.localeFrom(lang);
            req.lang = lang;

just before

            // the HTML page removes the header to allow embedding.
            res.removeHeader('X-FRAME-OPTIONS');

everything works as expected. I'm not positive that's correct? Possibly.

@shane-tomlinson
Copy link

@zaach - another problem is the user receives a 500 error if browsing directly to a locale that does not exist:

screen shot 2014-07-14 at 10 50 21

This is noted in #1377

@shane-tomlinson
Copy link

@zaach - I have a proposal in #1377 for the failed to lookup view problem

@zaach
Copy link
Contributor Author

zaach commented Jul 14, 2014

@shane-tomlinson I believe your comment #1376 (comment) is issue #1337. I'm working on a PR for that which turns on abide's feature to recognize the lang from the URL.

@shane-tomlinson
Copy link

@zaach - hot.

@zaach
Copy link
Contributor Author

zaach commented Jul 14, 2014

@shane-tomlinson I'm just going to roll the fix for #1337 into this PR

@shane-tomlinson
Copy link

@zaach - do it!

@@ -17,8 +17,6 @@ module.exports = function (grunt) {
// use error pages from en_US as the static error pages
'copy:error_pages',
'useminPrepare',
'l10n-create-json',
'l10n-generate-tos-pp:dist',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are now run as part of l10n-generate-pages, since it depends on them.

@zaach
Copy link
Contributor Author

zaach commented Jul 14, 2014

Fixes #1377.

@shane-tomlinson
Copy link

@zaach - still seeing some instances of strangeness.

  1. I set the browser language to en and browsed to en_US:

screen shot 2014-07-14 at 22 50 43

  1. If you browse to es_AR with en set as the browser language, similar error, but browsing to es-AR does not.

@zaach
Copy link
Contributor Author

zaach commented Jul 14, 2014

@shane-tomlinson Yep, I think we need to just remove en from the supported lang list (it's not present in production fwiw). Then it will default to en-US like other unsupported locales. To your second point, es_AR is unrecognized because of the underscore, so it follows the unrecognized languages path, which is working as intended.

@zaach
Copy link
Contributor Author

zaach commented Jul 14, 2014

Okay, I've removed en from the default supported languages array. The cases caught by @shane-tomlinson are working correctly but I'd like someone else to confirm.

ckarlof added a commit that referenced this pull request Jul 14, 2014
fix(legal): fix rendering of legal pages when loaded directly via url
@ckarlof ckarlof merged commit 555633b into master Jul 14, 2014
@ckarlof ckarlof deleted the issue-1372-legal-blank-rendering branch July 14, 2014 23:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terms and Privacy pages are empty
4 participants