Skip to content

Commit

Permalink
#163: removes last instances of $langDefs.
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoFara committed Dec 26, 2023
1 parent 1450f2d commit 750f4ca
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
23 changes: 8 additions & 15 deletions edit_languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,15 @@ function load_language($lgid)
*/
function edit_language_form($language): void
{
global $langDefs;
$sourceLg = '';
$targetLg = '';
$currentnativelanguage = getSetting('currentnativelanguage');
if (array_key_exists($currentnativelanguage, $langDefs)) {
$targetLg = $langDefs[$currentnativelanguage][1];
if (array_key_exists($currentnativelanguage, LWT_LANGUAGES_ARRAY)) {
$targetLg = LWT_LANGUAGES_ARRAY[$currentnativelanguage][1];
}
if ($language->name) {
if (array_key_exists($language->name, $langDefs)) {
$sourceLg = $langDefs[$language->name][1];
if (array_key_exists($language->name, LWT_LANGUAGES_ARRAY)) {
$sourceLg = LWT_LANGUAGES_ARRAY[$language->name][1];
}
$lgFromDict = langFromDict($language->translator);
if ($lgFromDict != '' && $lgFromDict != $sourceLg) {
Expand Down Expand Up @@ -879,15 +878,12 @@ function checkLanguageForm(l_form) {
* Returns a dropdown menu of the different languages.
*
* @param string $currentnativelanguage Default language
*
* @global mixed $langDefs
*/
function get_wizard_selectoptions($currentnativelanguage): string
{
global $langDefs;
$r = "<option value=\"\"" . get_selected($currentnativelanguage, "") .
">[Choose...]</option>";
$keys = array_keys($langDefs);
$keys = array_keys(LWT_LANGUAGES_ARRAY);
foreach ($keys as $item) {
$r .= "<option value=\"" . $item . "\"" .
get_selected($currentnativelanguage, $item) . ">" . $item . "</option>";
Expand All @@ -902,8 +898,6 @@ function get_wizard_selectoptions($currentnativelanguage): string
*/
function edit_languages_new()
{
global $langDefs;

$currentnativelanguage = getSetting('currentnativelanguage');
?>
<h2>
Expand All @@ -915,7 +909,7 @@ function edit_languages_new()

<script type="text/javascript" charset="utf-8">

const LANGDEFS = <?php echo json_encode($langDefs); ?>;
const LANGDEFS = <?php echo json_encode(LWT_LANGUAGES_ARRAY); ?>;

/**
* Main variable for the language selection wizard.
Expand Down Expand Up @@ -1053,17 +1047,16 @@ function edit_languages_new()
* @return void
*
* @global string $tbpref
* @global array $langDefs
*/
function edit_languages_change($lid)
{
global $tbpref, $langDefs;
global $tbpref;
$sql = "SELECT * FROM {$tbpref}languages WHERE LgID = $lid";
$res = do_mysqli_query($sql);
if (mysqli_fetch_assoc($res)) {
?>
<script type="text/javascript" charset="utf-8">
const LANGDEFS = <?php echo json_encode($langDefs); ?>;
const LANGDEFS = <?php echo json_encode(LWT_LANGUAGES_ARRAY); ?>;

$(document).ready(ask_before_exiting);
</script>
Expand Down
8 changes: 4 additions & 4 deletions edit_word.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ function edit_word_do_operation($translation, $fromAnn)
}


/*
/**
* @return void
*/
function edit_word_do_form($wid, $text_id, $ord, $fromAnn)
{
global $tbpref, $langDefs;
global $tbpref;
$lang = null;
$term = null;

Expand Down Expand Up @@ -312,8 +312,8 @@ function edit_word_do_form($wid, $text_id, $ord, $fromAnn)
"SELECT LgName AS value FROM {$tbpref}languages
WHERE LgID = $lang"
);
$lang_short = array_key_exists($lgname, $langDefs) ?
$langDefs[$lgname][1] : ''
$lang_short = array_key_exists($lgname, LWT_LANGUAGES_ARRAY) ?
LWT_LANGUAGES_ARRAY[$lgname][1] : ''

?>

Expand Down
9 changes: 5 additions & 4 deletions select_lang_pair.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
require_once 'inc/session_utility.php';
require_once 'inc/langdefs.php';

/// Returns a dropdown menu of the different languages
/**
* Returns a dropdown menu of the different languages
*/
function get_wizard_selectoptions($v): string
{
global $langDefs;
$r = "<option value=\"\"" . get_selected($v, "") . ">[Choose...]</option>";
$keys = array_keys($langDefs);
$keys = array_keys(LWT_LANGUAGES_ARRAY);
foreach ($keys as $item) {
$r .= "<option value=\"" . $item . "\"" . get_selected($v, $item) . ">" . $item . "</option>";
}
Expand All @@ -38,7 +39,7 @@ function get_wizard_selectoptions($v): string
<script type="text/javascript">
//<![CDATA[

const LANGDEFS = <?php echo json_encode($langDefs); ?>;
const LANGDEFS = <?php echo json_encode(LWT_LANGUAGES_ARRAY); ?>;

/// Execute the wizard
function wizard_go() {
Expand Down
23 changes: 13 additions & 10 deletions text_to_speech_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@
* @param string $language Language name, for instance "English"
*
* @return string Two-letter language name
*
* @ðeprecated Since 2.9.1-fork, use getLanguageCode
*/
function get_language_code($language)
{
global $langDefs;
return $langDefs[$language][1];
global $tbpref;
$lg_id = (int) get_first_value(
"SELECT LgID as value
FROM {$tbpref}languages
WHERE LgName = " . convert_string_to_sqlsyntax($language)
);
return getLanguageCode($lg_id, LWT_LANGUAGES_ARRAY);
}

/**
Expand All @@ -43,10 +50,9 @@ function get_language_code($language)
*/
function language_id_from_code($code)
{
global $langDefs;
$trimmed = substr($code, 0, 2);
foreach (get_languages() as $language => $language_id) {
$elem = $langDefs[$language];
$elem = LWT_LANGUAGES_ARRAY[$language];
if ($elem[0] == $trimmed) {
return $language_id;
}
Expand All @@ -57,15 +63,13 @@ function language_id_from_code($code)
/**
* String to population a SELECT tag.
*
* @return string HTML-formatted string
*
* @global array $langDefs List of all languages.
* @return string HTML-formatted string.
*/
function tts_language_options()
{
$output = '';
foreach (get_languages() as $language => $language_id) {
$languageCode = get_language_code($language);
$languageCode = getLanguageCode($language_id, LWT_LANGUAGES_ARRAY);
$output .= '<option value="' . $languageCode . '">' .
$language .
'</option>';
Expand Down Expand Up @@ -177,12 +181,11 @@ function tts_demo()
function tts_js()
{
$lid = (int) getSetting('currentlanguage');
$current_language = getLanguage((string) $lid);
?>
<script type="text/javascript" charset="utf-8">
/** @var Current language being learnt. */
const CURRENT_LANGUAGE = <?php
echo json_encode(get_language_code($current_language));
echo json_encode(getLanguageCode($lid, LWT_LANGUAGES_ARRAY));
?>;

/**
Expand Down

0 comments on commit 750f4ca

Please sign in to comment.