Can gettext translate text via AJAX from php file?
This is an example of what I'm trying to do.
<div id="resultText"></div> <?php echo gettext('Other text'); ?> <script> $(document).ready(function() { $.post('somefile.php', somedata, function(r) { $('#resultText').html(r); }); }); </script>
And php file:
<?php // somefile.php // gettext setup (from an included file) $lang = "de_DE"; if (isset($_GET['lang'])) $lang = $_GET['lang']; putenv("LC_ALL=$lang"); setlocale(LC_ALL, $lang); bindtextdomain("de_DE", "locale"); bind_textdomain_codeset('de_DE', 'UTF-8'); textdomain("de_DE"); // do some logic echo gettext('Text to be translated'); ?>
POEdit picks up the string somefile.php to translate ... and "Other Text" translates correctly. But "Text for Translation" is not ... :(
Any ideas?
source share