Mark Ku's Blog

Using chinese-language-loader in Vue CLI to Avoid Forgetting Traditional-to-Simplified Conversion

The Problem

Users in mainland China are sensitive to seeing Traditional Chinese characters. When developing front-end pages, it is easy to forget to convert Traditional to Simplified Chinese and accidentally hard-code Traditional Chinese strings into HTML or JS files.

Evaluating the Package

Snyk Advisor page for chinese-language-loader package, score 42/100 The package does not score very high on Snyk, probably because of low usage. But after reading the source code, the underlying mechanism is a Traditional/Simplified mapping table for character conversion, so it should be safe enough to use.

Install chinese-language-loader

[GitHub link]

npm install chinese-language-loader --save --devs

Adjust vue.config.js

chainWebpack: config => {
    config.module
      .rule('language')
      .test(/\.(js|vue)$/)
      .use('chinese-language-loader')
      .loader('chinese-language-loader')
      .options({
        language: 'zh-CN'
      })
      .end()
      }

Result

At this point, Traditional Chinese in your .vue and .js files will be converted to Simplified Chinese during bundling.

Bonus: Convert Simplified to Traditional Chinese in JavaScript

import chineseLanguageLoader  from "chinese-language-loader/lib/main.js";
let str = chineseLanguageLoader('红豆生南国,春来发几枝。愿君多采撷,此物最相思。', {language: 'zh-TW'});
console.log(s2tResult)

// 紅豆生南國,春來發幾枝。願君多采擷,此物最相思。

Author

Mark Ku

擁有 10+ 年經驗的資深軟體工程師,現為 AI 應用 Builder,專注於大型平台架構與簡化複雜系統設計,從電商系統到訂閱與收費平台,結合 AI Agent、AI 整合與自動化開發,打造高效率且可持續演進的產品技術基礎。Read More

Found this useful?

The author's free tools, daily podcasts and newsletter are all here.

Mark Ku · This article is licensed under CC BY 4.0. Credit the author and link back to the original when reusing it.

Comments

Subscribe to Newsletter

Subscribe to get new posts delivered instantly — never miss a tech share.

By submitting, you agree to receive emails. You can anytime.

Popular Posts

View all
Mark Ku
··602

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution
Mark Ku
··490

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.
Mark Ku
··333

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki
Mark Ku
··264

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning
Mark Ku
··221

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1
Mark Ku
··215

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Setting Up Samba on Ubuntu to Share Folders with Windows 11