Skip to content

gggscript/detect-machine-translation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Detect if your users translate your site

Detect if the current website has been machine-translated

Why

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

Usage

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,
    })
  }
})

Install

npm install detect-machine-translation

This project has no dependencies

API

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

Support

Resources

Daniel's Article on detecting machine-translated webpages

ToDo

  • Callback when translation happens using Observers
  • Normalizing Language Codes

Support more Services

About

Detect if the current website has been machine-translated

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published