VirtueMart Forum

VirtueMart 2 + 3 + 4 => Language/Translations => Topic started by: patrik60 on April 05, 2012, 16:32:11 PM

Title: How to translate customfields?
Post by: patrik60 on April 05, 2012, 16:32:11 PM
There is a very complicated explanation of how to translate customfields here at the forum: http://forum.virtuemart.net/index.php?topic=96758.0
Since there is an option in Joomla 2.5 for language override in the backend all these steps are not necessary. Simply do it by choosing Extensions-> Language Manger-> Overrides.

But there is no explanation how to translate the values after selecting the custom field type. Does anybody have an idea how to translate this? I tried it also with a language string but it didn't work.
Title: Re: How to translate customfields?
Post by: balai on April 05, 2012, 16:47:44 PM
Add a language string in capital letters.

e.g. COM_VIRTUEMART_COLOR_RED

then in the lang file write:
COM_VIRTUEMART_COLOR_RED="Red"

p.s. COM_VIRTUEMART prefix is not necessary but is usefull to avoid this string to be translated in another extension
Title: Re: How to translate customfields?
Post by: patrik60 on April 05, 2012, 16:50:32 PM
Do I have to write it in the virtuemart language file? It doesn't work with the language override possibility of Joomla.

EDIT: It can't be the com_virtuemart.ini file. I didn't also find any other language file where it would take effect. So in my opinion a translation of custom field values in VM 2 simply doesn't work :(
Title: Re: How to translate customfields?
Post by: Fintan on April 08, 2012, 09:20:17 AM
I would be interested in this as well.
Title: Re: How to translate customfields?
Post by: ereallstaff on April 23, 2012, 12:03:42 PM
As eplained in the article below:

http://forum.virtuemart.net/index.php?topic=96758.0

You have to write it inside the override files f.e.

language/overrides/fr-FR.override.ini

I was wondering how to translate the value in custom field as it seems to work only with the name of attribute

and overall I was wondering why it has not been made natively by virtuemart, instead of doing all this fools.

Attributes are the most important thing in an e-commerce!
Title: Re: How to translate customfields?
Post by: Studio 42 on April 30, 2012, 22:03:52 PM
Hi,

We have added the Jtext for some customfields Types.
Perhaps some jText is missing or you  don't added the translation in your Ini file.
We use INI file because some variant are reused in many product(sometime in all products)
For the translation i do it simple way , i use the english real word Uppercased.
eg.
RED="rouge"
GREEN="vert"

The advantage is when the jtext is missing the name is write in english because you can choice to not uppercase the Name using "jtext::_('red')" find the language key "RED"
Hope this help
When you use simple word, look if this is not existing in joomla before to don't have lnaguage naming conflict.
Title: Re: How to translate customfields?
Post by: rvbgnu on June 01, 2012, 14:38:32 PM
Hi,
Thank you for these explanations. I am still discovering some parts of VM2.
Currently with version 2.0.6, I could not find how to have the custom fields in drop down menu translated.
I have made a template override of default_customfields.php, adding JTEXT when missing. The CONSTANT is translated, but not the VALUE.
Then in the cart, VALUE is OK.

Electrocity, please, which files did you modify to get it working properly?
Title: Re: How to translate customfields?
Post by: rvbgnu on June 06, 2012, 10:46:49 AM
I have read again this thread, this one
http://forum.virtuemart.net/index.php?topic=100784.0
and the original one from jjk
http://forum.virtuemart.net/index.php?topic=96758.0

but I can't get the value translated...
The drop down menu display "SIZE_VALUE_L", that's my constant name in the .ini file.
We probably need to change another file with JText, the one controlling the menu.

Any hints from VM team, or jjk, please?
Title: Re: How to translate customfields?
Post by: balai on June 06, 2012, 16:16:01 PM
Try to add a suffix.

Something like: COM_VIRTUEMART_SIZE_VALUE_L
Title: Re: How to translate customfields?
Post by: rvbgnu on June 06, 2012, 17:29:43 PM
Thanks balai, but I did it already. I actually use ASF_SIZE_VALUE_L, and I search all the existing language files to make sure there is no duplication.
I just tried with the one you suggested, with no avail...
Title: Re: How to translate customfields?
Post by: balai on June 06, 2012, 18:06:10 PM
Maybe the problem is in the code.

Check if the values are within a JText constructor.
Title: Re: How to translate customfields?
Post by: rvbgnu on June 07, 2012, 01:22:23 AM
Well that is the point, but where in the code?
I failed to trace the file requested to build the drop down menu for the custom fileds. It is in the product details view only, inside the add to cart section.
Here is an extract of the HTML code. I have two custom fields that appears in menu (select / option part):


<div class="addtocart-area">

    <form action="index.php" class="product js-recalculate" method="post">
    <div class="product-fields">
    <div class="product-field product-field-type-V">
<span class="product-fields-title">ASF_SIZE</span>
<span class="product-field-display">

<select name="customPrice[0][7]" id="customPrice07">
<option value="290">ASF_SIZE_VALUE_S </option>
<option value="288">ASF_SIZE_VALUE_M </option>
<option value="287">ASF_SIZE_VALUE_L </option>
<option value="286">ASF_SIZE_VALUE_XL </option>
<option value="285">ASF_SIZE_VALUE_XXL 2,00 €</option>
</select>

</span>

