i have javascript code needs localisation, ie.
function js_proc() { var some_data = 'this text needs translated dynamically @ runtime'; }
so re-wrote this:
function js_proc() { var some_data = <?php echo $this->lang->line('some_data_id'); ?>; }
in view, wrote js link this:
<script type="text/javascript" src="www.domain.com/codeigniter/get_js/file-1/"></script>
which calls function get_js() in controller. idea have get_js() function read js file(s) , translate language strings...
there way many js strings translated, can't pass every string
variable. ideally i'd make work through codeigniter language files.
my question is: there way parse php parts in js file & executed (=translate) them? ie.
class app extends ci_controller { function get_js { $content = file_get_contents($js_file); echo parse_php($content); } ... }
thanks!
depending on how big language file is, quick way allow javascript access entire language array load array global javascript array;
<script> var globallang = <?php echo json_encode($this->lang->language); ?>; </script>
then access in javascript this;
globallang['some_lang_key']
Good job! For Sharing your best ideas... I will refer the people to best learning and training Institute for online courses... click the below link:
ReplyDeleteshort courses in pakistan
react native advanced concepts
sorting algorithms c++
graphic designing institute
mern stack course online
php training institute
e commerce online course in pakistan
Online short courses in Pakistan
Tech Inn Solutions