Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a page in different languages?

I use this meta tags to make google crawler know that I have two languages for my site, as suggested here support.google.

<link rel="alternate" hreflang="x-default" href="http://www.example.com" />
<link rel="alternate" hreflang="de" href="http://www.example.com/de" />
<link rel="alternate" hreflang="en" href="http://www.example.com/en" />

So sometimes the content of example.com would be the same as example.com/de and sometimes example.com would be the same as example.com/en.

I use the following code to detect language

const lang = (
     getLangFromUrl(req.url) || 
     getLangFromCookies(req.cookies) || 
     getLangFromHeader(req.headers) || 
     'de'
);

and google detects example.com and example.com/de as duplicated pages.

Can you please tell me how should it be correctly done?

like image 254
fingerpich Avatar asked Feb 25 '19 19:02

fingerpich


People also ask

How do you serve a page in multiple languages?

To change the language, just simply set the lang attribute. We can define it anywhere in the document, such as in the body, in the paragraph, in the heading, or in the span tag. But the best practice is to set the lang in the span tag.

How do I translate an entire page?

Launch Google Chrome and go to the Google Translate website i.e. translate.google.com. Type the entire URL of your website in the text box on the left. Select the new language you wish to translate your website into. Click the Translate button.


1 Answers

Google has mentioned this issue in this link: support.google.com

If you prefer to dynamically change content or reroute the user based on language settings, be aware that Google might not find and crawl all your variations. This is because the Googlebot crawler usually originates from the USA. In addition, the crawler sends HTTP requests without setting Accept-Language in the request header.

I hope this will help you

like image 153
mojtaba zangeneh Avatar answered Oct 14 '22 21:10

mojtaba zangeneh