- Posts: 25
- Thank you received: 2
Auto-generate alias on content translation
5 years 1 month ago #335340
by braverman
Auto-generate alias on content translation was created by braverman
-- HikaShop version -- : 4.4.3
-- Joomla version -- : 3.9.28
-- PHP version -- : 7.4.22
Hi,
my client translates hundreds of categories/products/etc. into 4 languages using the Falang extension. All works fine but I am trying to improve it a little. When saving translation from edit page I would like to autogenerate alias according to the name field (using stringURLSafe function). I don't like to hack core files so the ideal solution would be either if you implement this function (should be few lines in translation helper in function handleTranslations and one toggle switch in configuration) or more universally to trigger plugin event before and/or after translation saving.
Does it sound meaningful?
Thanks, Jan
-- Joomla version -- : 3.9.28
-- PHP version -- : 7.4.22
Hi,
my client translates hundreds of categories/products/etc. into 4 languages using the Falang extension. All works fine but I am trying to improve it a little. When saving translation from edit page I would like to autogenerate alias according to the name field (using stringURLSafe function). I don't like to hack core files so the ideal solution would be either if you implement this function (should be few lines in translation helper in function handleTranslations and one toggle switch in configuration) or more universally to trigger plugin event before and/or after translation saving.
Does it sound meaningful?
Thanks, Jan
Please Log in or Create an account to join the conversation.
5 years 1 month ago - 5 years 1 month ago #335342
by nicolas
Replied by nicolas on topic Auto-generate alias on content translation
Hi,
The handleTranslations is not really adapted to have before/after events.
And you can already use the onAfterProductUpdate and onAfterCategoryUpdate events to set the alias in the translations if empty.
And it's a bit more than a few lines to add code to handle that. It's more like 40 lines to do it properly.
But yes, it's a good idea to generate the alias automatically for the translation when the "alias auto fill" setting of the HikaShop configuration is activated. We'll look at adding that, thanks for your feedback.
The handleTranslations is not really adapted to have before/after events.
And you can already use the onAfterProductUpdate and onAfterCategoryUpdate events to set the alias in the translations if empty.
And it's a bit more than a few lines to add code to handle that. It's more like 40 lines to do it properly.
But yes, it's a good idea to generate the alias automatically for the translation when the "alias auto fill" setting of the HikaShop configuration is activated. We'll look at adding that, thanks for your feedback.
Last edit: 5 years 1 month ago by nicolas.
Please Log in or Create an account to join the conversation.
5 years 1 month ago #335347
by braverman
Replied by braverman on topic Auto-generate alias on content translation
Thanks! 
I thought that translation editing uses controller function save_translation that does not update product/category and so does not trigger onAfterProductUpdate or onAfterCategoryUpdate. But maybe I am wrong, did not test it.
Jan
I thought that translation editing uses controller function save_translation that does not update product/category and so does not trigger onAfterProductUpdate or onAfterCategoryUpdate. But maybe I am wrong, did not test it.
Jan
Please Log in or Create an account to join the conversation.
5 years 1 month ago #335348
by nicolas
Replied by nicolas on topic Auto-generate alias on content translation
Hi,
That's my bad. You're correct. Still, we'll look at adding that. It will be better that way as events as not really appropriate there.
That's my bad. You're correct. Still, we'll look at adding that. It will be better that way as events as not really appropriate there.
Please Log in or Create an account to join the conversation.
4 years 6 months ago #340864
by braverman
Replied by braverman on topic Auto-generate alias on content translation
Hi,
I returned to this topic after some time and found that it is half way. I found changes in handleTranslations method but if I see correctly these changes are never executed because the variable $auto_fill_prefix is never true. Am I correct?
Thanks, Jan
I returned to this topic after some time and found that it is half way. I found changes in handleTranslations method but if I see correctly these changes are never executed because the variable $auto_fill_prefix is never true. Am I correct?
Thanks, Jan
Please Log in or Create an account to join the conversation.
4 years 6 months ago #340866
by nicolas
Replied by nicolas on topic Auto-generate alias on content translation
Hi,
That's a good point. I think I forgot to change the code calling handleTranslations in the product controller.
I'll change the line for the next version (4.5.2) :
$translationHelper->handleTranslations('product',$element->product_id,$element);
to:
$translationHelper->handleTranslations('product',$element->product_id,$element, 'hikashop_', null, true);
in administrator/components/com_hikashop/controllers/product.php and that should do it.
That's a good point. I think I forgot to change the code calling handleTranslations in the product controller.
I'll change the line for the next version (4.5.2) :
$translationHelper->handleTranslations('product',$element->product_id,$element);
to:
$translationHelper->handleTranslations('product',$element->product_id,$element, 'hikashop_', null, true);
in administrator/components/com_hikashop/controllers/product.php and that should do it.
The following user(s) said Thank You: braverman
Please Log in or Create an account to join the conversation.
4 years 6 months ago #340881
by braverman
Replied by braverman on topic Auto-generate alias on content translation
Thanks.
I tested it (patched it according to your post) and found some other errors in translation.php:
On line 327 instead:
changed to:
and line 332
to
Now it works.
Jan
I tested it (patched it according to your post) and found some other errors in translation.php:
On line 327 instead:
Code:
if($config->get('alias_auto_fill', 1) && $auto_fill_prefix && $field == $name_field && !empty($trans) && empty($transArray[$alias_field])) {
Code:
if($config->get('alias_auto_fill', 1) && $auto_fill_prefix && $field == $name_field && !empty($trans) && empty($transArray[$alias_field][$lg])) {
and line 332
Code:
$emptyObject->$name_field = $trans;
Code:
$emptyObject->$name_field = $value;
Now it works.
Jan
The following user(s) said Thank You: nicolas
Please Log in or Create an account to join the conversation.
4 years 6 months ago #340882
by nicolas
Replied by nicolas on topic Auto-generate alias on content translation
Hi,
Thank you for your feedback. We'll add these modifications for the 4.5.2
Thank you for your feedback. We'll add these modifications for the 4.5.2
The following user(s) said Thank You: braverman
Please Log in or Create an account to join the conversation.
Time to create page: 0.132 seconds