Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Mecab required when not set #155

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ function media_files($get_req)
/**
* Get the phonetic reading of a word based on it's language.
*
* @param array $get_req Array with the fields "text" and "lang" (short language name)
* @param array $get_req Array with the fields "text" and "lang_id" (language_id)
*
* @return string[] JSON-encoded result
*
* @psalm-return array{phonetic_reading: string}
*/
function get_phonetic_reading($get_req): array
{
$data = phonetic_reading($get_req['text'], $get_req['lang']);
$data = phonetic_reading($get_req['text'], $get_req['lang_id']);
return array("phonetic_reading" => $data);
}

Expand Down
2 changes: 1 addition & 1 deletion do_test_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ function do_test_test_javascript_clickable($wo_record, $solution)
global $tbpref;
$wid = $wo_record['WoID'];
$abbr = getLanguageCode($wo_record['WoLgID'], LWT_LANGUAGES_ARRAY);
$phoneticText = phonetic_reading($wo_record['WoText'], $abbr);
$phoneticText = phonetic_reading($wo_record['WoText'], $wo_record['WoLgID']);
$voiceApi = get_first_value(
"SELECT LgTTSVoiceAPI AS value FROM {$tbpref}languages
WHERE LgID = " . $wo_record['WoLgID']
Expand Down
2 changes: 1 addition & 1 deletion do_text_header.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function browser_tts($text, $languageName): void
);
$languageCode = getLanguageCode($lg_id, LWT_LANGUAGES_ARRAY);
// Phonetic reading for this text
$phoneticText = phonetic_reading($text, $languageCode);
$phoneticText = phonetic_reading($text, $lg_id);
$voiceApi = get_first_value(
"SELECT LgTTSVoiceAPI AS value FROM {$tbpref}languages
WHERE LgID = $lg_id"
Expand Down
4 changes: 2 additions & 2 deletions inc/ajax_get_phonetic.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* \file
* \brief Make the phonetic translation of a word.
*
* Call: inc/ajax_get_phonetic.php?text=[text_string]&lang=[language_string]
* Call: inc/ajax_get_phonetic.php?text=[text_string]&lang_id=[language_id]
*
* @package Lwt
* @author HugoFara <[email protected]>
Expand All @@ -16,7 +16,7 @@
require_once 'session_utility.php';

if (isset($_GET['text']) && isset($_GET['lang'])) {
echo phonetic_reading(getreq('text'), getreq('lang'));
echo phonetic_reading(getreq('text'), getreq('lang_id'));
}

?>
10 changes: 7 additions & 3 deletions inc/session_utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -4830,16 +4830,20 @@ function trim_value(&$value): void
* is supported, using MeCab.
*
* @param string $text Text to be converted
* @param string $lang Language code (usually BCP 47 or ISO 639-1)
* @param string $lang_id the language id
* @return string Parsed text in a phonetic format.
*
* @since 2.9.0 Any language starting by "ja" or "jp" is considered phonetic.
*/
function phonetic_reading($text, $lang)
function phonetic_reading($text, $lang_id)
{
global $tbpref;
// Many languages are already phonetic
if (!str_starts_with($lang, "ja") && !str_starts_with($lang, "jp")) {
$languageCode = getLanguageCode($lang_id, LWT_LANGUAGES_ARRAY);

$mecab = get_first_value('select LgRegexpWordCharacters as value from ' . $tbpref . 'languages where LgID = ' . $lang_id);

if (!str_starts_with($languageCode, "ja") && !str_starts_with($languageCode, "jp") && $mecab != "mecab") {
return $text;
}

Expand Down