Welcome, Guest
Username: Password: Remember me

TOPIC: Multilingual filter

Multilingual filter 05 Sep 2018 06:25 #15608

  • Frederic
  • Frederic's Avatar
  • Offline
  • Senior Member
  • Posts: 56
  • Karma: 0
Hi every one !
Lets say, we have a category table with the following fields :
- id
- title (default field)
- title_en
- ...

I would like to show title or title_en field in the filter combo depending on language selected by the user.
For the moment, I found a few tricks but none of them works completly...
What would be the best way to do it ?

Thanks in advance,
Best regards,
Fred
Last Edit: 05 Sep 2018 06:25 by Frederic.
The administrator has disabled public write access.

Multilingual filter 09 Sep 2018 18:39 #15609

  • Frederic
  • Frederic's Avatar
  • Offline
  • Senior Member
  • Posts: 56
  • Karma: 0
So, Admin are you there ?
The administrator has disabled public write access.

Multilingual filter 21 Sep 2018 12:36 #15610

  • Frederic
  • Frederic's Avatar
  • Offline
  • Senior Member
  • Posts: 56
  • Karma: 0
So I feel very lonely here... :(

Any idea welcome !

I search the forum but it did not help.

TIA
Best,
Fred
Last Edit: 21 Sep 2018 12:36 by Frederic.
The administrator has disabled public write access.

Multilingual filter 23 Sep 2018 19:10 #15611

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 290
  • Thank you received: 125
  • Karma: 48
Hi there,

I do not think you want to add a field for every language you need ;)
How is this category table filled? Is it a table you have in your component?
And can an item be in only on or more categories?
The administrator has disabled public write access.

Multilingual filter 25 Sep 2018 07:20 #15612

  • Frederic
  • Frederic's Avatar
  • Offline
  • Senior Member
  • Posts: 56
  • Karma: 0
Hi Romkabouter,

Thank you for your answer, I feel a bit less lonely.

This project is stricly bi-lingual. You are right, having a text field for each language would be crazy otherwise.

Yes, the category table is inside my component and its contents change very often so using a language INI file is not a solution...
And Yes, an item is related to only one category.

What do you suggest ?

Best regards,
Fred
Last Edit: 25 Sep 2018 07:21 by Frederic.
The administrator has disabled public write access.

Multilingual filter 25 Sep 2018 18:30 #15613

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 290
  • Thank you received: 125
  • Karma: 48
I don't know how much of a developer you are, but read about forking your component here:
www.j-cook.pro/index.php/f/forks

In the view of the items there is probably something like
		$filters['filter_XXX']->jdomOptions = array(
			'list' => $modelXXX->getItems()
		);
for the categories. (I do not know your code, so try to find it yourself)

That "list" needs to get filled with either the title or title_en, you can do that by overriding your model.

Can you post some screenshots of your builder or folderstructure? I can then give better pointers as to where to change things :)
The administrator has disabled public write access.

Multilingual filter 28 Sep 2018 16:48 #15615

  • Frederic
  • Frederic's Avatar
  • Offline
  • Senior Member
  • Posts: 56
  • Karma: 0
Hi Romkabouter,
Thank you for your help. Maybe, I am not so far from the solution...

Here what I have done :
Forking the view :
// Catégorie > Titre
		$modelCategory = CkJModel::getInstance('categories', 'Cmp18Model');
		$modelCategory->set('context', $model->get('context'));
		$nomFiltre = ($lg == 'fr') ? 'filter_category':'filter_category_en';
		$filters[$nomFiltre]->jdomOptions = array(
			'list' => $modelCategory->getItems()
		);
Forking the items having a category field to filter on, I modify the models/forms/object.xml that way :
<field name="filter_category"
				listKey="id"
				labelKey="libelle"
				type="ckcombo"
				submit="true"
				nullLabel="CMPLUTECE18_FILTER_NULL_CHOISIR_UNE_CATEGORIE"
				class="span-2 element-filter"
				label="CMPLUTECE18_JSEARCH_CATEGORIE_TITRE"
				ui="chosen"/>

		<field name="filter_category_en"
				listKey="id"
				labelKey="libelle_en"
				type="ckcombo"
				submit="true"
				nullLabel="CMPLUTECE18_FILTER_NULL_CHOISIR_UNE_CATEGORIE"
				class="span-2 element-filter"
				label="CMPLUTECE18_JSEARCH_CATEGORIE_TITRE"
				ui="chosen"/>

In the model categories.pfp file, I forked the prepareQuery function to order the query on libelle or libelle_en field depending on the selected language.

With these modifications done, I am able to get the filter combo for category filled with the selected language and it is well ordered... Great ! but...

What is not working... :(

In English, when a filter is applied, the combo box does not display the selected value as it does in french...

Any idea ? Or another way to do it ?

Best regards,
Fred
The administrator has disabled public write access.
Time to create page: 0.082 seconds

Get Started