Hello Vamsi,
Currently, there is no way out of the box for your website to detect the location of where a visitor is coming from and automatically be able to translate the website for them. I would like to confirm which page you added the script to.
The root.master page cannot be customized, just as mchv2.0 mentioned above. You can refer to the suggestion of mchv2.0 as well as other community members who have the experience to help with this kind of issue.
Meanwhile, you can visit the TechNet forum or the MSDN forum for assistance. The two forums are staffed with technical support engineers and Microsoft partners who can provide technical expertise to resolve the issue.
Thanks,
Cherry Wang