Jump to content

Extend H2O To Translate Everything With Cms Plugin


a.daniello

Recommended Posts

I'm playing with the great Admin Tools by naja7host and i need to use in my cms pages something to be translated.

 

So i make this simple extension of h2o.

 

1. create a file called "translate.php" under "vendors/h2o/ext";

 

2. add this code to the file

<?php
class Translate_Tag extends H2o_Node {
    var $lang_key;
    function __construct($argstring, $parser, $pos=0) {
        $this->lang_key = trim($argstring);
    }
    function render($context, $stream) {
        $stream->write(Language::_($this->lang_key, true));
    }
}
h2o::addTag('translate');
3. load this tag where do you need (for frontend, in "plugins/cms/controllers/main.php" at line 56) adding this code
 
h2o::load('translate');
It's all! So you can add a simple h2o tag as you need, for example
 
{% translate here_write_language_key_or_your_string_also_with_spaces  %}

Usually, i'm adding my custom text in languages/[lang]/_custom.php.

 

Hope that this can help someone.

 

 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...