GoogleChromeLabs / proxx

A game of proximity
https://proxx.app
Apache License 2.0
1.31k stars 124 forks source link

Localisation #491

Open jakearchibald opened 4 years ago

jakearchibald commented 4 years ago

The plan is to use Accept-Language + Netlify's rewrite rules. https://www.netlify.com/docs/redirects/#geoip-and-language-based-redirects. It says 'redirect' here, but if you use 200 as the status code, it'll rewrite rather than redirect.

You can also set an nf_lang cookie, so we have a path to a language picker.

The idea is just to do multiple builds of the site.

import { strTryAgain, strMedium, strEasy } from ':lang:';

Where Rollup will make :lang: an import like:

export const strTryAgain = 'Try again';
export const strMedium = 'Medium';
export const strEasy = 'Easy';

And it'll just do a build per language pack.

We need to make sure we set Vary headers on all content.

We need to avoid the subsetted font trick for non-English (unless we do similar subsetting).

We probably need to rethink the font all together for non-latin script.

jakearchibald commented 4 years ago

Test: https://localisation-test--gravitongame.netlify.com/

curl -v -H "Accept-Language: en-in"  https://localisation-test--gravitongame.netlify.com
curl -v -H "Accept-Language: en-gb"  https://localisation-test--gravitongame.netlify.com
curl -v -H "Accept-Language: en-us"  https://localisation-test--gravitongame.netlify.com
curl -v -H "Accept-Language: hi-in"  https://localisation-test--gravitongame.netlify.com
surma commented 4 years ago

Nice!

The only worry I have around multiple, separate builds is ServiceWorker and the caches. For example, each language will have their own sprite textures that will get redownloaded when I switch languages, no? Or can we dedupe those across builds?

jakearchibald commented 4 years ago

They're duped in the build, but (assuming their content is the same) they'll have the same URL at the end. It could be a build optimisation though.

I guess the point is, hashed assets do not need Vary, since their variance is covered by the hash. I should limit to resources that aren't hashed and change by language (the root, the service worker, maybe more?)

But yeah, we'll have to trigger sprite regeneration on language change (assuming numbers are different).

I'll have a think about the service worker behaviour here. Maybe forcing a reload in this case is a better option.