Giter Site home page Giter Site logo

zimcke / piaolianghanzi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexandertang/piaolianghanzi

0.0 0.0 0.0 401 KB

Angular library for displaying pinyin and chinese Hanzi as coherent blocks

License: MIT License

JavaScript 2.58% TypeScript 89.48% HTML 6.72% CSS 1.22%

piaolianghanzi's Introduction

npm version license

PiaoLiangHanzi

Builder project for NgPiaoLiangHanzi

NgPiaoLiangHanzi

Angular module to format Hanzi and Pinyin as coherent blocks.

Quickstart

  1. Install via npm
npm install ng-piao-liang-hanzi
  1. Import 'NgPiaoLiangHanziModule'
import { NgPiaoLiangHanziModule } from 'ng-piao-liang-hanzi';
@NgModule({
  imports: [NgPiaoLiangHanziModule]
})
export class AppModule { }
  1. Use 'ng-piao-liang-hanzi' to display your Chinese characters and pinyin:
<ng-piao-liang-hanzi [chineseCharacters]="'你好。'"></ng-piao-liang-hanzi>

image

Features

Automatic pinyin

Pinyin is generated automatically by default:

<ng-piao-liang-hanzi [chineseCharacters]="'Hello, 我是 Alexander。'"></ng-piao-liang-hanzi>

image

Custom pinyin text

Custom text can override the pinyin:

<ng-piao-liang-hanzi [chineseCharacters]="'你好。'" [pinyin]="'Anylength isok'"></ng-piao-liang-hanzi>

image

Pinyin with numbers

By default the automatic pinyin will generate with tone symbols. To generate with pinyin numbering format, set [pinyinWithNumber]="true":

<ng-piao-liang-hanzi [chineseCharacters]="'你好。'" [pinyinWithNumber]="true"></ng-piao-liang-hanzi>

image

To enable pinyin with numbering format globally in your project, use the global flag ENABLE_PINYIN_NUMBER_FORMAT:

import { NgPiaoLiangHanziModule } from 'ng-piao-liang-hanzi';
@NgModule({
  imports: [NgPiaoLiangHanziModule],
  providers: [{provide: 'ENABLE_PINYIN_NUMBER_FORMAT', useValue: true}]
})
export class AppModule { }

[pinyinWithNumber]="true" is then no longer needed. It is also possible to disable the number format in specific cases by setting [pinyinWithNumber]="false".

Skip pinyin for some characters

The pinyin is divided by single spaces. If the pinyin should not be entered for a character, just perform an extra space:

<ng-piao-liang-hanzi [chineseCharacters]="'这是你的书。'" [pinyin]="'a   b'"></ng-piao-liang-hanzi>

image

For clarity purposes, you can also use _ as a placeholder for empty pinyin:

<ng-piao-liang-hanzi [chineseCharacters]="'这是你的书。'" [pinyin]="'a _ _ b'"></ng-piao-liang-hanzi>

image

Enable alphabet for pinyin

Non-Chinese characters are skipped for pinyin by default, including alphabetical characters. To enable alphabetical characters, set [includeAlphabet]="true":

<ng-piao-liang-hanzi [chineseCharacters]="'是OK,马?'" [pinyin]="'shì O K shì'" [includeAlphabet]="true"></ng-piao-liang-hanzi>

image

The alphabet can be enabled for pinyin globally with the ENABLE_ALPHABET flag:

import { NgPiaoLiangHanziModule } from 'ng-piao-liang-hanzi';
@NgModule({
  imports: [NgPiaoLiangHanziModule],
  providers: [{provide: 'ENABLE_ALPHABET', useValue: true}]
})
export class AppModule { }

[includeAlphabet]="true" is then no longer needed. It is also possible to disable the alphabet in specific cases by setting [includeAlphabet]="false".

Set pinyin below characters

Pinyin are displayed on top of the hanzi characters by default. To display them on the bottom, set [bottomPinyin]="true":

<ng-piao-liang-hanzi [chineseCharacters]="'你好。'" [pinyin]="'nĭ hăo'" [bottomPinyin]="true"></ng-piao-liang-hanzi>

image

This feature can be enabled globally with the ENABLE_BOTTOM_PINYIN flag:

import { NgPiaoLiangHanziModule } from 'ng-piao-liang-hanzi';
@NgModule({
  imports: [NgPiaoLiangHanziModule],
  providers: [{provide: 'ENABLE_BOTTOM_PINYIN', useValue: true}]
})
export class AppModule { }

It is still possible to override the global flag locally with [bottomPinyin]="false".

CSS styling

The Chinese characters and pinyin can have custom css styling with classes ng-piao-liang-hanzi-char and ng-piao-liang-hanzi-pinyin respectively:

.ng-piao-liang-hanzi-char {
  color: olivedrab
}

.ng-piao-liang-hanzi-pinyin {
  color: brown
}

image

⚠️ The css styling will only work in global styles.css!

For example: https://github.com/AlexanderTang/PiaoLiangHanzi/blob/master/src/styles.scss

piaolianghanzi's People

Contributors

alexandertang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.