0

I have installed the OJS 3.4 on a server, but when I tried to install my plugin, I got this error:

PHP Fatal error:  Uncaught Error: Class "AppLocale" not found in /app/plugins/generic/My_plugin/MyPlugin.inc.php:105

this is the line 105 in my MyPlugin.inc.php:

AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON,  LOCALE_COMPONENT_PKP_MANAGER);

the plugin works fine with OJS 3.X versions This error suggests that the code in the My_plugin is trying to use a class named “AppLocale,” but it cannot find this class because it's deprecated in OJS 3.4

@deprecated The class \APP\i18n\AppLocale has been replaced by PKP\facades\Locale

how should I modify the plugin code to make it works fine with OJS 3.3 and 3.4 versions?

I have tried to use in /app/plugins/generic/My_plugin/MyPlugin.inc.php:

use PKP\facades\Locale;
use PKP\i18n\PKPLocale;

Locale::requireComponents(PKPLocale::LOCALE_COMPONENT_APP_COMMON, PKPLocale::LOCALE_COMPONENT_APP_MANAGER);

but I got this error:

NOTICE: PHP message: PHP Fatal error:  Uncaught Error: Undefined constant PKP\i18n\PKPLocale::LOCALE_COMPONENT_APP_COMMON in /app/plugins/generic/My_plugin/MyPlugin.inc.php:114

Here is the code in OJS 3.4:

The class \APP\i18n\AppLocale:

namespace APP\i18n;

use PKP\i18n\PKPLocale;

if (!PKP_STRICT_MODE) {
    /**
     * @deprecated The class \APP\i18n\AppLocale has been replaced by PKP\facades\Locale
     */
    class AppLocale extends PKPLocale
    {
    }

    class_alias('\APP\i18n\AppLocale', '\AppLocale');
}

PKP\facades\Locale:

namespace PKP\facades;

use Illuminate\Support\Facades\Facade;
use PKP\i18n\interfaces\LocaleInterface;

class Locale extends Facade
{
    /**
     * Connects the facade to a container component
     */
    protected static function getFacadeAccessor(): string
    {
        return LocaleInterface::class;
    }
}

PKP\i18n\PKPLocale:

namespace PKP\i18n;

use PKP\facades\Locale;

if (!PKP_STRICT_MODE) {
    /**
     * @deprecated The class \PKP\i18n\PKPLocale has been replaced by PKP\facades\Locale
     */
    class PKPLocale
    {
        /**
         * Return the key name of the user's currently selected locale (default
         * is "en" English).
         *
         * @return string
         *
         * @deprecated 3.4.0.0 The same method is available at \PKP\facades\Locale::getLocale()
         */
        public static function getLocale()
        {
            return Locale::getLocale();
        }

        /**
         * Retrieve the primary locale of the current context.
         *
         * @return string
         *
         * @deprecated 3.4.0.0 The same method is available at \PKP\facades\Locale::getPrimaryLocale(), but before using this method, try to retrieve the locale directly from a nearby context
         */
        public static function getPrimaryLocale()
        {
            return Locale::getPrimaryLocale();
        }

        /**
         * Load a set of locale components. Parameters of mixed length may
         * be supplied, each a LOCALE_COMPONENT_... constant. An optional final
         * parameter may be supplied to specify the locale (e.g. 'en').
         *
         * @deprecated 3.4.0.0 All the available locale keys are already loaded
         */
        public static function requireComponents()
        {
        }

        /**
         * Return a list of all available locales.
         *
         * @deprecated 3.4.0.0 Use the \PKP\facades\Locale::getLocales()
         *
         * @return array
         */
        public static function &getAllLocales()
        {
            $locales = array_map(fn (LocaleMetadata $locale) => $locale->getDisplayName(), Locale::getLocales());
            return $locales;
        }
    }

    class_alias('\PKP\i18n\PKPLocale', '\PKPLocale');

    // Shared locale components
    define('LOCALE_COMPONENT_PKP_COMMON', 0x00000001);
    define('LOCALE_COMPONENT_PKP_ADMIN', 0x00000002);
    define('LOCALE_COMPONENT_PKP_INSTALLER', 0x00000003);
    define('LOCALE_COMPONENT_PKP_MANAGER', 0x00000004);
    define('LOCALE_COMPONENT_PKP_READER', 0x00000005);
    define('LOCALE_COMPONENT_PKP_SUBMISSION', 0x00000006);
    define('LOCALE_COMPONENT_PKP_USER', 0x00000007);
    define('LOCALE_COMPONENT_PKP_GRID', 0x00000008);
    define('LOCALE_COMPONENT_PKP_DEFAULT', 0x00000009);
    define('LOCALE_COMPONENT_PKP_EDITOR', 0x0000000A);
    define('LOCALE_COMPONENT_PKP_REVIEWER', 0x0000000B);
    define('LOCALE_COMPONENT_PKP_API', 0x0000000C);

    // Application-specific locale components
    define('LOCALE_COMPONENT_APP_COMMON', 0x00000100);
    define('LOCALE_COMPONENT_APP_MANAGER', 0x00000101);
    define('LOCALE_COMPONENT_APP_SUBMISSION', 0x00000102);
    define('LOCALE_COMPONENT_APP_AUTHOR', 0x00000103);
    define('LOCALE_COMPONENT_APP_EDITOR', 0x00000104);
    define('LOCALE_COMPONENT_APP_ADMIN', 0x00000105);
    define('LOCALE_COMPONENT_APP_DEFAULT', 0x00000106);
    define('LOCALE_COMPONENT_APP_API', 0x00000107);
    define('LOCALE_COMPONENT_APP_EMAIL', 0x00000108);
}

0 Answers0