Skip to content

Commit

Permalink
feat: voerkai18n extract 支持指定提取目录
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangfisher committed Sep 19, 2024
1 parent 67277f4 commit c63eddc
Show file tree
Hide file tree
Showing 26 changed files with 655 additions and 442 deletions.
10 changes: 10 additions & 0 deletions docs/zh/guide/intro/history.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# 更新日志<!-- {docsify-ignore-all} -->

## V2.1.10

- **[特性]** `@voerkai18n/cli``extract`原来总是从src中提取文本,现在支持指定从哪个文件夹中提取文本。

```shell
# 从public文件夹中提取文本
voerkai18n extract public
```


## V2.1.9

- **[Build]**`@voerkai18n/react``react`的版本依赖降低到`16.9.0`,以支持低版本的`react`
Expand Down
1 change: 1 addition & 0 deletions examples/vue3-ts/src/components/china.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
<h3>{{ t("成立于{}年",1949)}} </h3>
<h3>{{ t("首都:北京")}} </h3>
<h3>{{ t("首都:{city}",{city:"北京"})}} </h3>
<h3>{{ t("{count}人在等你聊天哦",{count:100}) }} </h3>
</div>
</template>

Expand Down
3 changes: 2 additions & 1 deletion examples/vue3-ts/src/languages/cht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export default {
"21": "{ value | currency({symbol:'¥¥',prefix:'人民币:',suffix:'元整',unit:2})}",
"22": "{ value | currency({symbol:'¥¥',prefix:'人民币:',suffix:'元整',unit:2,precision:4})}",
"23": "hello",
"24": "首都:{city}"
"24": "首都:{city}",
"25": "{count}人在等你聊天哦"
}
3 changes: 2 additions & 1 deletion examples/vue3-ts/src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export default {
"21": "{ value | currency({symbol:'¥¥',prefix:'人民币:',suffix:'元整',unit:2})}",
"22": "{ value | currency({symbol:'¥¥',prefix:'人民币:',suffix:'元整',unit:2,precision:4})}",
"23": "Hello",
"24": "English:{city}"
"24": "English:{city}",
"25": "{count} people are waiting for you to chat"
}
3 changes: 2 additions & 1 deletion examples/vue3-ts/src/languages/idMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export default {
"{ value | currency({symbol:'¥¥',prefix:'人民币:',suffix:'元整',unit:2})}": 21,
"{ value | currency({symbol:'¥¥',prefix:'人民币:',suffix:'元整',unit:2,precision:4})}": 22,
"hello": 23,
"首都:{city}": 24
"首都:{city}": 24,
"{count}人在等你聊天哦": 25
}
3 changes: 2 additions & 1 deletion examples/vue3-ts/src/languages/jp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export default {
"21": "{ value | currency({symbol:'¥¥',prefix:'人民币:',suffix:'元整',unit:2})}",
"22": "{ value | currency({symbol:'¥¥',prefix:'人民币:',suffix:'元整',unit:2,precision:4})}",
"23": "hello",
"24": "首都:{city}"
"24": "首都:{city}",
"25": "{count}人在等你聊天哦"
}
8 changes: 8 additions & 0 deletions examples/vue3-ts/src/languages/translates/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,13 @@
"$files": [
"components\\china.vue"
]
},
"{count}人在等你聊天哦": {
"en": "{count} people are waiting for you to chat",
"jp": "{count}人在等你聊天哦",
"cht": "{count}人在等你聊天哦",
"$files": [
"components\\china.vue"
]
}
}
3 changes: 2 additions & 1 deletion examples/vue3-ts/src/languages/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export default {
"21": "{ value | currency({symbol:'¥¥',prefix:'人民币:',suffix:'元整',unit:2})}",
"22": "{ value | currency({symbol:'¥¥',prefix:'人民币:',suffix:'元整',unit:2,precision:4})}",
"23": "hello",
"24": "首都:{city}"
"24": "首都:{city}",
"25": "{count}人在等你聊天哦"
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"prettier": "^2.7.1",
"semver": "^7.5.4",
"shelljs": "^0.8.5",
"turbo": "^2.1.2",
"vinyl": "^2.2.1",
"yalc": "1.0.0-pre.53",
"yorkie": "^2.0.0"
Expand All @@ -43,11 +44,12 @@
"tips": "请安装JsonComments插件,详见https://github.com/zhangfisher/json_comments_extension",
"package.json": {
"scripts.test:runtime": "运行@voerkai18n/runtime单元测试",
"scripts.build:all": "构建所有包",
"scripts.build:all": "构建所有包",
"scripts.version:patch:all": "升级所有包的Patch版本号",
"scripts.changeset": "当更新后执行以更新变更历史",
"scripts.sync": "同步淘宝镜像",
"scripts.release:all": "一健自动化发布所有包"
}
}
},
"packageManager": "[email protected]"
}
7 changes: 4 additions & 3 deletions packages/cli/extract.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ program
.option('-e, --exclude <folders>', t('排除要扫描的文件夹,多个用逗号分隔'))
.option('-u, --updateMode <value>', t('本次提取内容与已存在内容的数据合并策略,默认取值sync=同步,overwrite=覆盖,merge=合并'), 'sync')
.option('-f, --filetypes <values...> ', t('要扫描的文件类型'),[])
.argument('[location]', t('工程项目所在目录'),"./")
.hook("preAction",async function(location){
.argument('[location]', t('指定从该目录提取'))
.hook("preAction",async function(){
await i18nScope.change(getCliLanguage())
})
.action(async (location,options) => {
Expand All @@ -99,7 +99,8 @@ program

logger.log(t("工程目录:{}"), options.srcPath)
logger.log(t("语言目录:{}"),options.entry)
extract(options.srcPath,options)
const extractFrom =location==undefined ? location : (path.isAbsolute(location) ? location : path.join(process.cwd(),location))
extract(extractFrom || options.srcPath,options)
});


Expand Down
3 changes: 2 additions & 1 deletion packages/cli/languages/cht.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ module.exports = {
"86": "創建語言包資料夾",
"87": "生成語言設定檔settings.json",
"88": "初始化語言上下文",
"89": "調用翻譯API時出錯:{}"
"89": "調用翻譯API時出錯:{}",
"90": "指定從該目錄選取"
}
3 changes: 2 additions & 1 deletion packages/cli/languages/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ module.exports = {
"86": "Ordner für Sprachpakete erstellen",
"87": "Sprachkonfigurationsdatei settings.json generieren",
"88": "Sprachkontext initialisieren",
"89": "Fehler beim Aufruf der Übersetzungs-API: {}"
"89": "Fehler beim Aufruf der Übersetzungs-API: {}",
"90": "Geben Sie an, aus diesem Verzeichnis zu extrahieren"
}
3 changes: 2 additions & 1 deletion packages/cli/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ module.exports = {
"86": "Create Language Pack Folder",
"87": "Generate language configuration file settings.json",
"88": "Initialize Language Context",
"89": "Error calling translation API: {}"
"89": "Error calling translation API: {}",
"90": "Specify to extract from this directory"
}
3 changes: 2 additions & 1 deletion packages/cli/languages/fra.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ module.exports = {
"86": "Créer un dossier Language Pack",
"87": "Générer le profil de langue settings.json",
"88": "Initialiser le contexte linguistique",
"89": "Erreur lors de l'appel de l'API de traduction: {variable}"
"89": "Erreur lors de l'appel de l'API de traduction: {variable}",
"90": "Spécifie l'extraction à partir de ce répertoire"
}
3 changes: 2 additions & 1 deletion packages/cli/languages/idMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ module.exports = {
"创建语言包文件夹": 86,
"生成语言配置文件settings.json": 87,
"初始化语言上下文": 88,
"调用翻译API时出错:{}": 89
"调用翻译API时出错:{}": 89,
"指定从该目录提取": 90
}
2 changes: 1 addition & 1 deletion packages/cli/languages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 注意:执行compile命令会重新生成本文件,所以请不要修改本文件
*/
const idMap = require("./idMap")
const { translate,VoerkaI18nScope } = require("../../runtime/dist")
const { translate,VoerkaI18nScope } = require("@voerkai18n/runtime")
const defaultFormatters = require("./formatters/zh.js")
const defaultMessages = require("./zh.js")
const storage = require("./storage.js")
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/languages/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ module.exports = {
"86": "Crea cartella Language Pack",
"87": "Genera impostazioni del file di configurazione della lingua.json",
"88": "Inizializza contesto linguistico",
"89": "Errore nel chiamare API di traduzione: {}"
"89": "Errore nel chiamare API di traduzione: {}",
"90": "Specifica da estrarre da questa directory"
}
3 changes: 2 additions & 1 deletion packages/cli/languages/jp.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ module.exports = {
"86": "Language Packフォルダの作成",
"87": "言語プロファイルsettings.jsonを生成する",
"88": "言語コンテキストの初期化",
"89": "翻訳APIの呼び出し中にエラーが発生しました:{}"
"89": "翻訳APIの呼び出し中にエラーが発生しました:{}",
"90": "ディレクトリからの抽出の指定"
}
3 changes: 2 additions & 1 deletion packages/cli/languages/kor.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ module.exports = {
"86": "언어 팩 폴더 만들기",
"87": "언어 구성 파일 생성 settings.json",
"88": "언어 컨텍스트 초기화",
"89": "번역 API를 호출하는 중 오류 발생: {}"
"89": "번역 API를 호출하는 중 오류 발생: {}",
"90": "디렉토리에서 추출 지정"
}
3 changes: 2 additions & 1 deletion packages/cli/languages/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ module.exports = {
"86": "Создание папки языковых пакетов",
"87": "Создание языкового профиля settings.json",
"88": "Контекст языка инициализации",
"89": "Ошибка вызова интерфейса перевода: {Variable}"
"89": "Ошибка вызова интерфейса перевода: {Variable}",
"90": "Назначить извлечение из каталога"
}
3 changes: 2 additions & 1 deletion packages/cli/languages/spa.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ module.exports = {
"86": "Crear una carpeta de paquetes de idiomas",
"87": "Generar el archivo de configuración del lenguaje settings.json",
"88": "Iniciar el contexto del lenguaje",
"89": "Se produjo un error al llamar a la API de traducción: @ variable.."
"89": "Se produjo un error al llamar a la API de traducción: @ variable..",
"90": "Especifica la extracción de este catálogo"
}
14 changes: 14 additions & 0 deletions packages/cli/languages/translates/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -1250,5 +1250,19 @@
"$files": [
"translate.command.js"
]
},
"指定从该目录提取": {
"cht": "指定從該目錄選取",
"en": "Specify to extract from this directory",
"de": "Geben Sie an, aus diesem Verzeichnis zu extrahieren",
"jp": "ディレクトリからの抽出の指定",
"fra": "Spécifie l'extraction à partir de ce répertoire",
"spa": "Especifica la extracción de este catálogo",
"kor": "디렉토리에서 추출 지정",
"ru": "Назначить извлечение из каталога",
"it": "Specifica da estrarre da questa directory",
"$files": [
"extract.command.js"
]
}
}
3 changes: 2 additions & 1 deletion packages/cli/languages/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ module.exports = {
"86": "创建语言包文件夹",
"87": "生成语言配置文件settings.json",
"88": "初始化语言上下文",
"89": "调用翻译API时出错:{}"
"89": "调用翻译API时出错:{}",
"90": "指定从该目录提取"
}
1 change: 1 addition & 0 deletions packages/cli/translate.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ async function translateMessages(messages={},from="zh",to="en",options={}){
try{
translatedMessages =await provider.translate(replacedMessages,from,to)
}catch(e){
console.error(e)
throw new Error(t('调用翻译API时出错:{}',e.message))
}

Expand Down
Loading

0 comments on commit c63eddc

Please sign in to comment.