Skip to content

Instantly share code, notes, and snippets.

@Jeffen
Last active April 28, 2022 15:00
Show Gist options
  • Save Jeffen/c9f4a9b31baf2ba9715e09489b922955 to your computer and use it in GitHub Desktop.
Save Jeffen/c9f4a9b31baf2ba9715e09489b922955 to your computer and use it in GitHub Desktop.
Angular Web App i18n Nginx Conf
map $http_accept_language $lang {
default en;
~*^fr fr;
~*^zh cn;
}
server {
# Other Configurations...
root /usr/share/nginx/i18n;
index index.html;
# Let's say you have 3 languages comiled files.
# Put you compiled file into three different sub folder(./en, ./cn, ./fr).
# And apply following configs. Your Angular will be able to know user's browser default language
# and navigate when user visit root. And can navigate between different langs app without lossing child routes.
location = / {
return 302 /$lang/;
}
location ~^/en {
try_files $uri $uri/ /en/index.html;
}
location ~^/fr {
try_files $uri $uri/ /fr/index.html;
}
location ~^/cn {
try_files $uri $uri/ /cn/index.html;
}
# Other Configurations...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment