Hello. Is there any way to install lingua plugin to modx 3? I tryed to install it via package manager but keep getting SQL syntax errors. Is there any alternative to this plugin? Or any way to install it on modx 3? I tryed to use a babel but it requeres a lot of setup. Or is there any documentation on how to translate a website without to have to create contexts for each language?
The Lingua extra hasn’t been updated in years and looking at the github repo, it seems that there isn’t much activity either.
The way Lingua integrates into the manager, I suspect it would take some effort to make it compatible with MODX3. Maybe someone makes it happen (but I wouldn’t count on it anytime soon).
Personally, I would use Babel as it already seems to be compatible with MODX3.
There is a Lingua Version for modx 3: https://github.com/Sterc/Lingua/tree/3.x/_packages
Unfortunately, it is not working for me - perhaps somebody can help:
- ModX does not show me a selector for selecting which language to choose
- The Lingua Selector snippet goes to return on line 42
if (!($lingua instanceof \Lingua)) { return; }
Log is showing:
[2023-08-16 12:24:04] (ERROR @ /www/xxx/core/vendor/xpdo/xpdo/src/xPDO/xPDO.php : 667) Could not load class: Lingua from lingua
[2023-08-16 12:24:04] (ERROR @ /www/xxx/core/vendor/xpdo/xpdo/src/xPDO/xPDO.php : 1273) Problem getting service lingua, instance of class Lingua, from path
[2023-08-16 12:24:04] (ERROR @ /www/xxx/core/cache/includes/elements/modx/revolution/modsnippet/86.include.cache.php : 42) [lingua.getValue]: !($lingua instanceof Lingua)
Does it work if you replace the line with
if (!($lingua instanceof \Lingua\Lingua)) { return; }
Nothing changed
I guess the problem is actually that somehow the class is not even loaded …
I guess this line in the snippet code
should be like this (with an uppercase letter L
)
$lingua = $modx->getService('Lingua');
or better code like this (as the function getService()
is deprecated)
$lingua = null;
try {
if ($modx->services->has('Lingua')) {
$lingua = $modx->services->get('Lingua');
}
} catch (\Psr\Container\ContainerExceptionInterface $e) {
return;
}
The service gets added in the file bootstrap.php
Changed the getSerice part in all snippets and the plugin. As well as all the “instanceof \Lingua\Lingua”. Now this works - thanks a lot.
Unfortunately this brings the next issue: $allowedContexts returns empty
And the error messages of the log are also still showing - could this be an issue of Migx 3.0.0 alpha5? MODX 3.0.3 and MIGX error
[2023-08-16 12:24:04] (ERROR @ /www/xxx/core/vendor/xpdo/xpdo/src/xPDO/xPDO.php : 667) Could not load class: Lingua from lingua
[2023-08-16 12:24:04] (ERROR @ /www/xxx/core/vendor/xpdo/xpdo/src/xPDO/xPDO.php : 1273) Problem getting service lingua, instance of class Lingua, from path
Is this a fresh installation of the Lingua package?
I’ve noticed that all the system settings are wrong.
There names are lingua_lingua.contexts
, lingua_lingua.debug
, etc. but should be lingua.contexts
, lingua.debug
etc.
Also, the snippet “lingua.getValue” has the same error as the snippet “lingua.selector”.
I don’t think the MODX 3 rewrite of the Lingua extra is currently ready for production.
I don’t think the MODX 3 rewrite of the Lingua extra is currently ready for production.
Unfortunately, I have to agree with you …
Is this a fresh installation of the Lingua package?
I uninstalled completly and reinstalled
Also, the snippet “lingua.getValue” has the same error as the snippet “lingua.selector”.
Yes - and lingua.getField and the lingua plugin.
I’ve noticed that all the system settings are wrong.
There names arelingua_lingua.contexts
,lingua_lingua.debug
, etc. but should belingua.contexts
,lingua.debug
etc.
I guess they should be lingua_lingua but they are lingua
Another line gives error messages:
PHP warning: Undefined array key “” in lingua_selector
$language['url'] = $pageURL . (!empty($hasQuery) ? '&' : '?') . $langKey . '=' . $language[$codeField];
$phs = $lingua->setPlaceholders($language, $phsPrefix, false);
Some snippet properties (probably erroneously) have an empty value in the default property set.
You have to add true
as the fourth parameter of the method $modx->getOption()
, so that the empty value is ignored.
$langKey = $modx->getOption('getKey', $scriptProperties, $modx->getOption('lingua.get_key', null, 'lang'), true);
...
$phsPrefix = $modx->getOption('phsPrefix', $scriptProperties, 'lingua.', true);
$codeField = $modx->getOption('codeField', $scriptProperties, 'lang_code', true);
@halftrainedharry - do you have any idea about the reason for those errors in my log?