Known has a mechanism for translating text into other languages, and I’ve been working on this recently to try and make this ready for folk to begin adding translations.
When Known boots, it creates a new Language() object on the Idno object for the current language, which is addressable by
\Idno\Core\Idno::site()->language();. Your code/plugin can add strings to this object for later use, usually by registering them on the
registerTranslations() method hook.
Adding a translation for a language
It is possible to add single strings, one by one, for the current language, however the easiest way to register multiple strings is to extend
Idno/Core/Translation for each language you want to translate, and then implement its
It is then possible to add them all at once for each language (this way, Known will automatically select the appropriate translation for the loaded language).
Using a translation
Once a string has been registered, it is possible to echo the string, and have it translated:
echo \Idno\Core\Idno::site()->language()->_('This is the string to translate');
URL unfurling is one of the names given to that funky thing that happens when you paste a web address into a post in Facebook (or other social network) and automatically get a preview of it – an image, the title and maybe some extract text.
This was a much requested technology that was sadly missing from Known for a long time, but for no longer!
In the latest builds you will automatically get URL unfurling occurring in status posts and likes/bookmarks. What’s more, you’ll get a URL preview when you’re editing your post.
Behind the scenes this tool makes use of a number of technologies, notably:
The Unfurling endpoint
When passed a URL, this endpoint will attempt to fetch and parse out header tags – title, open graph, facebook and twitter tags. It’ll also attempt to extract certain whitelisted OEmbed endpoints (currently only JSON endpoints are supported).
It will then render out in a pretty way – using oembed as preference, but if that’s not present (or not whitelisted) it’ll use Open Graph, and finally page title and description meta tags if nothing else is found.
If there is an image present in the open graph headers, this will be retrieved by a local caching image proxy. This proxy fetches and saves the image locally so that the remote site doesn’t get hit every time you refresh your page (this also helps protect your privacy).
Further to my last post, I’d like to introduce you to a working implementation of the stats gathering mechanism using Etsy StatsD and NodeJS.
StatsD is a Node.JS stats server created by the people at etsy to provide a simple way of logging useful statistics from software. These statistics are an invaluable way of monitoring the performance of your application, monitoring the performance of software changes and diagnosing faults.
This plugin gives you an overview of what is happening in your Known install by logging important system level things – events, errors, exceptions etc. This lets you get a very clear idea of how your Known network is performing, and quickly see the effect that changes have on your users.
- Install Node.JS, either from github or the package manager for your OS
- Install StatsD
- Not required, but highly recommended, install a Graphite server for graph visualisation
- Place this plugin in IdnoPlugins/StatsD
- Add the following to your
statistics_collector = IdnoPlugins\StatsD\StatsDStatisticsCollector;
statsd_enabled = true;
Optionally, you can specify one or more of the following extra options, (although the defaults are usually ok):
statsd_host = localhost
statsd_port = 8125
statsd_bucket = some_name
statsd_samplerate = 1
statsd_samplerate is handy on really busy systems (see Statsd’s notes on the subject), but in a nutshell, setting this to something like 0.1 (capture one in every 10 count or timer events) is handy if you find StatsD being overloaded.
If everything is working, you should now be happily graphing some useful stats.
» Visit the project on Github...