0

I have a custom contact form, I send all the fields I need, but I can not translate a field.

Realizou compra: Sim
Pedido: Pedido #100000001 - Total: R$105.00 - Data: 31-07-2017 - Status: pending
Status: 
Telefone: 14654165
Assunto: Assunto
Motivo: Reclamação
Comentario: Comentario

I would like to change the status "pending" to Pending and all others, but the table(sales_flat_order) on which I get this data is not translated. I checked and another table (sales_order_status) is translated, but would I have to create another command just to get this table? Would I translate from the table I'm picking up?

controller

    public function getOrderByEmail() { 
    $customer_email = $this->getRequest()->getPost(); 
    $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_email', $customer_email) ; 

    foreach($orders as $order) { $date = $order->getCreatedAt();  $date = date("d-m-Y", strtotime($date)); 
    $neworderjson = array('orderid'=>$order->getIncrementId(), 'status'=>$order->getStatus(), 'total'=>number_format((float)$order->getBaseGrandTotal(), 2, '.', ''), 'created'=>$date); 
    $orderjson[] = $neworderjson;
    } 
    return $orderjson; 
    }

Template

<div id="messages_product_view"><?php echo $this->getMessagesBlock()->toHtml() ?></div>
<div class="page-title">
    <h1><?php echo Mage::helper('contacts')->__('Contact Us') ?></h1>
</div>
<form enctype="multipart/form-data" action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post" class="scaffold-form">
    <div class="fieldset">
        <h2 class="legend"><?php echo Mage::helper('contacts')->__('Contact Information') ?></h2>
        <p class="required"><?php echo Mage::helper('contacts')->__('* Required Fields') ?></p>
        <ul class="form-list">
            <li class="fields">
                <div class="field">
                    <label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Name') ?></label>
                    <div class="input-box">
                        <input style="height:24px;" name="name" id="name" title="<?php echo Mage::helper('core')->quoteEscape(Mage::helper('contacts')->__('Name')) ?>" class="input-text required-entry" type="text" />
                    </div>
                </div>
                <div class="field">
                    <label for="email" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Email') ?></label>
                    <div class="input-box">
                        <input style="height:24px;" name="email" id="email" title="<?php echo Mage::helper('core')->quoteEscape(Mage::helper('contacts')->__('Email')) ?>" class="input-text required-entry validate-email" type="email" autocapitalize="off" autocorrect="off" spellcheck="false" />
                    </div>
                </div>
            </li>
            <li>
                <label for="telephone"><?php echo Mage::helper('contacts')->__('Telephone') ?></label>
                <div class="input-box">
                    <input style="height:24px;" name="telephone" id="telephone" title="<?php echo Mage::helper('core')->quoteEscape(Mage::helper('contacts')->__('Telephone')) ?>" value="" class="input-text" type="tel" />
                </div>
            </li>
             <div class="select">
                <li>
                    <label for="f_f_assunto_ticket" class="required"><em>*</em>Motivo do contato</label>
                        <div class="input-box">
                            <select style="height:25px; padding:3px;" id="f_f_assunto_ticket" name="f_f_assunto_ticket" class="required-entry required-entry">
                            <option value="" selected="selected">-- Selecione --</option>
                            <option value="Dúvidas Sobre Entrega">Dúvidas Sobre Entrega</option>
                            <option value="Dúvidas Sobre Pagamento">Dúvidas Sobre Pagamento</option>
                            <option value="Dicas de Presente">Dicas de Presente</option>
                            <option value="Reclamação">Reclamação</option>
                            <option value="Elogio">Elogio</option>
                            <option value="Confirmação de Dados">Confirmação de Dados</option>
                            </select>
                        </div>
                </li>
            </div>            
            <div class="wide" id="pedido_option" style="display: none;">       
                <li>
                    <label for="f_compra" class="required"><em>*</em>Já realizou sua compra?</label>
                        <div class="input-box">
                            <select style="height:25px; padding:3px;" id="f_compra" name="f_compra" class="required-entry required-entry">
                            <option value="" selected="selected">-- Selecione --</option>
                            <option value='Sim'>Sim</option>
                            <option value='Não'>Não</option>
                            </select>
                        </div>
                </li>    
            </div>
            <div class="wide" id="pedido_txt" style="display: none;">            
                <li>
                    <label for="f_f_compra" class="required"><em>*</em>Já realizou sua compra?</label>
                        <div class="input-box">
                            <select style="height:25px; padding:3px;" id="f_f_compra" name="f_f_compra" class="required-entry required-entry select">
                            <option value="" selected="selected">-- Selecione --</option>
                            <option value="Sim">Sim</option>
                            <option value="Não">Não</option>
                            </select>
                        </div>
                </li>    
            </div>           
            <div id="pedido" style="display:none;">
                <li>
                    <label for="pedido" class="required"><em>*</em>Pedido</label>
                        <div class="input-box">
                        <select style="height:25px; padding:3px;" name="orders" id="orders"></select>
                        </div>   
                </li>
            </div>
            <div id="pedidon" class="wide" style="display:none;">
                <li>
                        <label for="pedidon" class="required"><em>*</em>Pedido</label>
                        <div class="input-box">
                            <input style="width:262px;" name="pedidon" id="pedidon" title="<?php echo Mage::helper('core')->quoteEscape(Mage::helper('contacts')->__('pedidon')) ?>" value="" class="input-box required-entry" type="text" />              
                        </div>
                </li>
            </div>                    
            <li class="fields">
                <div class="field">
                    <label for="assunto" class="required"><em>*</em>Assunto</label>
                    <div class="input-box">
                        <input style="width:262px;" name="assunto" id="assunto" title="<?php echo Mage::helper('core')->quoteEscape(Mage::helper('contacts')->__('assunto')) ?>" value="" class="input-box required-entry" type="text" />
                    </div>
                </div>
            <li class="wide">
                <label for="comment" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Comment') ?></label>
                <div class="input-box">
                    <textarea name="comment" id="comment" title="<?php echo Mage::helper('core')->quoteEscape(Mage::helper('contacts')->__('Comment')) ?>" class="required-entry input-text" cols="5" rows="3"></textarea>
                </div>
            </li>
        </ul>
    </div>
    <li>
            <label for="anexos">Anexar Arquivos</label>
            <div class="input-box">
                    <div class="MultiFile-wrap" id="attachment_wrap">
                        <input name="MAX_FILE_SIZE" type="hidden" value="2000000" />
                        <input type="file" class="multi MultiFile-applied" name="anexos" id="anexos" value="">
                            <div class="MultiFile-list" id="attachment_wrap_list"></div>
                    </div>
            </div>
        </li>
    <div class="buttons-set">
        <input type="text" name="hideit" id="hideit" value="" style="display:none !important;" />
        <button type="submit" title="<?php echo Mage::helper('core')->quoteEscape(Mage::helper('contacts')->__('Submit')) ?>" class="button"><span><span><?php echo Mage::helper('contacts')->__('Submit') ?></span></span></button>
    </div>
