custom js struggling

mdma 18 Aug, 2015
Hello,
iam trying to:
a.)redirect with a button to external dynamical url based on selected language
b.)changing the form-mehod to Get request to get the form params


a.)how to build a action-url dynamically based on selected language???
maybe it is easier to build different forms for different languages?

custom code for button at the moment:
jQuery(function() {
jQuery('#Submit_id').click(function(){
   jQuery('#chronoform-FormA_id').attr('method', 'get').attr('action', 'url');
  });
});


b.)ok.. could this be done better than this?
GreyHead 19 Aug, 2015
Hi mdma,

Where is the language being selected? That makes a big difference to how you do this. Is it the site language, (or the browser language), or is the user selecting in the form?

Bob
mdma 19 Aug, 2015
Hi!

Site language, selected by user.

multilingual site, (de, en, it, fr )
Joomla onboard language switcher

Why i ask:

1.) i have html inside custom-code to translate
is there a way to add php/html to locale settings?
a big bunch of code somehow with " , '

2.)i need to switch javascript based on language set..
GreyHead 19 Aug, 2015
Hi mdma,

You can resolve most of these question (perhaps all of them) using the code that you already have plus a PHP switch statement:
<?php
$lang = \JFactory::getLanguage();
$tag = $lang->getTag();
switch ( $tag ) {
  case 'de-DE':
  default:
    //set some value here or add some code
    break;
  case 'fr-FR':
    // French code here
   break;
  . . .
}
?>
ChronoForms also supports Locales which will use search and replace to change labels in the form HTML and some other places.

You can use the same code in a Load JavaScript action to load different scripts or parts of scripts.

Bob
mdma 19 Aug, 2015
...Locales:
are these only one-liners like:
#String to be replaced#=some Text
or would it also be possible to enclose in some way like:
#String#={alot of html containing =, " <div class=blabla><h1>oirfroinf....}


You can use the same code in a Load JavaScript action to load different scripts or parts of scripts:
you mean i can mix javascript with php inside javascript-action?
or is it meant to switch(include) different javascript based on php-code
GreyHead 20 Aug, 2015
Hi mdma,

or would it also be possible to enclose in some way like: No - you can't do that - use the Switch structure instead.

you mean i can mix javascript with php inside javascript-action? as long as the result is valid JavaScript e.g.
<?php
$lang = \JFactory::getLanguage();
$tag = $lang->getTag();
echo "alert($tag);";
?>

Bob
mdma 20 Aug, 2015
Answer
thank you i am nearly getting it completely my last question regarding this:
i stumbled upon:http://www.chronoengine.com/faqs/2669-how-can-i-translate-emails.html
which should be called "advanced multilanguage" in faq 😀
regarding this code snippet:
<?php
$lang =& JFactory::getLanguage();
$tag =& $lang->getTag();
include (JPATH_SITE."/components/com_chronoforms/includes/{$form->form_details->name}/email_template.{$tag}.php");
?>

how would that look like for including js-files? instead of "include"
include (JPATH_SITE."/components/com_chronoforms/includes/custom.{$tag}.js
mdma 20 Aug, 2015
i have seen this but dont know if/how this can be combined:
<?php
$jdoc =& JFactory::getDocument();
$jdoc->addScript('file_url');
?>
mdma 20 Aug, 2015
<?php
$lang =& JFactory::getLanguage();
$tag =& $lang->getTag();

$jdoc =& JFactory::getDocument();
$jdoc->addScript(JURI::root().'libraries/cegcore/assets/js/c1.$tag.js');

echo $tag;
?>


...in custom code action...

the script doesnt get loaded: 404 c1.$tag.js
also
$jdoc->addScript(JURI::root().'libraries/cegcore/assets/js/c1.{$tag}.js');


404 c1.%7B$tag%7D.js
mdma 20 Aug, 2015
<?php
$lang =& JFactory::getLanguage();
$tag =& $lang->getTag();
$scripturl = "libraries/cegcore/assets/js/c1.$tag.js";

$jdoc =& JFactory::getDocument();
$jdoc->addScript(JURI::root().$scripturl);
?>


This way language speciffic Js-files are loaded now
This topic is locked and no more replies can be posted.