snytkine / LampCMS

Open source Question and Answer program similar to StackOverflow and Quora in PHP + MongoDB. Follow @snytkine on Twitter

Home Page:http://support.lampcms.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Research the possibility of applying Translation from ob callback

snytkine opened this issue · comments

It may be more efficient to replace I18n strings from output buffer callback.
Usually during creation of one web page many blocks are rendered, many blocks expect already translated strings to be passed
to them in variables array, so we call TR object many many times when creating a single page.
What if we could just not worry about this in most of the blocks and just pass strings like %%Welcome back%%
%%Asked%%
%%Number of questions%%
then use preg_replace_callback from output buffer callback function. It will be done once per page rendering.
Also it will be alot easier to have default values in templates to be translatable strings like %%Reply%% or %%Vote%%
and don't worry about translating these strings before passing array to template parse() function.

And also some static classes don't need to be passed the TR object in order to translate strings.
Lastly exceptions messages don't have to be translated, just use %%Error occured%% as message of exception and it will be translated when page is rendered.

This callback can also be combined with another function to replace pseudo variables like {WWW_DIR}

So a single ob callback can be used to apply these 2 functions when buffer is sent to browser.

This can potentially improve performance by reducing number of calls to TR object.

This is done.