Forem

Cover image for Chinese npm package 汉译英
Tykok
Tykok

Posted on

Chinese npm package 汉译英

Why create a npm package ?

Just to:

  • Understand what i use when i use npm i ... or yarn add ...
  • Especially understand how they made it !

So, i create my first package !

What is the library ?

The library named Cedict dictionary and it's actually available on npm.js and yarnpkg.com !

This library simply give you some functions and a large JSON file with for each object the :

  • Traditional character in Chinese
  • Simplified character in Chinese
  • Pinyin pronunciation
  • English translation

Thank you Panda

Here is an example of what you can have in an object :

{ 
  traditional: "上天入地", 
  simplified: "上天入地", 
  pinyin: "shang4", 
  english: "lit. to go up to heaven or down to Hades (idiom)/fig. to go to great lengths/to search heaven and earth/" 
}
Enter fullscreen mode Exit fullscreen mode

ℹ️ I do not currently speak Chinese while writing this article!
It’s a really complex language, though the C language and all its pointers 🤣.

What is the Cedict ?

The Cedict, called CC-CEDICT is a continuation of the CEDICT project.

This project provide a complete downloadable Chinese to English dictionary, and all of this in a specific format of CC-CEDICT.
It's an open source project who is actually frequently updated !

ℹ️ If you want, you can go to her wiki.

How the @tykok/cedict-dictionary package work

The project have two parts :

  • The part who get data and format the Cedict into a JSON.
  • The part who simply exploit the JSON.

To get the final JSON, we need to

  • Download the .zip on CC-CEDICT project.
  • Unzip it.
  • Get the file who contain the dictionary.
  • Parse it into a JSON file.

All this actions are in a script called by a cronjob who simply execute this script and update the JSON Cedict of the library.


The second part is more simply than the previous one !

Here, we have a JSON file. And we can simply exploit it with some functions to get for example a chinese object with a traditional character.

A simple start with @tykok/cedict-dictionary

To start, use yarn or npm to install the dependency :

# With yarn
yarn add @tykok/cedict-dictionary

# With npm
npm i @tykok/cedict-dictionary
Enter fullscreen mode Exit fullscreen mode

Next, just import the global class to use the Cedict :

import Cedict from '@tykok/cedict-dictionary'
Enter fullscreen mode Exit fullscreen mode

And, with the Cedict class, you can use some function to get a specific chinese character, the pronunciation or all the cedict !

To know how to use this package, you can go to the documentation.

Conclusion

This project is not just for fun. I create it to learn some things i actually don't know or improve it !

Code boy

Of course, this project is open source and you can come to contribute to this project. There are still many things to improve !


Tell me if you have any suggestions, or remarks for the project. And of course if this article was interesting.

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay