From 261e7a8084a75e6d38088c06f43331d4cd421f55 Mon Sep 17 00:00:00 2001 From: HugoFara Date: Fri, 5 Jan 2024 16:06:20 +0100 Subject: [PATCH] Fixes issue signaled in #182: mecab was still required. Fixes many small parts of the code not collaborating with each other. --- api.php | 2 +- docs/CHANGELOG.md | 6 +++--- docs/info.html | 6 +++--- inc/session_utility.php | 2 +- js/pgm.js | 4 ++-- src/js/user_interactions.js | 18 +++++++++--------- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/api.php b/api.php index adcc377d..088e9c58 100644 --- a/api.php +++ b/api.php @@ -200,7 +200,7 @@ function readingConfiguration($get_req): array */ function get_phonetic_reading($get_req): array { - if (array_key_exists("lgid", $get_req)) { + if (array_key_exists("lang_id", $get_req)) { $data = phoneticReading($get_req['text'], $get_req['lang_id']); } else { $data = phonetic_reading($get_req['text'], $get_req['lang']); diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d3d7cf6e..fe063772 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -61,7 +61,7 @@ after solution display ([#159](https://github.com/HugoFara/lwt/issues/159)). * Database: * Database creation and migration is now handled directly in SQL, for a safer behavior. - * You do no longer need to give to LWT SYSTEM_VARIABLES_ADMIN for text reparsing. (new function `checkTextWithExpressions`) ([#167](https://github.com/HugoFara/lwt/issues/167)). It is still necessary for words import. + * You do no longer need to give to LWT SYSTEM_VARIABLES_ADMIN for text reparsing. (new function `checkExpressions`) ([#167](https://github.com/HugoFara/lwt/issues/167)). It is still necessary for words import. * Docker changes: * By default, the images now runs at localhot/lwt and no longer in the root folder ([installer #4](https://github.com/HugoFara/lwt-docker-installer/pull/4) @@ -77,8 +77,6 @@ behavior. Solves [#129](https://github.com/HugoFara/lwt/issues/129), thanks to the help of PR [#168](https://github.com/HugoFara/lwt/pull/168). * Text reading position was not working consistently when adding several known words. -* Japanese was always requiring MeCab for TTS, even if it was not used -([#155](https://github.com/HugoFara/lwt/pull/155)). * Multi-words: * Tooltip was not properly saved ([#170](https://github.com/HugoFara/lwt/pull/170)). * Translation may be escaped two times ([#170](https://github.com/HugoFara/lwt/pull/170)). @@ -92,6 +90,8 @@ Solves [#129](https://github.com/HugoFara/lwt/issues/129), thanks to the help of * Parsing Japanese texts with MeCab was creating warnings when the text was not finishing by a punctation mark. * Multi-words were not saved with MeCab parsing on Japanese. + * Japanese was always requiring MeCab for TTS, even if it was not used + ([#155](https://github.com/HugoFara/lwt/pull/155)) and [#182](https://github.com/HugoFara/lwt/pull/182). * On word review (test): * the space keyboard shortcut may have been inoperating. * On `api.php`, tests were always set to "multi-word" due to a missing variable diff --git a/docs/info.html b/docs/info.html index e5bd0ad8..addffc46 100644 --- a/docs/info.html +++ b/docs/info.html @@ -2303,7 +2303,7 @@

