Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

中文符号有问题, 有时2个符号只返回了一个拼音 #399

Open
fhtwl opened this issue Jan 14, 2025 · 1 comment
Open

中文符号有问题, 有时2个符号只返回了一个拼音 #399

fhtwl opened this issue Jan 14, 2025 · 1 comment

Comments

@fhtwl
Copy link

fhtwl commented Jan 14, 2025

比如:
七夕节,又叫“乞巧节”,发
生成的拼音:

 [
    "",
    "",
    "jié",
    "",
    "yòu",
    "jiào",
    "",
    "",
    "qiǎo",
    "jié",
    "”,",
    ""
  ]

中文引号和中文逗号成了一个拼音, 而不是2个
原代码:

import pinyin from 'pinyin';

@Injectable()
export class PinyinService {
  transform(text: string): string[] {
    return pinyin(text).map((item) => item[0]);
  }
}

版本 "pinyin": "4.0.0-alpha.2"

@hotoo
Copy link
Owner

hotoo commented Jan 14, 2025

是的,中文是会每个字拆开的,其他字符(比如标点、英文、数字等)都是整体拼接在一起的。
因为中文拼音会使用 join(' ') 拼接来展示,而其他字符需要保持原有格式,所以是不拆分的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants