如何确定网站的语言 [英] How to determine the language of a website

查看:70
本文介绍了如何确定网站的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站的网址,需要找出该网站使用的语言(无论是西班牙语,法语,意大利语等).

I have a url of a website and need to find out which language the website uses (whether it's spanish, french, italian, etc).

该网站的顶级域名是 .com ,这完全没有帮助.我不能简单地检查字符串是否包含".de",.fr"或任何其他国家(地区)代码.

The site's top level domain is .com, and this doesn't help at all. I cannot simply check if the string contains '.de', '.fr', or any other country codes.

我试图获取html标签的lang属性,但是有许多网站没有它.另外,我此处可以检查元数据标签,如下所示:

I was trying to get the lang attribute of the html tag, but there are many websites that don't have it. Also I found here that I can check the meta tag, which would look like this:

<meta name="language" content="english">

但同样,并非所有网站都使用此标签.

But again, not all websites use this tag.

您知道确定网站语言的其他方法吗?

Do you know any other ways to determine a website's language?

谢谢.

推荐答案

可悲的是,许多开发人员并不认为在其网页上添加语言元信息会很有用.也可能是页面上有多种语言-据我所知-强制使用<div>参数lang或其他类似的东西.以下是一些可能对您有帮助的提示:

Sadly many developers don't think that adding a language metainfo to their web page is something useful. Also it might be that the page has multiple languages on it which - as far as I know - forces the usage of the <div> parameter lang or other such things. Here are some pointers that might help you:

  1. 检查<meta name="language" content="...">标签
  2. 检查内部<div>并查看其中是否包含lang参数
  3. 检查菜单(如果有的话)-这些菜单通常包含比页面主体少得多的文本
  4. 寻找更小的HTML数据块,您可以轻松地对其进行解析,从而为您提供有关页面使用的语言的更多信息
  5. 最后开始试探性地分析大文本块
  1. Check for the <meta name="language" content="..."> tag
  2. Check inside <div>s and look if those contain lang parameter
  3. Check the menus (if any) - these usually contain much, much less text than the main body of the page
  4. Look for further smaller chunks of HTML data that you can parse easily and that can give you more information about the language(s) the page uses
  5. Finally start heuristically analyzing the big text chunks

实际上,当前的状况令人非常难过,因为提供此类信息并不难,不需要花费很多额外的时间来做,但是专业人士肯定在那里,尤其是在搜索引擎方面,最重要的是-改善了各种残障人士的可及性.

It's actually really sad how things currently are because providing such information is not that difficult and doesn't require much extra time invested into doing it but the pros are definitely there especially when it comes to search engines and most importantly - improving the accessibility for people who have various disabilities.

这篇关于如何确定网站的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