</form>
<script type="text/javascript">
//<![CDATA[
    var contactForm = new VarienForm('contactForm', true);
//]]>
</script>

<script type="text/javascript">
//Verifica o EMAIL para checar se tem algum PEDIDO cadastrado

$j("#email").focus(function() {}).blur(function() { 
    email = $j("#email").val(); 
        $j.ajax({url: "http://fol.projeto-gf.com.br/index.php/contato",
                type: "post",
                data: { type: "json", email: email },
                dataType: "json",
                success: function(result){ 
                $j("#orders" ).empty(); 
                    if (result == null) { 
                    } else { 
                        $j.each(result, function (index, data) { 
                        orderstring = "Pedido #" + result[index]["orderid"] + " - Total: R$" + result[index]["total"] + " - Data: " + result[index]["created"] + " - Status: " + result[index]["status"];
                        $j('#orders').append($j("<option></option>").attr("value",orderstring).text(orderstring)); 
            }) 
        } 
    }}); 
});
4
  • Hi Gustavo, so, we are talking about a custom module in this case? Aug 11, 2017 at 18:49
  • Yes, that's right Aug 11, 2017 at 18:52
  • Can you add the code of your template? Aug 11, 2017 at 18:55
  • I updated the question Aug 11, 2017 at 18:59

2 Answers 2

0
  1. Inside your config.xml you need to add the reference for the translation file:

    <frontend>
    <translate>
        <modules>
            <Custom_Module>
                <files>
                    <default>Custom_Module.csv</default>
                </files>
            </Custom_Module>
        </modules>
    </translate>
    

  2. The texts inside your phtml should always needs to have the helper to translate the text:

    __('text to translate');?>
  3. Set the translation file, create a folder inside app/locale/es_MX/Custom_Module.csv, and inside that file add your translations

"text to translate","Texto a traducir"

  1. If you want the translation for the status, you only need to go to the admin -> System -> Order Status.
  2. Then select the status you wanna to translate, select the store view, and put the translation right in the textbox.
7
  • How do I get the helpers to translate in phtml? Aug 11, 2017 at 19:41
  • I created a CSV to translate what I wanted and added in the config.xml the data that you passed. Just missing from phtml, could you give me an example? Aug 11, 2017 at 19:43
  • The data I want to translate is not input or something. They come from the database Aug 11, 2017 at 19:54
  • Are you refering to $order->getStatus()? Aug 11, 2017 at 20:22
  • Yes, that's right, he takes the data from this column. Aug 11, 2017 at 20:26
0

All Magento translations are used through the translation methods:

  1. $this->__('your word here');

  2. Mage::helper('helper name')->__('your word here');

Withoud one of these two methods Magento can't translate!

What you have to do is to check if your word have well a translation method.

Then to translate, you have to go to : app/design/frontend/yourPackage/yourTheme/locale/code_ISO/translate.csv then you add your word like this: "My word","My translation"

You can check also if you are using a custom module if you have well declared your helper !

app/code/codePool/Company/ModuleName/etc/config.xml

<?xml version="1.0" />
    ...
    <global>
        <helpers>
            <modulename>
                <class>Company_Modulename_Helper</class>
            </modulename>
        </helpers>
    </global>
    ...

app/code/codePool/Company/ModuleName/Helper/Data.php

class Company_Modulename_Helper_Data extends Mage_Core_Helper_Abstract
{
}

You call it like this: <?php Mage::helper('modulename')->__('My word') ?>

The order status can be translated through the admin configuration admin > system > order status

1
  • I have declared helper, and the status of my requests are translated, has a translation table, what I want to say is that I get the status of a table that is not translated, if you repair there in the question can see that table that I get is (sales / order) which is a status without capital letter, it takes "raw" information, but so I do not need to change the table (sales / order) to (sales_order_status) <THAT IS TRANSLATED, what I Do I need to translate? Or would it be easier for me to get the STATUS information from the other table that has already been translated? Aug 12, 2017 at 4:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.