Changed

  • Docker changes: @@ -2324,8 +2324,6 @@

    Fixed

    Solves #129, thanks to the help of PR #168.
  • Text reading position was not working consistently when adding several known words.
  • -
  • Japanese was always requiring MeCab for TTS, even if it was not used -(#155).
  • Multi-words:
  • On word review (test): diff --git a/inc/session_utility.php b/inc/session_utility.php index 464e9347..662b9fa2 100644 --- a/inc/session_utility.php +++ b/inc/session_utility.php @@ -3644,7 +3644,7 @@ function phoneticReading($text, $lgid) { global $tbpref; $sentence_split = get_first_value( - "SELECT LgRegexpSplitSentences AS value FROM {$tbpref}languages + "SELECT LgRegexpWordCharacters AS value FROM {$tbpref}languages WHERE LgID = $lgid" ); diff --git a/js/pgm.js b/js/pgm.js index 14996dde..7061a817 100644 --- a/js/pgm.js +++ b/js/pgm.js @@ -466,7 +466,7 @@ $(document).scrollTo(pos);focus();setTimeout(overlib,10);setTimeout(cClick,100)} function saveReadingPosition(text_id,position){$.post('api.php/v1/texts/'+text_id+'/reading-position',{position:position})} function saveAudioPosition(text_id,pos){$.post('api.php/v1/texts/'+text_id+'/audio-position',{position:pos})} function getPhoneticText(text,lang){let phoneticText;$.ajax('api.php/v1/phonetic-reading',{async:!1,data:{text:text,lang:lang},dataType:'json',type:'GET'}).done(function(data){phoneticText=data.phonetic_reading});return phoneticText} -async function getPhoneticTextAsync(text,lang){const parameters={text:text};if(typeof lang=='int'){parameters.lgid=lang}else{parameters.lang=lang} +async function getPhoneticTextAsync(text,lang){const parameters={text:text};if(typeof lang=='number'){parameters.lang_id=lang}else{parameters.lang=lang} return $.getJSON('api.php/v1/phonetic-reading',parameters)} function deepReplace(obj,searchValue,replaceValue){for(let key in obj){if(typeof obj[key]==='object'){deepReplace(obj[key],searchValue,replaceValue)}else if(typeof obj[key]==='string'&&obj[key].includes(searchValue)){obj[key]=obj[key].replace(searchValue,replaceValue)}}} function deepFindValue(obj,searchValue){for(const key in obj){if(obj.hasOwnProperty(key)){if(typeof obj[key]==='string'&&obj[key].startsWith(searchValue)){return obj[key]}else if(typeof obj[key]==='object'){const result=deepFindValue(obj[key],searchValue);if(result){return result}}}} @@ -485,4 +485,4 @@ if(rate){msg.rate=rate}else if(tts_settings.rate){msg.rate=tts_settings.rate} if(pitch){msg.pitch=pitch}else if(tts_settings.pitch){msg.pitch=tts_settings.pitch} window.speechSynthesis.speak(msg);return msg} function readTextAloud(text,lang,rate,pitch,voice,convert_to_phonetic){if(convert_to_phonetic){getPhoneticTextAsync(text,lang).then(function(data){readRawTextAloud(data.phonetic_reading,lang,rate,pitch,voice)})}else{readRawTextAloud(text,lang,rate,pitch,voice)}} -function speechDispatcher(term,lang_id){return $.getJSON('api.php/v1/languages/'+lang_id+'/reading-configuration',{lgid:lang_id},function(data){if(data.readingMode=="direct"||data.readingMode=="internal"){const lang_settings=cookieTTSSettings(data.language);if(data.readingMode=="direct"){readRawTextAloud(term,data.abbreviation,lang_settings.rate,lang_settings.pitch,lang_settings.voice)}else if(data.readingMode=="internal"){getPhoneticTextAsync(text,lang_id).then(function(reparsed_text){readRawTextAloud(reparsed_text.phonetic_reading,data.abbreviation,lang_settings.rate,lang_settings.pitch,lang_settings.voice)})}}else if(data.readingMode=="external"){readTextWithExternal(term,data.voiceApi,data.language)}})} \ No newline at end of file +function speechDispatcher(term,lang_id){return $.getJSON('api.php/v1/languages/'+lang_id+'/reading-configuration',{lgid:lang_id},function(data){if(data.reading_mode=="direct"||data.reading_mode=="internal"){const lang_settings=cookieTTSSettings(data.language);if(data.reading_mode=="direct"){readRawTextAloud(term,data.abbreviation,lang_settings.rate,lang_settings.pitch,lang_settings.voice)}else if(data.reading_mode=="internal"){getPhoneticTextAsync(term,parseInt(lang_id,10)).then(function(reparsed_text){readRawTextAloud(reparsed_text.phonetic_reading,data.abbreviation,lang_settings.rate,lang_settings.pitch,lang_settings.voice)})}}else if(data.reading_mode=="external"){readTextWithExternal(term,data.voiceApi,data.language)}})} \ No newline at end of file diff --git a/src/js/user_interactions.js b/src/js/user_interactions.js index 3bb4607e..5513af38 100644 --- a/src/js/user_interactions.js +++ b/src/js/user_interactions.js @@ -171,15 +171,15 @@ function getPhoneticText (text, lang) { /** * Get the phonetic version of a text, asynchronous. * - * @param {string} text Text to convert to phonetics. - * @param {string|int} lang Language, either two letters code or four letters (BCP 47), or language ID + * @param {string} text Text to convert to phonetics. + * @param {string|number} lang Language, either two letters code or four letters (BCP 47), or language ID */ async function getPhoneticTextAsync (text, lang) { const parameters = { text: text }; - if (typeof lang == 'int') { - parameters.lgid = lang; + if (typeof lang == 'number') { + parameters.lang_id = lang; } else { parameters.lang = lang; } @@ -348,9 +348,9 @@ function speechDispatcher (term, lang_id) { lgid: lang_id }, function (data) { - if (data.readingMode == "direct" || data.readingMode == "internal") { + if (data.reading_mode == "direct" || data.reading_mode == "internal") { const lang_settings = cookieTTSSettings(data.language); - if (data.readingMode == "direct") { + if (data.reading_mode == "direct") { // No reparsing needed readRawTextAloud( term, @@ -359,9 +359,9 @@ function speechDispatcher (term, lang_id) { lang_settings.pitch, lang_settings.voice ); - } else if (data.readingMode == "internal") { + } else if (data.reading_mode == "internal") { // Server handled reparsing - getPhoneticTextAsync(text, lang_id) + getPhoneticTextAsync(term, parseInt(lang_id, 10)) .then( function (reparsed_text) { readRawTextAloud( @@ -374,7 +374,7 @@ function speechDispatcher (term, lang_id) { } ); } - } else if (data.readingMode == "external") { + } else if (data.reading_mode == "external") { // Use external API readTextWithExternal(term, data.voiceApi, data.language); }