Skip to content

Commit

Permalink
西元2024年05月08日 (週三) 03時15分24秒 CST
Browse files Browse the repository at this point in the history
  • Loading branch information
pulipulichen committed May 7, 2024
1 parent ec2a791 commit c6d1aff
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 20 deletions.
10 changes: 5 additions & 5 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vendors/TextPanel.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vendors/TextPanel.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
<button type="button" class="ui button" v-on:click="saveAsSheet"
v-bind:class="{'disabled': outputButtonDisabled }">
<i class="table icon"></i>
Save
Save ODS
</button>
<button type="button" class="ui button" v-on:click="saveAsSheetCSV"
v-bind:class="{'disabled': outputButtonDisabled }">
<i class="table icon"></i>
Save CSV
</button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,28 @@ let TextOutputEmbbedingPanel = {

this.config.state.processOutputWait = false
},

saveAsSheetCSV: async function () {
this.config.state.processOutputWait = true

let appendFilename = '_embed_' + this.utils.Date.mmddhhmm()
var filename = this.config.session.inputFilename + appendFilename + ".csv"

var wb = XLSX.utils.book_new();

wb.SheetNames.push("data")

let ws = this.utils.Sheet.aoa_to_sheet(this.cacheOutputArray)
//console.log(ws)
wb.Sheets["data"] = ws

//var wbout = XLSX.write(wb, {bookType: 'ods', bookSST: true, type: 'base64'});
//let filename = 'jieba-js-config_' + (new Date()).mmddhhmm() + '.ods'
//saveAs(new Blob([this.s2ab(wbout)], {type: "application/octet-stream"}), filename);

XLSX.writeFile(wb, filename);

this.config.state.processOutputWait = false
},

