Download the PHP package phpmyadmin/motranslator without Composer
On this page you can find all versions of the php package phpmyadmin/motranslator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phpmyadmin/motranslator
More information about phpmyadmin/motranslator
Files in phpmyadmin/motranslator
Package motranslator
Short Description Translation API for PHP using Gettext MO files
License GPL-2.0-or-later
Homepage https://github.com/phpmyadmin/motranslator
Informations about the package motranslator
motranslator
Translation API for PHP using Gettext MO files.
Features
- All strings are stored in memory for fast lookup
- Fast loading of MO files
- Low level API for reading MO files
- Emulation of Gettext API
- No use of
eval()
for plural equation
Limitations
- Default
InMemoryCache
not suitable for huge MO files which you don't want to store in memory - Input and output encoding has to match (preferably UTF-8)
Installation
Please use Composer to install:
Documentation
The API documentation is available at https://develdocs.phpmyadmin.net/motranslator/.
Object API usage
Low level API usage
Translator API usage
Gettext compatibility usage
Using APCu-backed cache
If you have the APCu extension installed you can use it for storing the translation cache. The .mo
file
will then only be loaded once and all processes will share the same cache, reducing memory usage and resulting in
performance comparable to the native gettext
extension.
If you are using Loader
, pass it an ApcuCacheFactory
before getting the translator instance:
If you are using the low level API, instantiate the ApcuCache
directly:
By default, APCu will cache the translations until next server restart and prefix the cache entries with mo_
to
avoid clashes with other cache entries. You can control this behaviour by passing $ttl
and $prefix
arguments, either
to the ApcuCacheFactory
or when instantiating ApcuCache
:
If you receive updated translation files you can load them without restarting the server using the low-level API:
You should ensure APCu has enough memory to store all your translations, along with any other entries you use it
for. If an entry is evicted from cache, the .mo
file will be re-parsed, impacting performance. See the
apc.shm_size
and apc.shm_segments
documentation and monitor cache usage when first rolling out.
If your .mo
files are missing lots of translations, the first time a missing entry is requested the .mo
file
will be re-parsed. Again, this will impact performance until all the missing entries are hit once. You can turn off this
behaviour by setting the $reloadOnMiss
argument to false
. If you do this it is critical that APCu has enough
memory, or users will see untranslated text when entries are evicted.
History
This library is based on php-gettext. It adds some performance improvements and ability to install using Composer.
Motivation
Motivation for this library includes:
- The php-gettext library is not maintained anymore
- It doesn't work with recent PHP version (phpMyAdmin has patched version)
- It relies on
eval()
function for plural equations what can have severe security implications, see CVE-2016-6175 - It's not possible to install it using Composer
- There was place for performance improvements in the library
Why not to use native gettext in PHP?
We've tried that, but it's not a viable solution:
- You can not use locales not known to system, what is something you can not control from web application. This gets even more tricky with minimalist virtualisation containers.
- Changing the MO file usually leads to PHP segmentation fault. It (or rather Gettext library) caches headers of MO file and if it's content is changed (for example new version is uploaded to server) it tries to access new data with old references. This is bug known for ages: https://bugs.php.net/bug.php?id=45943
Why use Gettext and not JSON, YAML or whatever?
We want translators to be able to use their favorite tools and we want us to be able to use wide range of tools available with Gettext as well such as web based translation using Weblate. Using custom format usually adds another barrier for translators and we want to make it easy for them to contribute.