Firebase has recently(Aug 20, 2020) announced support for i18n rewrites.
My web app has two locales: English and French, so I've put the French content under public/localized/fr/
and the English content under public
. Then, I added the following to firebase.json
:
{
"hosting": {
...
},
"i18n": {
"root": "/localized"
}
}
However, if I set French as my primary language in the browser settings(and the value of the Accept-Language
header is fr
), the website still serves the English content.
I have created an MCVE: https://github.com/Jaimies/firebase-hosting-i18n-rewrites-demo.
I'm using Firebase CLI version 8.9.0
.
Update: I filed a bug report to Firebase support.
Update 2: I got a response from Firebase support, see this answer.
The i18n
attribute in your firebase.json
is placed at the root, while it should be inside the hosting
attribute.
So you have to change firebase.json
to the following:
{
"hosting": {
...
"i18n": {
"root": "/localized"
}
}
}
Thanks to Eder from Firebase support for pointing this issue out.