User tests: Successful: Unsuccessful:
This patch allows the custom field label to be translated with a new string.
To test, enter a constant compatible in the Label field when you create your custom field.
Note: YES, NO, TRUE, FALSE are reserved words in INI format.
; Double quotes in the values have to be formatted as "_QQ_"
For example: JM_MYFIELD
Then add an override for the language in the Language Manager->Overrides
JM_MYFIELD="A nice demo field"
Display the field
Status | New | ⇒ | Pending |
Labels |
Added:
?
|
Category | ⇒ | Front End Components |
maybe, but more complex.
Little by little :)
Note : for this PR, maybe we should check the $label before using JText::_(), i.e. make sure its formatted correctly with a regex.
isn't there a JField attribute to allow translations? i think i saw that somewhwere
yes, but this would mean adding these in the custom field in a way or another as a choice by the user. i.e new columns i guess in the table
https://github.com/joomla/joomla-cms/blob/490674af202168fd5bad38a44fe6a84ef7c894a2/libraries/joomla/form/field.php#L102
Where else do you need it?
Tested further
When adding the strings in en-GB.override.ini both in frontend and backend, I do get the forms translated
JMFIELD="My field"
AHINT="Test a translation of hint"
MYDESCRIPTION="Test a translatable description"
Remark: The Fields tab is double translated
Which is not the case when I use a Field Group AND add a new string
with
CONTENT-GROUP_1="Custom fields 1"
To solve the double translation for $key = 'JGLOBAL_FIELDS'; I guess some more owrk has to be done lines 385-410 of ROOT/administrator/components/com_fields/helpers/fields.php
Therefore concerning that aspect, this PR is fine for articles as it adds the translated label in the article info.
But will we always need to display the label in some other cases (when not editing a form)? I guess it is should be possible to choose to only display the value.
In that case the label should be hidden and only the value displayed.
What do you think?
As almost all code is getting the fields trough this function you can add the JText call of the label somewhere here https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_fields/helpers/fields.php#L102. Then you have it translated everywhere and not only during the output.
Yeps, but when you use the fields directly (they are attached to the item/article as a new variable fields) on a template override, then the label is not translated. Do we want that? If yes, then all is ok here.
I have tested this item
Frontend now displays the translated label.
Yeps, but when you use the fields directly (they are attached to the item/article as a new variable fields) on a template override, then the label is not translated. Do we want that? If yes, then all is ok here.
not sure what you mean. i would need a concrete example i can reproduce easily (code included)
In the file components/com_content/views/article/tmpl/default.php you can do print_r($this->item->fields);
. It will print the fields. Here are the labels not translated. That was what I was talking about.
print_r($this->item->fields);
will just not work anyway (Gets the details of the array) and doing an echo instead of print_r will create the array to string conversion error.
let's get this PR merged.
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
RTC. Thanks for testing.
Milestone |
Added: |
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-11-13 06:26:42 |
Closed_By | ⇒ | roland-d |
Category | Front End Components | ⇒ | Front End com_fields Components |
works as described.
But, shouldn't the same be done to other parts. e.g.: the descriptiom, hint placeholder, etc (dependng on the field)