Zoran Luledzija
Zoran Luledzija
February 06, 2023
5 min read
February 06, 2023
5 min read

Detecting navigator language

Detecting navigator language

Browsers are a crucial component of the modern world, as they are the gateway to the internet for most people. They have evolved to cater to the global market by offering support for multiple languages, making them accessible to users around the world. This localization feature also plays an important role in website localization, as it allows websites to detect the user's preferred language in the browser and return the proper version of the website accordingly. This enhances the user's experience and makes browsing the web more pleasant.

How browser language can be used in website localization?

Browser language has a significant impact on the way websites are displayed and experienced by the user. When a website is properly localized, it can return the correct version of the page based on the user's preferred language setting in their browser. This results in a personalized and enjoyable experience for the user as they can navigate the website in their own language.

On the other hand, when a website is not localized and a user's browser requests a page in a language that is not available, the user may see the page in a potentially unfamiliar language. This can be confusing and frustrating for the user and may even discourage them from using the website in the future. It is important for websites to take into consideration the global audience and offer localized versions to ensure a positive user experience for all visitors.

Having a localized website can be also crucial for locale businesses that are operating in countries where multiple languages are supported. Take Switzerland and Canada as examples, where residents often speak several languages. If a business fails to localize its website, it could potentially miss out on a large portion of its target audience who may not understand the content or feel alienated by the language used. This can negatively impact the business's reputation and bottom line.

How to know what language your visitors are using?

Discovering a user's preferred language can be accomplished through either server-side or client-side methods. It all depends on what you need and what technologies you use. Below, you can find techniques and details of both approaches.

Server-side language detection

The server detects the user's preferred language by analyzing the HTTP request made by the user's browser. When a user visits a website, the browser sends a request to the server containing information about the user's device, including the preferred language. This information is stored in the Accept-Language header of the request and specifies the user's preferred language for displaying content.

Also, when the browser preferences include multiple languages, the browser assigns a ranking to each language based on a value called qvalue. This ranking system helps the server understand the order in which the user prefers to receive content in those languages.

Below, you can find an example of the Accept-Language header with multiple languages. French is preferred. If that fails, British English is requested, and finally any type of English.

Accept-Language: fr,en-GB;q=0.9,en;q=0.8

Client-side language detection

Language detection in JavaScript can be crucial for creating user-friendly experiences in single-page applications (SPAs) built with front-end libraries/frameworks like React, Vue, and Angular. By detecting the user's preferred language, these apps can dynamically adjust the content and interface to meet the user's specific needs. Below, you can find a snippet that explains how to access the user's preferred language with JavaScript.

window.navigator.languages // ['fr', 'en-GB', 'en']
window.navigator.language // 'fr'

The window.navigator.languages property returns an array of language codes that represents the user's preferred language order, much like the Accept-Language header in HTTP requests, but without the qvalues.

The window.navigator.language property returns the user's preferred language, or the first element of the window.navigator.languages property.

Note: Different browsers may handle language and languages properties differently. It's important to test your code across multiple browsers to ensure accurate results.

Differences between the user's preferred language and the user's location

User's preferred language and location are often used to personalize the user experience in software localization. Preferred language refers to the language that a user has set as their preferred language in their device or browser settings, while location refers to the physical location of the user determined by their IP address.

In terms of software localization, the user's preferred language is typically used to determine the language in which the user interface and content should be presented. On the other hand, the user's location is often used for personalized content or advertisements based on the user's physical location.

However, the use of Virtual Private Networks (VPNs) can complicate the accuracy of both preferred language and location detection. VPNs allow users to mask their physical location and present a different IP address, making it difficult to determine the user's true location. Similarly, the language settings on a VPN-connected device may not accurately reflect the user's preferred language, making it important to have a fallback mechanism in place.

The importance of a fallback language

Websites can't support all languages, and this is why having a fallback language is so important. If a user's preferred language is not supported, it's important to have a fallback in place so that the user can still understand and navigate the website.

Good practices for fallback languages include using a generic language, such as English, as a default option. This ensures that the user can understand the content even if their preferred language is not available. Additionally, it is also a good practice to fall back to the language without region or script code. For example, if the user's preferred language is French (Canada), the fallback should be French, not English. By doing this, the user will still be able to understand the content in a language that they are familiar with.

Overall, having a well-thought-out fallback language strategy can greatly improve the user experience on your website.

Wrapping up

In this post, we covered the topic of detecting the user's preferred language on both the server side and the client side. We explored the importance of knowing the language your visitors are using and highlighted the differences between the user's preferred language and location. Also, we noted the importance of having a fallback language in the context of website localization.

Detecting the browser language is just one aspect of software localization. Software localization is a broader area that involves managing translations, ensuring the quality of translations through reviews, usage of glossaries, and much more. Implementing software localization effectively can be challenging, but using specialized tools can make the process smoother and more efficient. Try Localizely for free.

Like this article? Share it!

Zoran Luledzija
Zoran Luledzija

Zoran is a Software Engineer at Localizely. His primary interest is web development, but he also has a solid background in other technologies. For the last few years, he has been involved in the development of software localization tools.

Enjoying the read?

Subscribe to the Localizely blog newsletter for quality product content in your inbox.


How to translate ARB files efficiently
March 01, 2024
In “Localization
Localization Statistics 2023
December 22, 2023
In “Localization
Copyrights 2024 © Localizely