Welcome, Guest
Username: Password: Remember me

TOPIC: Wrap FK Select in a JText

Wrap FK Select in a JText 13 Nov 2017 14:41 #15433

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
So we have a 1:n FK table using a cross reference table. Here is the generated code
<div class="chzn-drop">
<ul class="chzn-results">
<li class="active-result" data-option-array-index="0" style="">Full Time</li>
<li class="active-result" data-option-array-index="1" style="">Part Time (1/5)</li>
<li class="active-result" data-option-array-index="2" style="">Part Time (2/5)</li>
<li class="active-result" data-option-array-index="3" style="">Part Time (3/5)</li>
<li class="active-result" data-option-array-index="4" style="">Part Time (4/5)</li>
<li class="active-result" data-option-array-index="5" style="">Selected Days</li>
</ul>
</div>

the problem is however, i need to make this fully multiligual, whcih is EASY with an enum table, but not with FK 1:n

Ideally I want the generated multiselect to output

<li class="active-result" data-option-array-index="5" style=""><?php echo JText::_('Selected Days'); ?></li>

then I can just add the strings to the language overrides (or use simpler labels such as SELECTED_DAYS

Thanks for any assistance
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Wrap FK Select in a JText 13 Nov 2017 19:13 #15434

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
My advice: add a field language, check the joomla 'content' table.
You can find the current language via
JFactory::getLanguage()->getTag();
It will return "en-GB" if the site is currently shown in english.
Use it in your orm statements :)
The field in the table can be filled in the form, you can achieve it via an enum or via the contentlanguage field
docs.joomla.org/Contentlanguage_form_field_type
The administrator has disabled public write access.

Wrap FK Select in a JText 13 Nov 2017 19:19 #15435

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
Sorry, I was incomplete.
You need to have a "base", so you can switch the language without losing the ID
The base will be linked to the translated versions, the translated versions should have the language field
The administrator has disabled public write access.

Wrap FK Select in a JText 14 Nov 2017 12:18 #15436

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
If the label is multilanguage, then you need that translated string into the data row.
Just change "labelKey" for setting which column you select on the row item.

I think it is quite basic question...
The most dificult is the language system iteself at the database level.
You need a versioning system, wich is still not avalailable in Cook
Coding is now a piece of cake
The administrator has disabled public write access.

Wrap FK Select in a JText 14 Nov 2017 15:43 #15437

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
I think there may be a little misunderstanding of my problem,
I know how multilingual works, and the site is live in three languages with everything translated except for this cross reference field

JOB (id)
|
JOBtoREGIEME (job_id, regieme_id)
|
REGIME (id, regieme_string)

The generated mutlselect (relational) dropdown pulls in the regieme string as the 'choices' and I need these to be in several languages

I have no way that I can see of letting the system know 'THIS is a constant, translate me'

This is the current model for reference as to what type it is

<field name="regimens"
alias="id"
label="MYPROJECT_FIELD_REGIME"
filter="array"
type="relation"
multiple="true"
labelKey="regimen"/>
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
Last Edit: 14 Nov 2017 15:58 by MorganL.
The administrator has disabled public write access.

Wrap FK Select in a JText 14 Nov 2017 16:24 #15438

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
I think this is all generated by the chosen jquery script
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Wrap FK Select in a JText 23 Nov 2017 20:43 #15451

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
Sorry, I was a bit busy. I will post an update soon but I think I have a solution
The administrator has disabled public write access.
The following user(s) said Thank You: MorganL

Wrap FK Select in a JText 25 Nov 2017 14:14 #15457

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
You are a clever chap! I expected no less :-D
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Wrap FK Select in a JText 01 Dec 2017 10:04 #15463

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
I almost got this one, just to make sure: this translation you need a frontend form yes?
The administrator has disabled public write access.
The following user(s) said Thank You: MorganL

Wrap FK Select in a JText 01 Dec 2017 10:05 #15464

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
Absolutely only Front End
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Wrap FK Select in a JText 01 Dec 2017 13:22 #15466

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
Ok good. I've got it working for a 1-1 relation of job-regime when I read you have a 1-N.
Will change that now, attached is a working version with 1-1 but do not pay too much attention to that
In general:
- extra table 1-N from regime->translation
- translation item has a language field and a translation field. And FK to regime. The language is a string field, but you could take that a step further :)
- fork the job, the regimes are joined with the translations and the translation is added a extra select
- fork the form.xml, change the labelKey

I do not know if this will work for 1-N, so I am going to try that :)

- attach did not work :\
Last Edit: 01 Dec 2017 13:22 by Romkabouter.
The administrator has disabled public write access.

Wrap FK Select in a JText 01 Dec 2017 14:54 #15467

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
So ok, that also works, with some other steps: a custom field

Here's how I made this:
  • add an extra table regimetranslations, with field: regime (FK), translation (string) and language (string). The language could be a dropdown, but is ok for now
  • add views for this table, the item view having the regime dropdown and the two textfields
  • for language, fill in the tag like en-GB
  • create folder "fork" in the site component folder, with "models" as subfolder and in there a "forms" folder
  • copy job.xml from the non-forked folder in there and edit it: remove all fieldsets except the one with the regimes field
  • in the addfieldpath, add "fork" in the path: addfieldpath="/administrator/components/com_yourcomponent/fork/models/fields"
  • change labelKey to " translation" and type to "regimetranslation", see attached job.xml
  • create folder "fork" in the admin component folder, with "models" as subfolder and in there a "fields" folder
  • copy relation from the non-forked folder in there and rename to regimetranslation.php
  • remove all functions, change "extends JFormFieldModel" to "extends JFormFieldRelation" and loadFieldClass('model') to loadFieldClass('relation'); See attached choicetranslation.php
  • put in the protected function getOptions(), this will override the items

Now you got a translated multiselect field. This can be made smoother, as to work with EVERY multiselect but for now it works ;)
See my attached custom field, you will have to edit it to reflect the correct classnames!

If you see only a textfield in the JobForm, that means something is (still) wrong with the custom field. Let us know if you encounter problems.
Attachments:
The administrator has disabled public write access.
Time to create page: 0.194 seconds

Get Started