This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Multi language website support
#1

Hi there,
Commentics supports multiple languages itself, but once you have set a frontend language it cannot be changed anymore on the site.

Many sites support multiple languages too, e.g. by clicking a flag icon in the website's menu, the sites changes its language accordingly. This is usually done by submitting a POST parameter in the URL.

Commentics cannot react to that right now. It would be great if it could.

Here is an idea how it could be done.

When commentic.php is called from a web page, the a frontend language could be passed to it. Here is an example how that could look like:
PHP Code:
<?php 
$cmtx_identifier
= '1';
$cmtx_reference = 'My Topic';
$cmtx_path = 'comments/';
$cmtx_frontend_language = $website_frontend_language;
define('IN_COMMENTICS', 'true'); //no need to edit this line
require_once $cmtx_path . 'includes/commentics.php'; //no need to edit this line

"$website_frontend_language" would be a variable that was set via PHP from a POST paramater.

In commentics.php you could react to that like this:
PHP Code:
<?php 
/*************************************************************** LANGUAGE ***************************************************************/
if (!isset($cmtx_frontend_language)) $cmtx_frontend_language = cmtx_setting('language_frontend');
require_once
$cmtx_path . 'includes/language/' . $cmtx_frontend_language . '/page.php'; //load language file for page
require_once $cmtx_path . 'includes/language/' . $cmtx_frontend_language . '/comments.php'; //load language file for comments
require_once $cmtx_path . 'includes/language/' . $cmtx_frontend_language . '/processor.php'; //load language file for processor
require_once $cmtx_path . 'includes/language/' . $cmtx_frontend_language . '/form.php'; //load language file for form
require_once $cmtx_path . 'includes/language/' . $cmtx_frontend_language . '/countries.php'; //load language file for countries
require_once $cmtx_path . 'includes/language/' . $cmtx_frontend_language . '/ratings.php'; //load language file for ratings
/****************************************************************************************************************************************/

I think this would be a nice improvement.

Thank you very much for your great script. Best regards,
george
Reply
#2

Hi George,

This is very likely to be a feature in a future version. After all, it would be a shame for Commentics not to make full use of all the translations people have contributed. However it's a little more complicated than your solution, which is one of the reasons why it hasn't been added yet. For example with your solution the email subscribers would receive their email notification in whatever language the person posting the comment was using. To fix this the subscribers table in the database would need to store each subscriber's preferred language. Then the other reason why it hasn't been added yet is because there isn't much room around the comments section to add another feature. With everything enabled the only available space is between the 'Sort By' menu on the left and the 'Topic' on the right. If you have any advice regarding this then it would be appreciated. A final reason is because a lot of the languages need updating before this feature is added. I noticed you updated the German translation so thanks very much for that.

Have you completed the interview?
Reply
#3

I have just started to use Commentics and have arrived this old thread looking for multi language support. I have implemented the same idea on v2.5, modifying includes/bootstrap/language.php instead of commentics.php. I added the line

PHP Code:
<?php 
if (!isset($cmtx_frontend_language)) $cmtx_frontend_language = cmtx_setting('language_frontend');
on top of the file and then replaced all other occurrences of

PHP Code:
<?php 
cmtx_setting
('language_frontend')
by

PHP Code:
<?php 
$cmtx_frontend_language

Up to now it works like a charm.
Next I have tried to get captcha questions, terms and conditions and privacy policy translated, modifying files includes/functions/form.php and includes/template/form.php like in this example:
PHP Code:
<?php
if (!isset($cmtx_frontend_language)) $cmtx_frontend_language = cmtx_setting('language_frontend');
if (
file_exists($cmtx_path . 'agreement/' . $cmtx_frontend_language . '/custom/terms_and_conditions.html')) {
$terms_link = '<a href="' . cmtx_commentics_url() . 'agreement/' . $cmtx_frontend_language . '/custom/terms_and_conditions.html" class="cmtx_terms_link" title="' . CMTX_TERMS_LINK_TITLE . '" target="_blank" rel="nofollow">' . CMTX_TERMS_LINK . '</a>';
} else {
$terms_link = '<a href="' . cmtx_commentics_url() . 'agreement/' . $cmtx_frontend_language . '/terms_and_conditions.html" class="cmtx_terms_link" title="' . CMTX_TERMS_LINK_TITLE . '" target="_blank" rel="nofollow">' . CMTX_TERMS_LINK . '</a>';
}
?>
but the change is ignored. I guess I must retrieve cmtx_frontend_language variable from the page in some way, so that it is taken into account, but I'm almost new to php and don't know how to do it. Suggestions are welcome.
Reply
#4

(10-Jan-2016, 12:15 PM)Carluti Wrote:  Up to now it works like a charm.
Next I have tried to get captcha questions, terms and conditions and privacy policy translated, modifying files includes/functions/form.php and includes/template/form.php like in this example:
PHP Code:
<?php
if (!isset($cmtx_frontend_language)) $cmtx_frontend_language = cmtx_setting('language_frontend');
if (
file_exists($cmtx_path . 'agreement/' . $cmtx_frontend_language . '/custom/terms_and_conditions.html')) {
$terms_link = '<a href="' . cmtx_commentics_url() . 'agreement/' . $cmtx_frontend_language . '/custom/terms_and_conditions.html" class="cmtx_terms_link" title="' . CMTX_TERMS_LINK_TITLE . '" target="_blank" rel="nofollow">' . CMTX_TERMS_LINK . '</a>';
} else {
$terms_link = '<a href="' . cmtx_commentics_url() . 'agreement/' . $cmtx_frontend_language . '/terms_and_conditions.html" class="cmtx_terms_link" title="' . CMTX_TERMS_LINK_TITLE . '" target="_blank" rel="nofollow">' . CMTX_TERMS_LINK . '</a>';
}
?>
but the change is ignored. I guess I must retrieve cmtx_frontend_language variable from the page in some way, so that it is taken into account, but I'm almost new to php and don't know how to do it. Suggestions are welcome.
The problem is that recaptcha needs a value like "es" or "fr", but cmtx_frontend_language sends a value like "spanish" or "french".

So, I created another variable called $cmtx_frontend_recaptcha_language. Now my webpage code look like this: 


PHP Code:
<?php 
$cmtx_identifier
= '1';
$cmtx_reference = 'My Topic';
$cmtx_path = 'comments/';
$cmtx_frontend_language = $website_frontend_language;
$cmtx_frontend_recaptcha_language = "es";
define('IN_COMMENTICS', 'true'); //no need to edit this line
require_once $cmtx_path . 'includes/commentics.php'; //no need to edit this line 

And my code in includes/template/form.php:


PHP Code:
<?php 
if (!isset($cmtx_frontend_recaptcha_language)) $cmtx_frontend_recaptcha_language = "en";
if (
cmtx_setting('enabled_captcha') && cmtx_setting('captcha_type') == 'recaptcha') { ?>
<script type="text/javascript">
// <![CDATA[
var RecaptchaOptions = {
lang : '<?php echo $cmtx_frontend_recaptcha_language; ?>', 
theme : '<?php echo cmtx_setting('recaptcha_theme'); ?>'
};
// ]]>
</script>
<?php } ?>
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by Steven
29-Jul-2011, 11:44 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)