I have to implement a webapp interface in several different foreign languages. I find that the jquery functions I am writing depend on what language is being implemented. For example:
<?php
require 'nl.php';
/*
if(isset($_SESSION['lang'])){
$lang = $_SESSION['lang'];
if(!empty($lang)){
if($lang == 'en'){
require 'en.php';
}else if($lang = 'nl'){
require 'nl.php';
}
}
}
*/
?>
<html>
<head>
</head>
<body>
<textarea id = "notes"><?php echo $string_lib['ENTER_NOTES'];?></textarea>
<script type="text/javascript" src= "js/jquery.js"></script>
<script type="text/javascript" src= "js/clicknotes.js"></script>
</body>
</html>
So this calls for a language file that provides an array. the commented out section is just to demonstrate how I am determining what's language to send. the first require command works in its place. Now here are the language files.
nl.php:
<?php
$string_lib = array(
'ENTER_NOTES' => 'Vul hier uw notities.',
'ENTER_PASSWORD' => 'Vul hier uw wachtwoord in.',
);
and en.php
<?php
$string_lib = array(
'ENTER_NOTES' => 'Enter your notes here.',
'ENTER_PASSWORD' => 'Enter your password here.',
);
?>
So now, problems arise when I start doing certain things in javascript, like this, clicknotes.js:
$(window).load(function(){
$(document).ready(function(){
$('#notes').focusin(function(){
if($(this).text() == 'Enter your notes here.'){
$(this).text('');
}
//alert($(this).text());
});
});
});
So I either have to dynamically generate the javascript with php using the same method I used for the html, like this:
<?php
header('Content-type: text/javascript');
?>
$(window).load(function(){
$(document).ready(function(){
$('#notes').focusin(function(){
if($(this).text() == '<?php echo $string_lib['ENTER_NOTES'];?>'){
$(this).text('');
}
//alert($(this).text());
});
});
});
or I have to send the equivalent arrays in javascript and call those variables in javascript,i.e. if($(this)).text() == string_lib['nl']['ENTER_NOTES']). OR I was thinking I could do an ajax request to get the arrays i need.
So, which of these methods would you say is best for maintainability and ease of modification?
$(document).ready()from inside$(window).load()?