initOutput: async function () {
if (this.cacheOutput.length === 0) {
Expand All @@ -105,6 +126,22 @@ let TextOutputEmbbedingPanel = {
},

startProcess: async function () {
if (window.confirm(`Process model requires a long time. Will you continue?`) === false) {
return false
}

let cache = this.$parent.$refs.TextOutputTransPanel.cacheTrans

if (cache.length === 0) {
// console.log('go')
await this.$parent.$refs.TextOutputTransPanel.startTrans(false)
cache = this.$parent.$refs.TextOutputTransPanel.cacheTrans
// console.log('go2', cache, cache.length)
if (cache.length === 0) {
return false
}
}

this.config.state.processOutputWait = true

//let e = await this.parseSentenceEmbedding('This is a pen.')
Expand All @@ -114,7 +151,7 @@ let TextOutputEmbbedingPanel = {
return this.cacheOutput
}

let cache = this.$parent.$refs.TextOutputTransPanel.cacheTrans


for (let i = 0; i < cache.length; i++) {
let row = cache[i]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
<button type="button" class="ui button" v-on:click="saveAsSheet"
v-bind:class="{'disabled': outputButtonDisabled }">
<i class="table icon"></i>
Save
Save ODS
</button>
<button type="button" class="ui button" v-on:click="saveAsSheetCSV"
v-bind:class="{'disabled': outputButtonDisabled }">
<i class="table icon"></i>
Save CSV
</button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ let TextOutputTransPanel = {
return output
}
},
mounted() {
// mounted() {

},
// },
methods: {
copy() {
this.$refs.outputTransTextarea.select()
Expand Down Expand Up @@ -86,15 +86,44 @@ let TextOutputTransPanel = {

this.config.state.processOutputWait = false
},

saveAsSheetCSV: async function () {
this.config.state.processOutputWait = true // ok

let appendFilename = '_trans_' + this.utils.Date.mmddhhmm()
var filename = this.config.session.inputFilename + appendFilename + ".csv"

var wb = XLSX.utils.book_new();

wb.SheetNames.push("data")

let ws = this.utils.Sheet.aoa_to_sheet(this.cacheOutputArray)
//console.log(ws)
wb.Sheets["data"] = ws

//var wbout = XLSX.write(wb, {bookType: 'ods', bookSST: true, type: 'base64'});
//let filename = 'jieba-js-config_' + (new Date()).mmddhhmm() + '.ods'
//saveAs(new Blob([this.s2ab(wbout)], {type: "application/octet-stream"}), filename);

XLSX.writeFile(wb, filename);

this.config.state.processOutputWait = false
},

initOutputTrans: async function () {
if (this.cacheTrans.length === 0) {
await this.startTrans()
}
},

startTrans: async function () {
startTrans: async function (showWarning = true) {
if (showWarning && window.confirm(`Process model requires a long time. Will you continue?`) === false) {
return false
}

if (this.config.state.outputTextRows.length === 0) {
await this.$parent.$parent.$refs.TextProcessComponent.processOutput()
}

this.config.state.processOutputWait = true

if (this.cacheTrans.length > 0) {
Expand All @@ -109,7 +138,7 @@ let TextOutputTransPanel = {
let text = this.getLineText(row)
let textTrans
if (this.config.development.debug.skipTrans === false) {
textTrans = await this.utils.Trans.trans(text, 'en')
textTrans = await this.utils.Trans.trans(text, 'en')
}
else {
textTrans = 'This is a pen.'
Expand Down
23 changes: 22 additions & 1 deletion src/utils/TransUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ let url = 'https://pulipulichen.github.io/HTML-API-Transtration/index.html'
if (location.href.startsWith('http://localhost:8383/')) {
url = 'http://localhost:8383/HTML-API-Transtration/index.html'
}
if (location.href.startsWith('http://127.0.0.1:5500/')) {
else if (location.href.startsWith('http://127.0.0.1:5500/')) {
// url = 'http://localhost:8000/index.html'
url = 'http://127.0.0.1:5502/index.html'
}
else if (location.href.startsWith('http://127.0.0.1:5502/')) {
// url = 'http://localhost:8000/index.html'
url = 'http://127.0.0.1:5500/index.html'
}

// if (location.href.startsWith('https://dangerous-lizard-99.telebit.io/')) {
// // url = 'http://localhost:8000/index.html'
// url = 'http://127.0.0.1:5500/index.html'
// }

export default {
cache: {},
Expand All @@ -21,6 +30,8 @@ export default {

return lang + ':' + text
},
nonEnglishPattern: /[\u00C0-\u02AF\u0370-\u03FF\u0400-\u04FF\u0500-\u052F\u0591-\u05F4\u0600-\u06FF\u0700-\u074F\u0750-\u077F\u0780-\u07BF\u0900-\u097F\u0980-\u09FF\u0A00-\u0A7F\u0A80-\u0AFF\u0B00-\u0B7F\u0B80-\u0BFF\u0C00-\u0C7F\u0C80-\u0CFF\u0D00-\u0D7F\u0E00-\u0E7F\u0E80-\u0EFF\u0F00-\u0FFF\u1000-\u109F\u10A0-\u10FF\u1100-\u11FF\u1200-\u137F\u13A0-\u13FF\u1400-\u167F\u1680-\u169F\u16A0-\u16FF\u1700-\u171F\u1720-\u173F\u1740-\u175F\u1760-\u177F\u1780-\u17FF\u1800-\u18AF\u1E00-\u1EFF\u1F00-\u1FFF\u2000-\u206F\u2070-\u209F\u20A0-\u20CF\u20D0-\u20FF\u2100-\u214F\u2150-\u218F\u2190-\u21FF\u2200-\u22FF\u2300-\u23FF\u2400-\u243F\u2440-\u245F\u2460-\u24FF\u2500-\u257F\u2580-\u259F\u25A0-\u25FF\u2600-\u26FF\u2700-\u27BF\u2800-\u28FF\u2E80-\u2EFF\u2F00-\u2FDF\u2FF0-\u2FFF\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\u3100-\u312F\u3130-\u318F\u3190-\u319F\u31A0-\u31BF\u31C0-\u31EF\u31F0-\u31FF\u3200-\u32FF\u3300-\u33FF\u3400-\u4DBF\u4DC0-\u4DFF\u4E00-\u9FFF\uA000-\uA48F\uA490-\uA4CF\uA4D0-\uA4FF\uA500-\uA63F\uA640-\uA69F\uA6A0-\uA6FF\uA700-\uA71F\uA720-\uA7FF\uA800-\uA82F\uA830-\uA83F\uA840-\uA87F\uA880-\uA8DF\uA8E0-\uA8FF\uA900-\uA92F\uA930-\uA95F\uA960-\uA97F\uA980-\uA9DF\uA9E0-\uA9FF\uAA00-\uAA5F\uAA60-\uAA7F\uAA80-\uAADF\uAAE0-\uAAFF\uAB00-\uAB2F\uAB30-\uAB6F\uAB70-\uABBF\uABC0-\uABFF\uAC00-\uD7AF\uD7B0-\uD7FF\uF900-\uFAFF\uFB00-\uFB4F\uFB50-\uFDFF\uFE00-\uFE0F\uFE10-\uFE1F\uFE20-\uFE2F\uFE30-\uFE4F\uFE50-\uFE6F\uFE70-\uFEFF\uFF00-\uFFEF\uFF80-\uFFEF]/,

/**
*
* @param {type} text
Expand All @@ -31,6 +42,16 @@ export default {
if (!text) {
return false
}

if (lang === 'en') {
let tempText = text
if (Array.isArray(tempText)) {
tempText = tempText.join(' ')
}
if (this.nonEnglishPattern.test(tempText) === false) {
return text
}
}

if (Array.isArray(text) && (typeof(text[0]) !== 'string' || text[0].trim() === '')) {
return false
Expand Down
3 changes: 1 addition & 2 deletions src/utils/puli-post-message-api/puli-post-message-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,7 @@ function PuliPostMessageAPI(options) {

let _messageHandler = function (event) {
//console.log(event, location.href.slice(location.href.lastIndexOf('/') + 1))
if (typeof(event.data) !== 'object'
|| !event.data.eventName) {
if (typeof(event.data) !== 'object' || !event.data.eventName) {
return false
}
let eventName = event.data.eventName
Expand Down

0 comments on commit c6d1aff

Please sign in to comment.