Detect if the current website has been machine-translated
Not everyone speaks the language of your website's content. Browsers (like Chrome and Edge) sometimes automatically translate the page. Search Engines (like Google, Bing, Baidu, and Yandex) include "Translate Page" links next to your website. Automatic translations aren't perfect, which can impact your user's experience. The example below shows how you can integrate this with your analytics to monitor machine translations
import detectMachineTranslation from 'detect-machine-translation'
// use pagehide event
window.addEventListener('pagehide', () => {
const translation = detectMachineTranslation()
if (translation) {
yourAnalytics.sendEvent('machine-translation', {
by: translation.translator,
from: translation.source,
target: translation.target,
})
}
})
npm install detect-machine-translation
This project has no dependencies
interface Translation {
translator: 'Google' | 'Microsoft' | 'Mozilla' | 'Baidu' | 'Yandex' | 'Naver'
source: string // initial value from document.documentElement.lang
target: string // ISO 639-1 language code
}
export default function detectMachineTranslation(): Translation | undefined
- Google Chrome Built In Extension
- Microsoft Edge Built In Extension
- Mozilla's Bergamot Extension
- Google Translate (also used by many browser extensions)
- Yandex Translate
- Naver Papago
- Baidu Translate
Daniel's Article on detecting machine-translated webpages
- Callback when translation happens using Observers
- Normalizing Language Codes
- Apple/Safari
- UC Browser
- Xiaomi Browser
- Sogou
- Tencent
- https://apertium.org
- https://fanyi.caiyunapp.com
- https://gramtrans.com
- https://www.worldlingo.com
- https://fanyi.youdao.com/
- https://caiyunai.com/
- https://lingvanex.com/