php - Include javascript files content in ob_start buffer -
i working on translation of website.  perform translation easily, created .csv file containing matches between 2 languages (japanese->english). then, file parsed php, , ob_start() called on page in order replace wanted strings.
here script :
    function lang_modify($buffer){                 require('get_messages.php');                for($i=0; $i<count($messages); $i++){                    $buffer = str_replace($messages[$i][0], $messages[$i][1], $buffer);                }                  return $buffer;          }     $buffer = ob_start('lang_modify');   this script works on php/html files. however, ob_start not read javascript files wondering if knows way include javascript files output buffer ob_start() function replace words found in javascript well.
someone adviced me search addfile statement (.htaccess), don't know @ how use want. 
does have clue ?
what facing here, separation of concerns issue.
your translation generated php.
and yet, javascript displays , (sometimes) generates messages.
how fix this?
1) make sure translations comes 1 single source, ideally php
2) use i18n js library process translations. suggest: https://airbnb.github.io/polyglot.js/
3) if using polyglot, make sure php translations being generated js file, loaded based on localisation.
polygot translate default messages internationalized ones.
in short:
- enable modularity - administer(crud) translations in php. storing them in database ideal
 - decouple js translation - polygot provide translated messages views(html).
 
Comments
Post a Comment