ExpressionEngine Plugin to translates a given string using a dictionary
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

#Sk Reword - ExpressionEngine Plugin

Version: 1.0.0
Jean-Francois Paradis -
Copyright (c) 2012 Jean-Francois Paradis
MIT License - please see LICENSE file included with this distribution


This plugin extends on similar functionality provided by the function translate() or __() in Wordpress which translates a given string using a dictionary.

This implementation can also handle placeholders (eg: Hello %s) and can translate dates formats (eg: Today is %d).

The language of the user is detected using the browser settings and stored in a cookie. The language can be changed by providing a 'lang' parameter in the url (eg: This changes the cookie, and persists even id the 'lang' parameter does not appear in subsequent urls.

The list of supported languages is defined in languages.php, which allows to convert between language codes (sent by the browser 'Accept Language' header or by the 'lang' parameters) and language strings used by Code Igniter.

The dictionaries are located in the 'language_path' folder defined in the configuration (default /themes if not provided), in the given languages subfolder. The system also supports multisite and multiple language sets per language (default 'all').

example (one file for all): /var/www/themes/languages/default_site/french/lang.all.php

example (one file for set='front', one for set='profile', the rest goes in 'all'): /var/www/themes/languages/default_site/french/lang.front.php /var/www/themes/languages/default_site/french/lang.profile.php /var/www/themes/languages/default_site/french/lang.all.php

The language file must define a $lang associative array as follows.


'Bonjour', 'Hello %s' => 'Bonjour %s', '%s search results for "%s"' => '%s résultats pour "%s"', '%M %d, %Y' => '%d %M %Y', 'Posted %d' => "Publié le %d" ); If navigating to {exp:sk_reword text='Hello'}
{exp:sk_reword text='Hello %s' string='Mary'}
{exp:sk_reword text='%s search results for "%s"' string='25|Test'}
{exp:sk_reword text='Posted %d' format='%M %d, %Y' date='2010-01-01'} Will render as (if using the set above): Bonjour Bonjour Mary 25 résultats pour "Test" Publié le 07 Sep 2012 ##Setup Download the "sk_reword" folder and upload it to the third party directory of your ExpressionEngine folder. ##Usage: ### Basic Translation {exp:sk_reword text=''} Replaces $text with its translated equivalence in the dictionary using the language of the user. If there is no translation, the original text is returned. example: {exp:sk_reword text='Hello'} You can also specify a language set. example: {exp:sk_reword set='profile' text='My Profile'} ### String replacement {exp:sk_reword text='' string=''} Translates $text as above, then replaces %s in $text with the content of $string. Can also replace multiple occurrences of %s when multiple values are provided in $string and separated by '|'. example: {exp:sk_reword text='Hello %s' string='{username}'} example: {exp:sk_reword text='%s search results for "%s"' string='{exp:search:total_results}|{exp:search:keywords}'} ### Date format and replacement {exp:sk_reword text='' format='' date=''} Translates $text as above, then translates $format using the same process, and then replaces %d in $text with $date (default current date) using the given $format. This function is used to support language-specific date formats. If $text is not provided, the date is returned with the correct format. example: {exp:sk_reword text='Posted %d' format='%M %d, %Y' date='{entry_date}'} example: {exp:sk_reword format='%M %d, %Y'} ##Changelog 1.0.0 - Initial plugin