Skip to content

Commit

Permalink
fix: unable to import module in ./lib/
Browse files Browse the repository at this point in the history
update: language list
  • Loading branch information
BANKA2017 committed Jan 21, 2024
1 parent b0354a7 commit 3d86999
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 21 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@kdwnil/translator-utils",
"private": true,
"version": "0.0.2-alpha.26",
"version": "0.0.2-alpha.27",
"description": "translate utils",
"homepage": "https://github.com/BANKA2017/translator-utils",
"bugs": {
Expand All @@ -20,6 +20,7 @@
"default": "./dist/esm/index.js"
}
},
"./lib/*": "./lib/*",
"./package.json": "./package.json"
},
"type": "module",
Expand Down
16 changes: 11 additions & 5 deletions scripts/language_list_types_builder.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ jsContent += `export type GOOGLE_LIST = ${Object.entries(google)
.join('|')}\n`
jsContent += `export const GOOGLE_LANGUAGE: TargetFilter['google'][] = [${Object.entries(google)
.map((lang) => "'" + lang[0] + "'")
.join(',')}]\n\n`
.join(',')}]\n`
jsContent += `export const GOOGLE_LANGUAGE_OBJECT: { [p in GOOGLE_LIST]: string } = ${JSON.stringify(google)}\n`

// microsoft content/type/tts
// JSON.stringify(Object.fromEntries([...tta_srcsl.querySelectorAll('option[aria-label]')].map(x => [x.value.toLowerCase(), x.innerText]).sort((a, b) => a[0] > b[0] ? 1 : -1)))
Expand All @@ -21,11 +22,12 @@ jsContent += `export type BING_LIST = ${Object.entries(microsoft)
jsContent += `export const BING_LANGUAGE: TargetFilter['microsoft'][] = [${Object.entries(microsoft)
.map((lang) => "'" + lang[0] + "'")
.join(',')}]\n`
jsContent += `export const BING_LANGUAGE_OBJECT: { [p in BING_LIST]: string } = ${JSON.stringify(microsoft)}\n`

const microsoft_tts = JSON.parse(readFileSync('../assets/target/microsoft_tts.json').toString())

jsContent += `export type BING_TTS_LIST = ${microsoft_tts.map((msttsItem) => "'" + msttsItem.code + "'").join('|')}\n`
jsContent += `export const MICROSOFT_TTS_LIST: { code: BING_TTS_LIST; language: string; gender: 'Male' | 'Female'; model: string }[] = ${JSON.stringify(microsoft_tts)}\n\n`
jsContent += `export const MICROSOFT_TTS_LIST: { code: BING_TTS_LIST; language: string; gender: 'Male' | 'Female'; model: string }[] = ${JSON.stringify(microsoft_tts)}\n`

// yandex content/type
// JSON.stringify(Object.fromEntries([...document.querySelectorAll('.langs-item.langs-item_cell.langs-item_hasLetterSpace')].map(x => [x.dataset.value.toLowerCase(), x.innerText.includes('\n') ? x.innerText.split('\n')[1].trim() : x.innerText.trim()]).sort((a, b) => a[0] > b[0] ? 1 : -1)))
Expand All @@ -35,7 +37,8 @@ jsContent += `export type YANDEX_LIST = ${Object.entries(yandex)
.join('|')}\n`
jsContent += `export const YANDEX_LANGUAGE: TargetFilter['yandex'][] = [${Object.entries(yandex)
.map((lang) => "'" + lang[0] + "'")
.join(',')}]\n\n`
.join(',')}]\n`
jsContent += `export const YANDEX_LANGUAGE_OBJECT: { [p in YANDEX_LIST]: string } = ${JSON.stringify(yandex)}\n`

// deepl content/type
const deepl = JSON.parse(readFileSync('../assets/target/deepl.json').toString())
Expand All @@ -44,7 +47,8 @@ jsContent += `export type DEEPL_LIST = ${Object.entries(deepl)
.join('|')}\n`
jsContent += `export const DEEPL_LANGUAGE: TargetFilter['deepl'][] = [${Object.entries(deepl)
.map((lang) => "'" + lang[0] + "'")
.join(',')}]\n\n`
.join(',')}]\n`
jsContent += `export const DEEPL_LANGUAGE_OBJECT: { [p in DEEPL_LIST]: string } = ${JSON.stringify(deepl)}\n`

// baidu content/type/tts
const baidu = JSON.parse(readFileSync('../assets/target/baidu.json').toString())
Expand All @@ -54,9 +58,10 @@ jsContent += `export type BAIDU_LIST = ${Object.entries(baidu)
jsContent += `export const BAIDU_LANGUAGE: TargetFilter['baidu'][] = [${Object.entries(baidu)
.map((lang) => "'" + lang[0] + "'")
.join(',')}]\n`
jsContent += `export const BAIDU_LANGUAGE_OBJECT: { [p in BAIDU_LIST]: string } = ${JSON.stringify(baidu)}\n`

const baidu_tts = JSON.parse(readFileSync('../assets/target/baidu_tts.json').toString())
jsContent += `export type BAIDU_TTS_LIST = ${baidu_tts.map((lang) => "'" + lang + "'").join('|')}\n\n`
jsContent += `export type BAIDU_TTS_LIST = ${baidu_tts.map((lang) => "'" + lang + "'").join('|')}\n`

// sogou
const sogou = JSON.parse(readFileSync('../assets/target/sogou.json').toString())
Expand All @@ -66,6 +71,7 @@ jsContent += `export type SOGOU_LIST = ${Object.entries(sogou)
jsContent += `export const SOGOU_LANGUAGE: TargetFilter['sogou'][] = [${Object.entries(sogou)
.map((lang) => "'" + lang[0] + "'")
.join(',')}]\n`
jsContent += `export const SOGOU_LANGUAGE_OBJECT: { [p in SOGOU_LIST]: string } = ${JSON.stringify(sogou)}\n`

jsContent += `export type SOGOU_TTS_LIST = Exclude<SOGOU_LIST, 'tr'>\n`

Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaiduLanguagePredict, BaiduTranslator, GetBaiduTranslatorToken, BaiduTTS } from './source/baidu.js'
import { DeepL } from './source/deepl.js'
import { GoogleTranslate, GoogleBrowserTranslate, GoogleTTS } from './source/google.js'
import { GoogleTranslate, GoogleBrowserTranslate, GoogleTTS, GoogleTranslateTk } from './source/google.js'
import { MicrosoftTranslator, MicrosoftBrowserTranslator, GetMicrosoftBrowserTranslatorAuth, GetMicrosoftTranslatorToken, MicrosoftBrowserPredict, MicrosoftTTS } from './source/microsoft.js'
import { SogouBrowserTranslator, SogouTTS } from './source/sogou.js'
import { YandexDetect, YandexTranslator, YandexBrowserTranslator } from './source/yandex.js'
Expand Down Expand Up @@ -62,6 +62,7 @@ export {
YandexBrowserTranslator
}
export { GetBaiduTranslatorToken, GetMicrosoftBrowserTranslatorAuth, GetMicrosoftTranslatorToken }
export { GoogleTranslateTk }
export { IsChs, IsCht }
export { GoogleTTS, MicrosoftTTS, BaiduTTS, SogouTTS }
export default Translator
Loading

0 comments on commit 3d86999

Please sign in to comment.