From 842a3290c00c16dd4d34fe8e53f77362fa727eb4 Mon Sep 17 00:00:00 2001 From: SkyEye_FAST Date: Mon, 20 May 2024 00:17:06 +0800 Subject: [PATCH] Update --- .github/workflows/pylint.yml | 23 ++++++++++ data/fixed_zh_cy.json | 3 +- data/fixed_zh_gr.json | 3 +- data/fixed_zh_py.json | 3 +- data/fixed_zh_wg.json | 3 +- output/zh_cy.json | 8 ++-- output/zh_gr.json | 8 ++-- output/zh_py.json | 8 ++-- output/zh_wg.json | 8 ++-- output/zh_xj.json | 2 +- pack.py | 84 +++++++++++++++++++++++------------- 11 files changed, 103 insertions(+), 50 deletions(-) create mode 100644 .github/workflows/pylint.yml diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 0000000..28e9a16 --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,23 @@ +name: Pylint + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.12"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pylint + pip install -r requirements.txt + - name: Analysing the code with pylint + run: pylint $(git ls-files '*.py') diff --git a/data/fixed_zh_cy.json b/data/fixed_zh_cy.json index adee512..1fb6569 100644 --- a/data/fixed_zh_cy.json +++ b/data/fixed_zh_cy.json @@ -229,5 +229,6 @@ "debug.gamemodes.press_f4": "[ F4 ]", "optimizeWorld.stage.failed": "Шибай лэ! :(", "selectWorld.allowCommands.info": "Лижу /gamemode、/experience дэн минлин", - "language.code": "Zho-Hans_CN" + "language.code": "Zho-Hans_CN", + "painting.minecraft.sunset.title": "sunset_dense" } \ No newline at end of file diff --git a/data/fixed_zh_gr.json b/data/fixed_zh_gr.json index 7203298..d7e10f4 100644 --- a/data/fixed_zh_gr.json +++ b/data/fixed_zh_gr.json @@ -229,5 +229,6 @@ "debug.gamemodes.press_f4": "[ F4 ]", "optimizeWorld.stage.failed": "Shybay .lhe!:(", "selectWorld.allowCommands.info": "Lihru /gamemode、/experience deeng minqlinq", - "language.code": "Zho-Hans_CN" + "language.code": "Zho-Hans_CN", + "painting.minecraft.sunset.title": "sunset_dense" } \ No newline at end of file diff --git a/data/fixed_zh_py.json b/data/fixed_zh_py.json index e52c391..2ef79d3 100644 --- a/data/fixed_zh_py.json +++ b/data/fixed_zh_py.json @@ -229,5 +229,6 @@ "debug.gamemodes.press_f4": "[ F4 ]", "optimizeWorld.stage.failed": "Shībài le!:(", "selectWorld.allowCommands.info": "Lìrú /gamemode、/experience děng mìnglìng", - "language.code": "Zho-Hans_CN" + "language.code": "Zho-Hans_CN", + "painting.minecraft.sunset.title": "sunset_dense" } \ No newline at end of file diff --git a/data/fixed_zh_wg.json b/data/fixed_zh_wg.json index 6accfbc..1b344d5 100644 --- a/data/fixed_zh_wg.json +++ b/data/fixed_zh_wg.json @@ -229,5 +229,6 @@ "debug.gamemodes.press_f4": "[ F4 ]", "optimizeWorld.stage.failed": "Shih¹-pai⁴ le⁵!:(", "selectWorld.allowCommands.info": "Li⁴-ju² /gamemode、/experience teng³ ming⁴-ling⁴", - "language.code": "Zho-Hans_CN" + "language.code": "Zho-Hans_CN", + "painting.minecraft.sunset.title": "sunset_dense" } \ No newline at end of file diff --git a/output/zh_cy.json b/output/zh_cy.json index 0720f26..aae0974 100644 --- a/output/zh_cy.json +++ b/output/zh_cy.json @@ -4658,9 +4658,9 @@ "lectern.take_book": "Цюйшу", "loading.progress": "%s%%", "mco.account.privacy.info": "Юэду гэн до гуаньюй Mojang хэ цита иньсы чжэнцэ дэ синьси", - "mco.account.privacy.info.button": "Юэду гуаньюй 《тунюн шуцзюйбаоху тяоли》 дэ нэйжун", - "mco.account.privacy.information": "Mojang шиши сюйдо фанфа лай банчжу баоху эртун цзици иньсыцюань, баоко люйсин 《эртун цзайсянь иньсыцюань баоху фаань》 (COPPA) юй 《тунюн шуцзюйбаоху тяоли》 (GDPR) . \n\nЦзай цюйдэ Realms чжанху фанвэнь цюань чжицянь, ни кэнэн сюйяо ходэ фуму дэ туни. ", - "mco.account.privacyinfo": "Mojang шиши сюйдо фанфа лай цуцзинь эртун цзици иньсыцюань дэ баоху, баоко люйсин 《эртун цзайсянь иньсыцюань баоху фаань》 (COPPA) юй 《тунюн шуцзюйбаоху тяоли》 (GDPR) . \n\nЦзай фанвэнь ни дэ Realms чжанху чжицянь, ни кэнэн сюйяо чжэндэ фуму дэ туни. \n\nЖуго ни юню дэ ши цзюбань дэ Minecraft чжанху (дэнлу ши шиюн юнхумин) , ни сюйяо цзян ци хэбин дао Mojang чжанху и фанвэнь Realms. ", + "mco.account.privacy.info.button": "Юэду гуаньюй 《Тунюн Шуцзюйбаоху Тяоли》 дэ нэйжун", + "mco.account.privacy.information": "Mojang шиши сюйдо фанфа лай банчжу баоху эртун цзици иньсыцюань, баоко люйсин 《Эртун Цзайсянь Иньсыцюань Баоху Фаань》 (COPPA) юй 《Тунюн Шуцзюйбаоху Тяоли》 (GDPR) . \n\nЦзай цюйдэ Realms чжанху фанвэнь цюань чжицянь, ни кэнэн сюйяо ходэ фуму дэ туни. ", + "mco.account.privacyinfo": "Mojang шиши сюйдо фанфа лай цуцзинь эртун цзици иньсыцюань дэ баоху, баоко люйсин 《Эртун Цзайсянь Иньсыцюань Баоху Фаань》 (COPPA) юй 《Тунюн Шуцзюйбаоху Тяоли》 (GDPR) . \n\nЦзай фанвэнь ни дэ Realms чжанху чжицянь, ни кэнэн сюйяо чжэндэ фуму дэ туни. \n\nЖуго ни юню дэ ши цзюбань дэ Minecraft чжанху (дэнлу ши шиюн юнхумин) , ни сюйяо цзян ци хэбин дао Mojang чжанху и фанвэнь Realms. ", "mco.account.update": "Гэнсинь чжанху", "mco.activity.noactivity": "Гоцюй %s тяньу дунтай", "mco.activity.title": "Ваньцзя дунтай", @@ -5499,7 +5499,7 @@ "painting.minecraft.sunflowers.author": "Kristoffer Zetterstrand", "painting.minecraft.sunflowers.title": "Sunflowers", "painting.minecraft.sunset.author": "Kristoffer Zetterstrand", - "painting.minecraft.sunset.title": "Sunset_dense", + "painting.minecraft.sunset.title": "sunset_dense", "painting.minecraft.tides.author": "Kristoffer Zetterstrand", "painting.minecraft.tides.title": "Tides", "painting.minecraft.unpacked.author": "Sarah Boeving", diff --git a/output/zh_gr.json b/output/zh_gr.json index 560983b..68b2227 100644 --- a/output/zh_gr.json +++ b/output/zh_gr.json @@ -4658,9 +4658,9 @@ "lectern.take_book": "Cheushu", "loading.progress": "%s%%", "mco.account.privacy.info": "Yuehdwu genq duo guanyu Mojang her chyita yiinsy jenqtseh .de shinnshi", - "mco.account.privacy.info.button": "Yuehdwu guanyu 《tongyonq shuhjiuhbaohuh tyaulih》 .de neyrong", - "mco.account.privacy.information": "Mojang shyrshy sheuduo fangfaa lai bangjuh baohuh erltorng jyichyi yiinsychyuan, baukuoh leushyng 《erltorng tzayshiann yiinsychyuan baohuh faaann》 (COPPA) yeu 《tongyonq shuhjiuhbaohuh tyaulih》 (GDPR) . \n\nTzay cheuder Realms janqhuh faangwenn chyuan jychyan, nii keeneng shiuyaw huohder fuhmuu .de torngyih. ", - "mco.account.privacyinfo": "Mojang shyrshy sheuduo fangfaa lai tsuhjinn erltorng jyichyi yiinsychyuan .de baohuh, baukuoh leushyng 《erltorng tzayshiann yiinsychyuan baohuh faaann》 (COPPA) yeu 《tongyonq shuhjiuhbaohuh tyaulih》 (GDPR) . \n\nTzay faangwenn nii .de Realms janqhuh jychyan, nii keeneng shiuyaw jengder fuhmuu .de torngyih. \n\nRuguoo nii iongyeou .de shyh jiowbaan .de Minecraft janqhuh (dengluh shyr shyyyonq yonqhuhming) , nii shiuyaw jiang chyi herbinq daw Mojang janqhuh yii faangwenn Realms. ", + "mco.account.privacy.info.button": "Yuehdwu guanyu 《Tongyonq Shuhjiuhbaohuh Tyaulih》 .de neyrong", + "mco.account.privacy.information": "Mojang shyrshy sheuduo fangfaa lai bangjuh baohuh erltorng jyichyi yiinsychyuan, baukuoh leushyng 《Erltorng Tzayshiann Yiinsychyuan Baohuh Faaann》 (COPPA) yeu 《Tongyonq Shuhjiuhbaohuh Tyaulih》 (GDPR) . \n\nTzay cheuder Realms janqhuh faangwenn chyuan jychyan, nii keeneng shiuyaw huohder fuhmuu .de torngyih. ", + "mco.account.privacyinfo": "Mojang shyrshy sheuduo fangfaa lai tsuhjinn erltorng jyichyi yiinsychyuan .de baohuh, baukuoh leushyng 《Erltorng Tzayshiann Yiinsychyuan Baohuh Faaann》 (COPPA) yeu 《Tongyonq Shuhjiuhbaohuh Tyaulih》 (GDPR) . \n\nTzay faangwenn nii .de Realms janqhuh jychyan, nii keeneng shiuyaw jengder fuhmuu .de torngyih. \n\nRuguoo nii iongyeou .de shyh jiowbaan .de Minecraft janqhuh (dengluh shyr shyyyonq yonqhuhming) , nii shiuyaw jiang chyi herbinq daw Mojang janqhuh yii faangwenn Realms. ", "mco.account.update": "Gengshin janqhuh", "mco.activity.noactivity": "Guohchiuh %s tianwu donqtay", "mco.activity.title": "Wanjia donqtay", @@ -5499,7 +5499,7 @@ "painting.minecraft.sunflowers.author": "Kristoffer Zetterstrand", "painting.minecraft.sunflowers.title": "Sunflowers", "painting.minecraft.sunset.author": "Kristoffer Zetterstrand", - "painting.minecraft.sunset.title": "Sunset_dense", + "painting.minecraft.sunset.title": "sunset_dense", "painting.minecraft.tides.author": "Kristoffer Zetterstrand", "painting.minecraft.tides.title": "Tides", "painting.minecraft.unpacked.author": "Sarah Boeving", diff --git a/output/zh_py.json b/output/zh_py.json index 1ebdb2a..c423329 100644 --- a/output/zh_py.json +++ b/output/zh_py.json @@ -4658,9 +4658,9 @@ "lectern.take_book": "Qǔshū", "loading.progress": "%s%%", "mco.account.privacy.info": "Yuèdú gèng duō guānyú Mojang hé qítā yǐnsī zhèngcè de xìnxī", - "mco.account.privacy.info.button": "Yuèdú guānyú 《tōngyòng shùjùbǎohù tiáolì》 de nèiróng", - "mco.account.privacy.information": "Mojang shíshī xǔduō fāngfǎ lái bāngzhù bǎohù értóng jíqí yǐnsīquán, bāokuò lǚxíng 《értóng zàixiàn yǐnsīquán bǎohù fǎ'àn》 (COPPA) yǔ 《tōngyòng shùjùbǎohù tiáolì》 (GDPR) . \n\nZài qǔdé Realms zhànghù fǎngwèn quán zhīqián, nǐ kěnéng xūyào huòdé fùmǔ de tóngyì. ", - "mco.account.privacyinfo": "Mojang shíshī xǔduō fāngfǎ lái cùjìn értóng jíqí yǐnsīquán de bǎohù, bāokuò lǚxíng 《értóng zàixiàn yǐnsīquán bǎohù fǎ'àn》 (COPPA) yǔ 《tōngyòng shùjùbǎohù tiáolì》 (GDPR) . \n\nZài fǎngwèn nǐ de Realms zhànghù zhīqián, nǐ kěnéng xūyào zhēngdé fùmǔ de tóngyì. \n\nRúguǒ nǐ yōngyǒu de shì jiùbǎn de Minecraft zhànghù (dēnglù shí shǐyòng yònghùmíng) , nǐ xūyào jiāng qí hébìng dào Mojang zhànghù yǐ fǎngwèn Realms. ", + "mco.account.privacy.info.button": "Yuèdú guānyú 《Tōngyòng Shùjùbǎohù Tiáolì》 de nèiróng", + "mco.account.privacy.information": "Mojang shíshī xǔduō fāngfǎ lái bāngzhù bǎohù értóng jíqí yǐnsīquán, bāokuò lǚxíng 《Értóng Zàixiàn Yǐnsīquán Bǎohù Fǎ'àn》 (COPPA) yǔ 《Tōngyòng Shùjùbǎohù Tiáolì》 (GDPR) . \n\nZài qǔdé Realms zhànghù fǎngwèn quán zhīqián, nǐ kěnéng xūyào huòdé fùmǔ de tóngyì. ", + "mco.account.privacyinfo": "Mojang shíshī xǔduō fāngfǎ lái cùjìn értóng jíqí yǐnsīquán de bǎohù, bāokuò lǚxíng 《Értóng Zàixiàn Yǐnsīquán Bǎohù Fǎ'àn》 (COPPA) yǔ 《Tōngyòng Shùjùbǎohù Tiáolì》 (GDPR) . \n\nZài fǎngwèn nǐ de Realms zhànghù zhīqián, nǐ kěnéng xūyào zhēngdé fùmǔ de tóngyì. \n\nRúguǒ nǐ yōngyǒu de shì jiùbǎn de Minecraft zhànghù (dēnglù shí shǐyòng yònghùmíng) , nǐ xūyào jiāng qí hébìng dào Mojang zhànghù yǐ fǎngwèn Realms. ", "mco.account.update": "Gēngxīn zhànghù", "mco.activity.noactivity": "Guòqù %s tiānwú dòngtài", "mco.activity.title": "Wánjiā dòngtài", @@ -5499,7 +5499,7 @@ "painting.minecraft.sunflowers.author": "Kristoffer Zetterstrand", "painting.minecraft.sunflowers.title": "Sunflowers", "painting.minecraft.sunset.author": "Kristoffer Zetterstrand", - "painting.minecraft.sunset.title": "Sunset_dense", + "painting.minecraft.sunset.title": "sunset_dense", "painting.minecraft.tides.author": "Kristoffer Zetterstrand", "painting.minecraft.tides.title": "Tides", "painting.minecraft.unpacked.author": "Sarah Boeving", diff --git a/output/zh_wg.json b/output/zh_wg.json index c0bf80c..451b8fd 100644 --- a/output/zh_wg.json +++ b/output/zh_wg.json @@ -4658,9 +4658,9 @@ "lectern.take_book": "Ch'ü³-shu¹", "loading.progress": "%s%%", "mco.account.privacy.info": "Yüeh⁴-tu² keng⁴ to¹ kuan¹-yü² Mojang ho² ch'i²-t'a¹ yin³-ssu¹ cheng⁴-ts'e⁴ te⁵ hsin⁴-hsi¹", - "mco.account.privacy.info.button": "Yüeh⁴-tu² kuan¹-yü² 《t'ung¹-yung⁴ shu⁴-chü⁴-pao³-hu⁴ t'iao²-li⁴》 te⁵ nei⁴-jung²", - "mco.account.privacy.information": "Mojang shih²-shih¹ hsü³-to¹ fang¹-fa³ lai² pang¹-chu⁴ pao³-hu⁴ erh²-t'ung² chi²-ch'i² yin³-ssu¹-ch'üan², pao¹-k'uo⁴ lü³-hsing² 《erh²-t'ung² tsai⁴-hsien⁴ yin³-ssu¹-ch'üan² pao³-hu⁴ fa³-an⁴》 (COPPA) yü³ 《t'ung¹-yung⁴ shu⁴-chü⁴-pao³-hu⁴ t'iao²-li⁴》 (GDPR) . \n\nTsai⁴ ch'ü³-te² Realms chang⁴-hu⁴ fang³-wen⁴ ch'üan² chih¹-ch'ien², ni³ k'o³-neng² hsü¹-yao⁴ huo⁴-te² fu⁴-mu³ te⁵ t'ung²-i⁴. ", - "mco.account.privacyinfo": "Mojang shih²-shih¹ hsü³-to¹ fang¹-fa³ lai² ts'u⁴-chin⁴ erh²-t'ung² chi²-ch'i² yin³-ssu¹-ch'üan² te⁵ pao³-hu⁴, pao¹-k'uo⁴ lü³-hsing² 《erh²-t'ung² tsai⁴-hsien⁴ yin³-ssu¹-ch'üan² pao³-hu⁴ fa³-an⁴》 (COPPA) yü³ 《t'ung¹-yung⁴ shu⁴-chü⁴-pao³-hu⁴ t'iao²-li⁴》 (GDPR) . \n\nTsai⁴ fang³-wen⁴ ni³ te⁵ Realms chang⁴-hu⁴ chih¹-ch'ien², ni³ k'o³-neng² hsü¹-yao⁴ cheng¹-te² fu⁴-mu³ te⁵ t'ung²-i⁴. \n\nJu²-kuo³ ni³ yung¹-yu³ te⁵ shih⁴ chiu⁴-pan³ te⁵ Minecraft chang⁴-hu⁴ (teng¹-lu⁴ shih² shih³-yung⁴ yung⁴-hu⁴-ming²) , ni³ hsü¹-yao⁴ chiang¹ ch'i² ho²-ping⁴ tao⁴ Mojang chang⁴-hu⁴ i³ fang³-wen⁴ Realms. ", + "mco.account.privacy.info.button": "Yüeh⁴-tu² kuan¹-yü² 《T'ung¹-yung⁴ Shu⁴-chü⁴-pao³-hu⁴ T'iao²-li⁴》 te⁵ nei⁴-jung²", + "mco.account.privacy.information": "Mojang shih²-shih¹ hsü³-to¹ fang¹-fa³ lai² pang¹-chu⁴ pao³-hu⁴ erh²-t'ung² chi²-ch'i² yin³-ssu¹-ch'üan², pao¹-k'uo⁴ lü³-hsing² 《Erh²-t'ung² Tsai⁴-hsien⁴ Yin³-ssu¹-ch'üan² Pao³-hu⁴ Fa³-an⁴》 (COPPA) yü³ 《T'ung¹-yung⁴ Shu⁴-chü⁴-pao³-hu⁴ T'iao²-li⁴》 (GDPR) . \n\nTsai⁴ ch'ü³-te² Realms chang⁴-hu⁴ fang³-wen⁴ ch'üan² chih¹-ch'ien², ni³ k'o³-neng² hsü¹-yao⁴ huo⁴-te² fu⁴-mu³ te⁵ t'ung²-i⁴. ", + "mco.account.privacyinfo": "Mojang shih²-shih¹ hsü³-to¹ fang¹-fa³ lai² ts'u⁴-chin⁴ erh²-t'ung² chi²-ch'i² yin³-ssu¹-ch'üan² te⁵ pao³-hu⁴, pao¹-k'uo⁴ lü³-hsing² 《Erh²-t'ung² Tsai⁴-hsien⁴ Yin³-ssu¹-ch'üan² Pao³-hu⁴ Fa³-an⁴》 (COPPA) yü³ 《T'ung¹-yung⁴ Shu⁴-chü⁴-pao³-hu⁴ T'iao²-li⁴》 (GDPR) . \n\nTsai⁴ fang³-wen⁴ ni³ te⁵ Realms chang⁴-hu⁴ chih¹-ch'ien², ni³ k'o³-neng² hsü¹-yao⁴ cheng¹-te² fu⁴-mu³ te⁵ t'ung²-i⁴. \n\nJu²-kuo³ ni³ yung¹-yu³ te⁵ shih⁴ chiu⁴-pan³ te⁵ Minecraft chang⁴-hu⁴ (teng¹-lu⁴ shih² shih³-yung⁴ yung⁴-hu⁴-ming²) , ni³ hsü¹-yao⁴ chiang¹ ch'i² ho²-ping⁴ tao⁴ Mojang chang⁴-hu⁴ i³ fang³-wen⁴ Realms. ", "mco.account.update": "Keng¹-hsin¹ chang⁴-hu⁴", "mco.activity.noactivity": "Kuo⁴-ch'ü⁴ %s t'ien¹-wu² tung⁴-t'ai⁴", "mco.activity.title": "Wan²-chia¹ tung⁴-t'ai⁴", @@ -5499,7 +5499,7 @@ "painting.minecraft.sunflowers.author": "Kristoffer Zetterstrand", "painting.minecraft.sunflowers.title": "Sunflowers", "painting.minecraft.sunset.author": "Kristoffer Zetterstrand", - "painting.minecraft.sunset.title": "Sunset_dense", + "painting.minecraft.sunset.title": "sunset_dense", "painting.minecraft.tides.author": "Kristoffer Zetterstrand", "painting.minecraft.tides.title": "Tides", "painting.minecraft.unpacked.author": "Sarah Boeving", diff --git a/output/zh_xj.json b/output/zh_xj.json index 58a429a..dd11ad0 100644 --- a/output/zh_xj.json +++ b/output/zh_xj.json @@ -5499,7 +5499,7 @@ "painting.minecraft.sunflowers.author": "Kristoffer Zetterstrand", "painting.minecraft.sunflowers.title": "Sunflowers", "painting.minecraft.sunset.author": "Kristoffer Zetterstrand", - "painting.minecraft.sunset.title": "Sunset_dense", + "painting.minecraft.sunset.title": "sunset_dense", "painting.minecraft.tides.author": "Kristoffer Zetterstrand", "painting.minecraft.tides.title": "Tides", "painting.minecraft.unpacked.author": "Sarah Boeving", diff --git a/pack.py b/pack.py index e408b5a..ea71184 100644 --- a/pack.py +++ b/pack.py @@ -2,9 +2,10 @@ """Minecraft难视语言资源包生成器""" import json +import re import zipfile as zf from pathlib import Path -from typing import Callable, TypeAlias, Optional, Dict, List, Set +from typing import Callable, TypeAlias, Optional, Dict, List, Set, Tuple from romajitable import to_kana as tk from pypinyin import Style, lazy_pinyin, load_phrases_dict @@ -44,25 +45,25 @@ def load_json(file: str, folder: str = "data") -> Ldata: jieba.load_userdict(str(P / "data" / "dict.txt")) # 初始化其他自定义数据 -finals = tuple("aāááàoōóǒòeēéěè") # 可能的零声母开头 -pinyin_to_ipa = load_json("py2ipa") # 汉语拼音至IPA +finals: Tuple[str, ...] = tuple("aāááàoōóǒòeēéěè") # 可能的零声母开头 +pinyin_to_ipa: Ldata = load_json("py2ipa") # 汉语拼音至IPA tone_to_ipa: Ldata = {"1": "˥", "2": "˧˥", "3": "˨˩˦", "4": "˥˩", "5": ""} # IPA声调 -pinyin_to_wadegiles = load_json("py2wg") # 汉语拼音至威妥玛拼音 -pinyin_to_romatzyh = load_json("py2gr") # 汉语拼音至国语罗马字 -gr_values = set(pinyin_to_romatzyh.values()) # 国语罗马字的有效拼写 -pinyin_to_cyrillic = load_json("py2cy") # 汉语拼音至西里尔转写 -cy_values = set(pinyin_to_cyrillic.values()) # 西里尔转写的有效拼写 -pinyin_to_xiaojing = load_json("py2xj") # 汉语拼音至小儿经 - -rep_zh = load_json("rep_zh") # 连写的中文转写方案替换修正 -fixed_zh_py = load_json("fixed_zh_py") # 汉语拼音修正 -fixed_zh_wg = load_json("fixed_zh_wg") # 威妥玛拼音修正 -fixed_zh_gr = load_json("fixed_zh_gr") # 国语罗马字修正 -fixed_zh_cy = load_json("fixed_zh_cy") # 西里尔转写修正 -fixed_zh_xj = load_json("fixed_zh_xj") # 小儿经转写修正 - -rep_ja_kk = load_json("rep_ja_kk") # 片假名替换修正 -manyoganas_dict = load_json("manyogana") # 万叶假名 +pinyin_to_wadegiles: Ldata = load_json("py2wg") # 汉语拼音至威妥玛拼音 +pinyin_to_romatzyh: Ldata = load_json("py2gr") # 汉语拼音至国语罗马字 +gr_values: Set[str] = set(pinyin_to_romatzyh.values()) # 国语罗马字的有效拼写 +pinyin_to_cyrillic: Ldata = load_json("py2cy") # 汉语拼音至西里尔转写 +cy_values: Set[str] = set(pinyin_to_cyrillic.values()) # 西里尔转写的有效拼写 +pinyin_to_xiaojing: Ldata = load_json("py2xj") # 汉语拼音至小儿经 + +rep_zh: Ldata = load_json("rep_zh") # 连写的中文转写方案替换修正 +fixed_zh_py: Ldata = load_json("fixed_zh_py") # 汉语拼音修正 +fixed_zh_wg: Ldata = load_json("fixed_zh_wg") # 威妥玛拼音修正 +fixed_zh_gr: Ldata = load_json("fixed_zh_gr") # 国语罗马字修正 +fixed_zh_cy: Ldata = load_json("fixed_zh_cy") # 西里尔转写修正 +fixed_zh_xj: Ldata = load_json("fixed_zh_xj") # 小儿经转写修正 + +rep_ja_kk: Ldata = load_json("rep_ja_kk") # 片假名替换修正 +manyoganas_dict: Ldata = load_json("manyogana") # 万叶假名 # 读取语言文件 data: Dict[str, Ldata] = { @@ -105,6 +106,35 @@ def capitalize_lines(text: str) -> str: return text[:1].upper() + text[1:] +def capitalize_titles(text: str) -> str: + """ + 将字符串中书名号(《》)中的单词全部作首字母大写处理。 + + Args: + text (str): 需要转换的字符串 + + Returns: + str: 转换结果 + """ + + def title_case_content(content: str) -> str: + """ + 将书名号中的内容首字母大写。 + + Args: + content (str): 书名号中的内容。 + + Returns: + str: 首字母大写后的书名号内容。 + """ + + return " ".join(word.capitalize() for word in content.split()) + + return re.sub( + r"《(.*?)》", lambda match: f"《{title_case_content(match.group(1))}》", text + ) + + def add_apostrophes(input_list: List[str], values: Set[str]) -> List[str]: """ 处理隔音符号。 @@ -153,8 +183,7 @@ def to_manyogana(text: str) -> str: str: 转换结果 """ - text = to_katakana(text) - return "".join([manyoganas_dict.get(char, char) for char in text]) + return "".join([manyoganas_dict.get(char, char) for char in to_katakana(text)]) def to_pinyin(text: str) -> str: @@ -182,7 +211,7 @@ def to_pinyin(text: str) -> str: # 调整格式 result = replace_multiple(" ".join(output_list), rep_zh) - return capitalize_lines(result) + return capitalize_lines(capitalize_titles(result)) def to_ipa(text: str) -> str: @@ -241,7 +270,7 @@ def to_wadegiles(text: str) -> str: # 调整格式 result = replace_multiple(" ".join(output_list), rep_zh) - return capitalize_lines(result) + return capitalize_lines(capitalize_titles(result)) def to_romatzyh(text: str) -> str: @@ -266,7 +295,7 @@ def to_romatzyh(text: str) -> str: result = replace_multiple(" ".join(output_list), rep_zh) # 调整格式 - return capitalize_lines(result) + return capitalize_lines(capitalize_titles(result)) def to_cyrillic(text: str) -> str: @@ -290,7 +319,7 @@ def to_cyrillic(text: str) -> str: result = replace_multiple(" ".join(output_list), rep_zh) # 调整格式 - return capitalize_lines(result) + return capitalize_lines(capitalize_titles(result)) def to_xiaojing(text: str) -> str: @@ -312,10 +341,7 @@ def to_xiaojing(text: str) -> str: xj_list = [pinyin_to_xiaojing.get(p, p) for p in pinyin_list] output_list.append("\u200c".join(xj_list)) - # 调整格式 - result = replace_multiple(" ".join(output_list), rep_zh) - - return capitalize_lines(result) + return replace_multiple(" ".join(output_list), rep_zh) def save_to_json(