Skip to content

Commit

Permalink
Add a text function for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Jun 28, 2023
1 parent 411beee commit 7a03dab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
18 changes: 18 additions & 0 deletions libraries/src/Plugin/CMSPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,22 @@ public function setApplication(CMSApplicationInterface $application): void
$this->setLanguage($application->getLanguage());
}
}

/**
* Returns the string for the given key from the internal language object.
*
* @param string $key The key
*
* @return string
*
* @since __DEPLOY_VERSION__
*/
protected function text(string $key): string
{
try {
return $this->getLanguage()->_($key);
} catch (\UnexpectedValueException $e) {
return $this->getApplication()->getLanguage()->_($key);
}
}
}
14 changes: 7 additions & 7 deletions plugins/installer/packageinstaller/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
$maxSizeBytes = FilesystemHelper::fileUploadMaxSize(false);
$maxSize = HTMLHelper::_('number.bytes', $maxSizeBytes);
?>
<legend><?php echo Text::_('PLG_INSTALLER_PACKAGEINSTALLER_UPLOAD_INSTALL_JOOMLA_EXTENSION'); ?></legend>
<legend><?php echo $this->text('PLG_INSTALLER_PACKAGEINSTALLER_UPLOAD_INSTALL_JOOMLA_EXTENSION'); ?></legend>

<div id="uploader-wrapper">
<div id="dragarea" data-state="pending">
Expand All @@ -57,7 +57,7 @@
</div>
<p class="lead">
<span class="uploading-text">
<?php echo Text::_('PLG_INSTALLER_PACKAGEINSTALLER_UPLOADING'); ?>
<?php echo $this->text('PLG_INSTALLER_PACKAGEINSTALLER_UPLOADING'); ?>
</span>
<span class="uploading-number">0</span><span class="uploading-symbol">%</span>
</p>
Expand All @@ -68,18 +68,18 @@
</div>
<p class="lead">
<span class="installing-text">
<?php echo Text::_('PLG_INSTALLER_PACKAGEINSTALLER_INSTALLING'); ?>
<?php echo $this->text('PLG_INSTALLER_PACKAGEINSTALLER_INSTALLING'); ?>
</span>
</p>
</div>
<div class="upload-actions">
<p class="lead">
<?php echo Text::_('PLG_INSTALLER_PACKAGEINSTALLER_DRAG_FILE_HERE'); ?>
<?php echo $this->text('PLG_INSTALLER_PACKAGEINSTALLER_DRAG_FILE_HERE'); ?>
</p>
<p>
<button id="select-file-button" type="button" class="btn btn-success">
<span class="icon-copy" aria-hidden="true"></span>
<?php echo Text::_('PLG_INSTALLER_PACKAGEINSTALLER_SELECT_FILE'); ?>
<?php echo $this->text('PLG_INSTALLER_PACKAGEINSTALLER_SELECT_FILE'); ?>
</button>
</p>
<p>
Expand All @@ -92,7 +92,7 @@

<div id="legacy-uploader" class="hidden">
<div class="control-group">
<label for="install_package" class="control-label"><?php echo Text::_('PLG_INSTALLER_PACKAGEINSTALLER_EXTENSION_PACKAGE_FILE'); ?></label>
<label for="install_package" class="control-label"><?php echo $this->text('PLG_INSTALLER_PACKAGEINSTALLER_EXTENSION_PACKAGE_FILE'); ?></label>
<div class="controls">
<input class="form-control-file" id="install_package" name="install_package" type="file">
<input id="max_upload_size" name="max_upload_size" type="hidden" value="<?php echo $maxSizeBytes; ?>" />
Expand All @@ -101,7 +101,7 @@
</div>
<div class="form-actions">
<button class="btn btn-primary" type="button" id="installbutton_package">
<?php echo Text::_('PLG_INSTALLER_PACKAGEINSTALLER_UPLOAD_AND_INSTALL'); ?>
<?php echo $this->text('PLG_INSTALLER_PACKAGEINSTALLER_UPLOAD_AND_INSTALL'); ?>
</button>
</div>

Expand Down

0 comments on commit 7a03dab

Please sign in to comment.