Adding pgettext (gettext context) support to PHP

TL;DR: Packagist Version

It seems the PHP team completely forgot about adding support for gettext context functions, so I implemented them based on what I found in this Stack Overflow answer.

The functions signatures (names and parameters) are what I’m seing in C and Python.

So, if you want to use them – here it is. However, you are probably using composer so you are going to use this:

  1. In your CLI:
    composer require datalinx/gettext-context
  2. Include the vendor/datalinx/gettext-context/src/gettext-context.php file when you need it*

* It’s not added to the autoload directive, since you might not need or want to always include it in runtime. If you want to always load it, just add the source file to your composer.json autoload files list:

    "autoload": {
        "files": [

Now you have pgettext, npgettext, dpgettext, dnpgettext function ready to use in your PHP code.

The functions are documented and fully tested.

Extracting messages with context support

If you are using the xgettext CLI utility, you can add extra keyword parameters to include the context functions. For example, this would be used in our package:

xgettext --force-po --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 --keyword=dpgettext:2c,3 --keyword=dnpgettext:2c,3,4 -c -o messages.po tests/Test.php

If you’re using Poedit, add the following keywords in your Catalog > Properties > Sources Keywords:

  • pgettext:1c,2
  • npgettext:1c,2,3
  • dpgettext:2c,3
  • dnpgettext:2c,3,4

Using Dell D3100 USB3.0 dock with Ubuntu Linux

If you are considering buying this universal USB “dock” to use it with Ubuntu Linux, I say: go for it. It just plain works.

Basically all you have to do is hook it up and install the DisplayLink driver.

I am currently (March 2020) using it with my Asus TUF Gaming FX705GD laptop with Ubuntu 19.10 as described in my other article.

You do have to know that using a DisplayLink dock will never be the same as hooking the external monitors directly to the laptop, since it uses compression to deliver the image to the monitor. This is most noticeable when scrolling – it’s just not as smooth.

Regarding CPU usage, there is a slight increase but is barely noticeable and completely inconsequential, at least with one Quad HD (2560×1440 px) monitor.

Hot-plugging works perfectly. However when setting it up, it might display some distortion or artefacts around the mouse cursor. To fix this, all I needed to do was log out and back in.

Basically I would gladly recommend this dock, though I have not tried an UHD/4K or multiple monitors.

Asus TUF Gaming FX705GD and Ubuntu Linux

UPDATE: everything works out-of-the-box with Ubuntu 20.04 LTS.

For anyone considering buying this laptop and running Ubuntu Linux on it, here’s my experience with it.

It’s been 4 months now and my experience is positive – everything works, though not from the beginning. My exact model is FX705GD-EW106T with the following specs:

  • CPU: Core i7 8750H
  • RAM: 16GB of DDR4 (now upgraded to 32GB)
  • Storage: 256GB NVMe SSD + 1TB HDD
  • GPU: GTX 1050 (switching)
  • Screen: 17,3″ Full HD IPS
  • OS: Windows 10 Home

TL;DR: Use kernel 5.3+ and everything will work.

Asus TUF Gaming FX705GD running Ubuntu 19.10
Asus TUF Gaming FX705GD running Ubuntu 19.10

I initially tried installing Ubuntu 18.04 because I prefer LTS releases, but although it installed normally, I could not boot into Ubuntu. I did not invest any time in debugging, because I already had the 19.04 image ready, so I tried installing that. It worked, I guess because of the 5.0 kernel.

With Ubuntu 19.04 and kernel 5.0 pretty much everything worked, except the keyboard backlight. For example, when waking up the laptop from sleep, it would not light up at all. Only turning off the machine and starting it again would make the backlight come back. Or it would stay on even when the screen was locked and therefore turned off.

So using the Ukuu tool I updated the kernel to 5.2 and backlight was working again when coming back from sleep – most of the time. However, the function keys to brighten or dim the backlight would still not work (there are 3 levels btw). Any press of either keys would completely turn off the backlight and again a complete power off was needed to get it back.

So some time passed and kernel 5.3 was released. It was with great joy that after installing it, I could state the laptop was fully functional – the backlight was working and so were the + and – keys.

Today (Dec 2019), after upgrading Ubuntu, I am on 19.10 which ships with kernel 5.3, so if you install this release, everything should work out of the box!

So your choice is either to use the 5.3 kernel on a pre-19.10 version or to use 19.10.

CKEditor save button callback

I am sharing this since it was impossible to find with Google.

Before CKEditor 4.2 if you wanted to handle the save event with a custom function, you had to write your own plugin.

Now all you need to do is to specify the callback upon initialization:

CKEDITOR.replace('ckeditor', {
	on: {
		save: function(evt)
			// Do something here, for example:

			// If you want to prevent the form submit (if your editor is in a <form> element), return false here
			return false;

jQuery YoxView “Error loading language file”

A quick note for all googlers: If you happen to stumble upon this error when using the great YoxView plugin for jQuery, make sure you don’t put the script in a folder that has “jquery.yoxview” in it’s name. There’s a bug in the script which uses a loose regular expression, which, when provided the following URL
will return
and thus will try to request the language files from e.g.

I have the habit of unzipping the archive and using a full script name + version for the folder name, which has the benefit, that when you change the script version, all your returning visitors will definitely get the latest script since the cache for it will not exist.