-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add X-PHONETIC-ORG field and the number of items next to group name (#…
…529) * Add X-PHONETIC-ORG field to enable alphabetical sorting on English language systems * Add the number of items in each group next to its nam * chore: replace hardcoded usernames with variables
- Loading branch information
Showing
7 changed files
with
43 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { pinyin } from 'pinyin-pro' | ||
|
||
const addPhoneticField = (text, fieldName) => { | ||
const regex = new RegExp(`${fieldName};CHARSET=UTF-8:(.*)\r?\n`, 'g'); | ||
return text.replace(regex, (match, value) => { | ||
const hasChinese = /[\u4e00-\u9fa5]/.test(value); | ||
const pinyinText = hasChinese ? | ||
pinyin(value, { toneType: 'none', nonZh: 'consecutive', type: 'array' }) | ||
.map(item => item[0].toUpperCase() + item.slice(1)) | ||
.join(' ') | ||
: value; | ||
return `${match}X-PHONETIC-${fieldName};CHARSET=UTF-8:${pinyinText}\n`; | ||
}); | ||
}; | ||
|
||
export default addPhoneticField; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters