Hi,
I've seen a few posts on how to translate forms, but I just wanted to post the way I went about it. Please keep in mind that I am far from being a php coder, I simply observe closely and analyze. This time I analyzed how components would incorporate language files, and basically applied the same concept to my form. I find this easier and cleaner than adding the entire language information and conditional language checking to the form code itself. This might not be a big deal if you have a small form with 2 languages, but what if you're site uses 4 or 5 languages?. Anyway, here it is
First the form:
english.php:
spanish.php:
Please note the path of the language file and change this according to your settings. Again, I'm not a coder or anything like that, so if anyone has suggestions for a better way please share.
I've seen a few posts on how to translate forms, but I just wanted to post the way I went about it. Please keep in mind that I am far from being a php coder, I simply observe closely and analyze. This time I analyzed how components would incorporate language files, and basically applied the same concept to my form. I find this easier and cleaner than adding the entire language information and conditional language checking to the form code itself. This might not be a big deal if you have a small form with 2 languages, but what if you're site uses 4 or 5 languages?. Anyway, here it is
First the form:
<?php
// Calling the path global, and the language global
global $mosConfig_absolute_path, $mosConfig_lang;
// Checking for language file according to languae setting. If non use the english.php file (you can change this to your defualt language
if (file_exists($mosConfig_absolute_path."/components/com_chronocontact/language_form01/".$mosConfig_lang.".php"«»)){
include_once($mosConfig_absolute_path."/components/com_chronocontact/language_form01/".$mosConfig_lang.".php"«»);
}
else{
include_once($mosConfig_absolute_path."/components/com_chronocontact/language_form01/english.php"«»);
}
?>
<table width="100%">
<tbody>
<tr>
<td><?php echo _FORM_DESCRIPTION_; ?>
<table border="0" cellspacing="5">
<tbody>
<tr>
<td width="90"><?php echo _FIELD_LABEL_TYPE_; ?></td>
<td><select name="type" id="type">
<option value=""><?php echo _FIELD_OPTION00_TYPE_; ?></option>
<option value="value01"><?php echo _FIELD_OPTION01_TYPE_; ?></option>
<option value="value02"><?php echo _FIELD_OPTION02_TYPE_; ?></option>
<option value="value03"><?php echo _FIELD_OPTION03_TYPE_; ?></option>
</td>
</tr>
<tr>
<td width="90"><?php echo _FIELD_LABEL_HEADING_; ?>:</td>
<td><input name="heading" size="40" maxlength="100" class="inputbox"></td>
<td><?php echo _FIELD_DESCRIPTION_HEADING_;?></td>
</tr>
<tr>
<td><span style="font-weight: bold;"><?php echo _FIELD_LABEL_NAME_; ?></span>:</td>
<td><input name="name" size="40"
type="text" class="inputbox"></td>
<td> </td>
</tr>
<tr>
<td><?php echo _FIELD_LABEL_MESSAGE_; ?>:</td>
<td><textarea rows="5" cols="80"
name="message"></textarea><br>
</td>
</tr>
<tr>
<td><?php echo _FIELD_LABEL_INSTRUCTIONS_; ?>:</td>
<td><input name="instructions" size="40" maxlength="100"></input>
</td>
</tr>
</tbody>
</table>
<button type="submit" class="button"><?php echo _FIELD_LABEL_SUBMIT_; ?></button>
<button type="reset" class="button"><?php echo _FIELD_LABEL_RESET_; ?></button>
</td>
</tr>
</table>
english.php:
<?php
// ensure this file is being included by a parent file
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
// Field Labels
DEFINE("_FIELD_LABEL_TYPE_","TYPE"«»);
DEFINE("_FIELD_LABEL_HEADING_","Heading"«»);
DEFINE("_FIELD_LABEL_NAME_","Name"«»);
DEFINE("_FIELD_LABEL_MESSAGE_","Message"«»);
DEFINE("_FIELD_LABEL_INSTRUCTIONS_","Instructions"«»);
DEFINE("_FIELD_LABEL_SUBMIT_","Submit"«»);
DEFINE("_FIELD_LABEL_RESET_","Clear"«»);
// Field Type Labels
DEFINE("_FIELD_OPTION00_TYPE_","SELECT ONE"«»);
DEFINE("_FIELD_OPTION01_TYPE_","Value01"«»);
DEFINE("_FIELD_OPTION02_TYPE_","Value02"«»);
DEFINE("_FIELD_OPTION03_TYPE_","Value03"«»);
// Form General Headers
DEFINE("_FORM_DESCRIPTION_","<strong>This form can handle many languages</strong>"«»);
...
?>
spanish.php:
<?php
// ensure this file is being included by a parent file
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
// Field Labels
DEFINE("_FIELD_LABEL_TYPE_","TIPO"«»);
DEFINE("_FIELD_LABEL_HEADING_","Encabezado: "«»);
DEFINE("_FIELD_LABEL_NAME_","Nombre: "«»);
DEFINE("_FIELD_LABEL_MESSAGE_","Mensaje: "«»);
DEFINE("_FIELD_LABEL_INSTRUCTIONS_","Instrucciones: "«»);
DEFINE("_FIELD_LABEL_SUBMIT_","Enviar"«»);
DEFINE("_FIELD_LABEL_RESET_","Borrar"«»);
// Field Type Labels
DEFINE("_FIELD_OPTION00_TYPE_","SELECCIONE UNO"«»);
DEFINE("_FIELD_OPTION01_TYPE_","Valor01"«»);
DEFINE("_FIELD_OPTION02_TYPE_","Valor02"«»);
DEFINE("_FIELD_OPTION03_TYPE_","Valor03"«»);
// Form General Headers
DEFINE("_FORM_DESCRIPTION_","<strong>Este formulario maneja multiple idiomas</strong>"«»);
....
?>
Please note the path of the language file and change this according to your settings. Again, I'm not a coder or anything like that, so if anyone has suggestions for a better way please share.