Skip to content

Instantly share code, notes, and snippets.

@darklow
Last active December 31, 2015 02:09
Show Gist options
  • Save darklow/7919307 to your computer and use it in GitHub Desktop.
Save darklow/7919307 to your computer and use it in GitHub Desktop.
Koken translation tag. <koken:trans en="Hello" fr="Bonjour" lv="Sveiki" />
<?php
class TagTrans extends Tag {
function generate()
{
$value = '""';
$lng = isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'en';
if(isset($this->parameters[$lng])){
$value = '"' . $this->attr_parse($this->parameters[$lng]) . '"';
}
return <<<DOC
<?php echo $value; ?>
DOC;
}
}
/* Usage:
------------
1. Copy this file to ./app/site/tags/ directory.
2. Add your own HTML/JS language switcher to templates and ensure $_COOKIE['lang'] is set with wanted language ('en', 'fr', ...)
3. In templates use <koken:trans en="Hello" fr="Bonjour" lv="Sveiki" />
Now correct translation will be displayed.
Enjoy!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment