Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Redirect a user from the root to a supported locale directory based on the "Accept-Language" header
ResourceFunction["HTTPLanguageRedirect"][languages,options] returns HTTPRedirect, which sends the user to the appropriate supported locale directory. |
"FallbackLanguage" | "en" | default locale |
"PreferredRegion" | {} | replace generic language with region variant |
Set your cloud directory:
In[1]:= |
Out[1]= |
Assume you have two localized versions of a site:
In[2]:= |
Out[2]= |
In[3]:= |
Out[3]= |
Apply CloudDeploy to the HTTPLanguageRedirect at index.nb:
In[4]:= |
Out[4]= |
Now send users to the root of your site:
In[5]:= |
Out[5]= |
Based on their browser settings, they will be automatically redirected to the correct localized version:
In[6]:= |
Out[6]= |
In[7]:= |
Out[7]= |
You may support multiple languages:
In[8]:= |
If you are supporting regional variants, you should include the generic language and use the "PreferredRegion" option to rewrite the generic language to the preferred regional variant:
In[9]:= |
The "FallbackLanguage" option returns a default language if none are applicable:
In[10]:= |
This function will redirect to a lowercase version of your supported languages:
In[11]:= |
Out[11]= |
This work is licensed under a Creative Commons Attribution 4.0 International License