5 lines of code, webpage multilingual translation in 1 second!

Content

With the popularity of the Internet and the trend of globalization, more and more companies and individuals are turning their attention to overseas markets.

In this context, website internationalization has become an essential link.

Today, we are going to introduce a translation tool library based on JavaScript - translate.js, and how it helps us achieve website internationalization.

What is translate.js?

translate.js is a free, open-source translation tool library that supports mutual translation between multiple languages, such as Chinese, English, French, Japanese, Korean, German, etc.

It avoids the limitations and cost issues of API call times, and is easy to use, convenient, and fast.

By using translate.js, we can easily achieve website internationalization, allowing users from different countries and regions to conveniently use our website.

Unique Advantages

  • Extremely easy to use
  • Does not increase workload
  • Dynamically configurable
  • Free to use permanently
  • No need for API. Translate directly using JavaScript, avoiding limitations and costs associated with API calls;
  • Supports translation between multiple languages.

Online Experience

Four, try the water with someone else's website first

在这里插入图片描述

  1. Open a webpage at random
  2. F12 (Inspect Element)
  3. Paste the following code into the console tab:
 var head= document.getElementsByTagName('head')[0];
 var script= document.createElement('script');
 script.type= 'text/javascript';
 script.src= 'https://res.zvo.cn/translate/inspector_v2.js';
 head.appendChild(script);

在这里插入图片描述
5.Enter 回车键 , 执行

  1. In the upper left corner of the current webpage, there is a big language switch, give it a try.

How to Use Quickly

At the end of the webpage, before, add the following code, generally at the bottom of the page, the select language switch tag appears. It's that simple:

 <script src="https://res.zvo.cn/translate/translate.js"></script>
 <script>
 translate.setUseVersion2(); //设置使用v2.x 版本
 translate.language.setLocal('chinese_simplified'); //设置本地语种(当前网页的语种)。如果不设置,默认自动识别当前网页显示文字的语种。
 translate.execute();//进行翻译 
</script>

More usage methods can be found in the project repository:

Chapter 6 Summary

translate.js project quickly implements website internationalization.

By simple and easy-to-understand tutorials, let your website quickly embrace global users.

If you are still struggling with the huge workload of dynamically configuring translation files for i18n, why not try translate.js? It can save you 99.99% of translation time. Come and experience it now!

觉得还不错? 一键收藏 ![](https://csdnimg.cn/release/blogv2/dist/pc/img/collectionCloseWhite.png)

Summary
The article introduces a JavaScript-based translation tool library called translate.js, which facilitates website internationalization by supporting translation between multiple languages. It is free, open-source, easy to use, and avoids API limitations and costs. Users can experience the tool online and easily implement it on their websites. By following simple steps, users can quickly enable language switching on any webpage. The article provides code snippets for integrating translate.js into web pages and directs users to the project repository for more information. Overall, translate.js offers a fast solution for website internationalization, saving time and effort compared to traditional translation methods. The tool is recommended for those looking to efficiently cater to a global audience.