I’m developing a plugin to translate text to SignWriting. The plugin needs to load a new locale, that is not distributed with OJS. It also uses JavaScript for the SignWriting translation.
The locale is site wide, a new language, like pt_BR, en_EN, not restricted to the plugin itself.
Is there a way to do that using the plugin, without modifications into the OJS instance? (include the locale on registry/locales.xml, and put locale files on /locales and /lib/pkp/locales)
Had some progress using a combination of dynamic locale loading, based on the custom locale plugin, and adding the new locale directly on the locales list cache.
Now the plugin can load the new locale (sn_BR), in which the locale files are included into the plugin folder. The new locale also is displayed on the UI, and can be toggle on/off as usual.
The only point that needed modification directly on OJS, was the need to create a symbolic link between the OJS “/locale/sn_BR” directory to the plugin folder where the locales are loaded.
This point is only necessary because of some validation made on locales, by the PKPLocale::isLocaleValid method, which checks for the existence of the “/locale/sn_BR” directory. If there is no folder there, the locale is not loaded, even if the locale files are in fact loaded by our plugin, triggered by a hook.
It would be perfect if it was not necessary to create the symbolic link. Any ideas?
I guess pkplib ought to have a hook PKPLocale::isLocaleValid that is evaluated in the function of that same name and allows to short-circuit the normal logic, so that a plugin can insert its own test instead: If the plugin knows it can load that locale, the callback returns true for isLocaleValid; if it does not, it defers the evaluation to the ordinary implementation of PKPLocale::isLocaleValid.
I think this restriction might have gone away with OJS/OMP/OPS 3.4.0: it is no longer necessary for OJS to include a translation of a locale for Locale::isLocaleValid to accept it as valid. Now it only needs to pass a regular expression:
Regards,
Alec Smecher
Public Knowledge Project Team