<span class="product-field-desc"></span>
    </div><br>
        <div class="product-field product-field-type-V">
<span class="product-fields-title">ASF_COLOUR</span>
<span class="product-field-display">

<select name="customPrice[1][8]" id="customPrice18">
<option value="291">ASF_COLOUR_ORANGE </option>
<option value="292">ASF_COLOUR_BURGUNDY </option>
<option value="293">ASF_COLOUR_NAVY </option>
</select>

</span>

<span class="product-field-desc"></span>
    </div><br>
        [...]

        </div>
<div id="productPrice33" class="product-price" style="opacity: 1;">
    <strong>Price: </strong><div style="display : none;" class="PricevariantModification">0</div>
<div style="display : none;" class="PricebasePriceWithTax">0</div><div style="display : none;" class="PricesalesPriceWithDiscount">0</div>
<div style="display : block;" class="PricesalesPrice"><span class="PricesalesPrice">14,00 €</span></div>
<div style="display : none;" class="PricediscountAmount">0</div></div>
<div class="addtocart-bar">

<!-- <label for="quantity33" class="quantity_box">Quantity: </label> -->
    <span class="quantity-box">
<input type="text" value="1" name="quantity[]" class="quantity-input js-recalculate">
    </span>
    <span class="quantity-controls js-recalculate">
<input type="button" class="quantity-controls quantity-plus">
<input type="button" class="quantity-controls quantity-minus">
    </span>
   
    <span class="addtocart-button">
<input type="submit" title="Add to Cart" value="Add to Cart" class="addtocart-button" name="addtocart">
</span>

    <div class="clear"></div>
</div>

[...]

    </form>

    <div class="clear"></div>
</div>


Where is(are) the file(s) building the menu (select / option)? A JText function should be inserted there...
Title: Re: How to translate customfields?
Post by: balai on June 07, 2012, 10:33:18 AM
Within the <option></option> write:

<option value="VALUE"><?php echo JText::_('COM_VIRTUEMART_VALUE');?></option>

VALUE->The integer number of that value
COM_VIRTUEMART_VALUE->the value you want to use
Title: Re: How to translate customfields?
Post by: rvbgnu on June 07, 2012, 15:40:59 PM
Thank you Balai,
But this is the HTML rendered, not the source. In which is the php file the menu is built ?
Title: Re: How to translate customfields?
Post by: DarthVaderNow on June 07, 2012, 23:20:25 PM
Hi,
i'm very interrested in any information regarding this too.

no way to know how <option>... menus are built OR what object "$field->display" in default_addtocart.php is reffered to.

BUT: in cart everything working perfectly

Thanks in advance, matic
Title: Re: How to translate customfields?
Post by: rvbgnu on June 08, 2012, 15:59:30 PM
Yes, I know. Very frustrating not to find it... I am still upgrading my php and Joomla programming skills, so I will eventually.
But in the meantime, the website will not look good.

A work around will be to have something else that a menu: text area, radio button, ...
Title: Re: How to translate customfields?
Post by: DarthVaderNow on June 20, 2012, 01:40:59 AM
hi,

i have found a workaround. this is a manual solution and works for me. but is a bug in vmart (if exists price modification in custom field - translations does not work!)

solution:
in file: administrator/components/com_virtuemart/models/customfields.php:623
                       
            //   ORIGINAL:   $group->display = VmHTML::select('customPrice['.$row.']['.$group->virtuemart_custom_id.']',$group->options,$default->custom_value,'','value','text',false);
            // REPAIR (translations are in language overrides)
            $MMMtemp = '';
       $MMMtemp = VmHTML::select('customPrice['.$row.']['.$group->virtuemart_custom_id.']',$group->options,$default->custom_value,'','value','text',false);
            $MMMtemp = str_replace('COM_CUSTOM_FIELD_DOLZINA_ROKAVA_KRATKI',JText::_('COM_CUSTOM_FIELD_DOLZINA_ROKAVA_KRATKI'), $MMMtemp);
            $MMMtemp = str_replace('COM_CUSTOM_FIELD_DOLZINA_ROKAVA_DOLGI',JText::_('COM_CUSTOM_FIELD_DOLZINA_ROKAVA_DOLGI'), $MMMtemp);
            $group->display = $MMMtemp;

hope this helps (took me 7 hours to reverse engineere that with firebug)...

matic
Title: Re: How to translate customfields?
Post by: rvbgnu on June 20, 2012, 12:13:58 PM
Thanks for getting closer, but I have tens of constants in language overrides  :'(

But I think there is some translation methods missing in
administrator/components/com_virtuemart/helpers/html.php,
for example line 335 (public function select), it is where the menu drop down (html tags select / option).
But a simple JText::_() doesn't help here, unfortunately.
Title: Re: How to translate customfields?
Post by: Zegenrijk on October 01, 2012, 13:10:07 PM
SOLVED

Change in: /administrator/components/com_virtuemart/models/customfields.php

Line 870
OLD:
$productCustom->text = $productCustom->custom_value . ' ' . $price;

NEW:
$productCustom->text =  JText::_ ($productCustom->custom_value) . ' ' . $price;

In your product give as a value of the custom field by example: COM_VIRTUEMART_COLOR_BLACK
In the language overrides you give the translations of COM_VIRTUEMART_COLOR_BLACK

Of course, nicer is it that you can translate this fields in the same way as you can translate the productname/product description in another language.