Skip to content

Instantly share code, notes, and snippets.

@worthy7
Created December 12, 2023 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save worthy7/b36509fb2be13231c71b26160722cb48 to your computer and use it in GitHub Desktop.
Save worthy7/b36509fb2be13231c71b26160722cb48 to your computer and use it in GitHub Desktop.
Firebase + Angular i18n notes
How firebase works
3 ways to detect
country by IP
language by accept-language header
cookie override for both.
if nothing found, will use rewrites
Country is detected from IP
Language is detected from accept-language header
folder names must be lowercase, except for ALL case which should be caps.
AL header if used, firebase ignores the country.
if AL has es or es-419 and IP is spain, es_es folder will work.
of AL has es or es-419 and IP is 419/mexico/US, es_es folder will not work but es_ALL will (just es?)
if AL has es-419, IP is Mexico (419), es_mx will work because mx matches the ip and AL has es in it.
if AL has es-419, IP is US (419), es_ALL and es_us will work because us matches the ip and AL has es in it.
if AL has en then ja, IP is jp, only en_us en_gb and ja (ja_ALL) folders exist, it chooses ja because even though en is highest, the IP is jp so only en or en_ALL or en_jp would work for ja. Since they do not exist, it finds ja in the AL header too, an allowed language, and serves that.
So basically, it will only accept country of that IP or the cookie or blank (en or en_ALL)
If you want country specific locals, you have to set it with cookie and it has to be done before the app starts, which is basically impossible but you can reload.
**service and caches may cache the first language loaded... when page starts.**
So, if we want the first load to get the correct language,
A generic rewrite to us_gb or whatever on fail to find i18n works but links etc all break
ALL as a folder does not work.
if firebase cookies are set to something undefined, it will only load the root.
Big problem: firebase i18n rewrites, don't preserve the ** -> index.html rewrite rule defined for SPAs. So it is completely useless.
How do major companies manage language?
Firebase adds ?hl=es as url parameter
google homepage sets some cookie or something detected by the backend. No url change.
microsoft writes ms.com/locale/ into the url. The whole app is translated. en-gb etc.
amazon is strange. amazon.jp/-/ja/?language=locale
it is a parameter but also has a website and then even a url segment...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment