1

Is there a way to be able to translate data inside grid table in {exp:channel:form}?

I want to change the table headers to be translated.

I also want to change the button to add new rows to something like a translatable word(for example, "add row").

Is this possible with Grid? Or are we stuck with what we input in the channels?

EDIT:

My question only applies to the publish form inside a Channel Form tag. I am not looking for a solution that works on the EE Control Panel.

1

Preface: this is just an idea.

You could use Brian Litzinger's Publisher (http://devot-ee.com/add-ons/publisher) on exp:channel:form to allow for grid translations.

To change the headers and buttons you could possibly add the grid to the Channel Form, grab the rendered code and paste that into the template directly (rather than letting the field generate the HTML on the fly) and then use Publisher's language tags to translate headers and buttons.

So for example, I might make a Channel Form and tell it to render the grid. Looking at the code I will see that it generates...

<table id="testing" class="grid_field_container" cellspacing="0" cellpadding="0">
<tr>
    <td class="grid_field_container_cell">
        <table class="grid_field" cellspacing="0" cellpadding="0">
            <thead>
                <th class="grid_handle">&nbsp;</th>
                <th width="0%"><b>Column 1</b></th>
                <th width="0%"><b>Column 2</b></th>
            </thead>
            <tbody class="grid_row_container">
                <tr class="grid_row blank_row">
                    <td class="grid_handle">&nbsp;</td>
                    <td width="0%" data-fieldtype="text" data-column-id="1">
                        <div class="grid_cell">
                            <input type="text" name="testing[rows][new_row_0][col_id_1]" value="" dir="ltr" field_content_type="all" maxlength="256"  />
                        </div>
                    </td>
                    <td width="0%" data-fieldtype="text" data-column-id="2">
                        <div class="grid_cell">
                            <a href="#" class="grid_button_delete" tabindex="-1" title="Delete Row">Delete Row</a>
                            <input type="text" name="testing[rows][new_row_0][col_id_2]" value="" dir="ltr" field_content_type="all" maxlength="256"  />
                        </div>
                    </td>
                </tr>
                <tr class="empty_field">
                    <td colspan="3" class="empty_field first">You have not added any rows of data yet. <a href="#" class="grid_link_add">Add some data?</a></td>
                </tr>
            </tbody>
        </table>
    </td>
    <td class="grid_delete_row_gutter">&nbsp;</td>
</tr>
<tr>
    <td>
        <a class="grid_button_add" href="#" title="Add Row">Add Row</a>
    </td>
</tr>

Well you could now change that to use Publisher "Phrases" (https://boldminded.com/add-ons/publisher/phrases)

<table id="testing" class="grid_field_container" cellspacing="0" cellpadding="0">
<tr>
    <td class="grid_field_container_cell">
        <table class="grid_field" cellspacing="0" cellpadding="0">
            <thead>
                <th class="grid_handle">&nbsp;</th>
                <th width="0%"><b>{phrase:form_col1}</b></th>
                <th width="0%"><b>{phrase:form_col1}</b></th>
            </thead>
            <tbody class="grid_row_container">
                <tr class="grid_row blank_row">
                    <td class="grid_handle">&nbsp;</td>
                    <td width="0%" data-fieldtype="text" data-column-id="1">
                        <div class="grid_cell">
                            <input type="text" name="testing[rows][new_row_0][col_id_1]" value="" dir="ltr" field_content_type="all" maxlength="256"  />
                        </div>
                    </td>
                    <td width="0%" data-fieldtype="text" data-column-id="2">
                        <div class="grid_cell">
                            <a href="#" class="grid_button_delete" tabindex="-1" title="Delete Row">{phrase:form_delete}</a>
                            <input type="text" name="testing[rows][new_row_0][col_id_2]" value="" dir="ltr" field_content_type="all" maxlength="256"  />
                        </div>
                    </td>
                </tr>
                <tr class="empty_field">
                    <td colspan="3" class="empty_field first">{phrase:form_no-rows} <a href="#" class="grid_link_add">{phrase:form_add-data}</a></td>
                </tr>
            </tbody>
        </table>
    </td>
    <td class="grid_delete_row_gutter">&nbsp;</td>
</tr>
<tr>
    <td>
        <a class="grid_button_add" href="#" title="Add Row">{phrase:form_add-row}</a>
    </td>
</tr>

You would then just set those phrases in your Publisher's control panel and it should do the job.

Bare in mind: this is a bit of a hacky solution, and if Grid's markup changes you'll have to rinse and repeat.

8
  • I think I already have an add-o to translate. The problem is that I have nowhere to put the code that translates unless I hack the core files. I have looked into the hooks to see if I can use some of them but I don't see anything that helps me change the talbe header. – developarvin Mar 4 '14 at 7:18
  • What is your translate add-on? – Mutual Mar 4 '14 at 10:29
  • I just created an add-on using EE's underlying CI language support(ee()->lang->line). I can use it as a tag or as a function inside extensions. Problem is, I don't see any extensions where I can change the strings in the publish form of Grids. – developarvin Mar 4 '14 at 11:56
  • Could you write a simple plugin called {exp:yourplugin:string phrase="add_field"} which would look at your translation dictionary and return the string, and mix that with my idea above - swapping {phrase:} with your plugin? – Mutual Mar 4 '14 at 16:47
  • Sure. But what I don't know is how to grab the template and be able to change the header and footer. I don't see it indicated in your answer. – developarvin Mar 4 '14 at 23:55
0

Know it's a 2014 question. To help people looking into this in the future, you can use "Low Replace". Example:

{exp:low_replace find="You have not added any rows of data yet|Add some data" replace="No agregaste informacion|Agregar" multiple="yes"}
{field:estudios_en_curso_y_terminados}
{/exp:low_replace}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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