This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Minius
Minius

Hi, Yes, october cms is perfect tools :) now im have build 5 sites with it, cool :) but need some help. One think i cant figure out: can`t translate slug from my plugin.

Approximately my octobercms environment is:

  • inf config edgeUpdates => true;
  • all updates instaled;
  • for translation i`m using rainlab-translate;
  • for plugin development using rainlab-builder plugin, everythink fine with it;
  • in plugin model, as translatable attributes, i set: ['slug', 'index' => true];
  • and in responsible layout config are correct (as i think): url param: url = "/produktai/:slug" viewBag: localeUrl[en] = "/products/:slug"
  • any other translation i.e. static page, cms page works perfect;
  • any error related with translation.

Say for example, if i make slug translation, so only model, who has slug in general language is accessible. If i try access it with translated slug - it does`t work. Work on with default (general language) slug. Why is the problem? And even, i try default october rainlab-blog plugin, and it is the same situation: translatable slug not working.

As i think, all magic is usage of ['slug', 'index' => true] , not ?

Last updated

Minius
Minius

Okey, it looks like solutions at the end is use translation metod transWhere, for example

Post::transWhere('slug', 'hello-world', 'en')->first();

as wrote here: https://github.com/rainlab/translate-plugin now its work :)

witul
witul

I have a bit different question, but also about slugs. Is it possible to make a "slug" preset in a backend form, which depends on translatable field? I would like to generate slugs for each language variant of field.

roulendz
roulendz

Minius said:

Okey, it looks like solutions at the end is use translation metod transWhere, for example

Post::transWhere('slug', 'hello-world', 'en')->first();

as wrote here: https://github.com/rainlab/translate-plugin now its work :)

Can you give your example how you was able to fix this and where did you put that code?

Thanks!

witul
witul

rolands.zeltins22620 said:

Minius said:

Okey, it looks like solutions at the end is use translation metod transWhere, for example

Post::transWhere('slug', 'hello-world', 'en')->first();

as wrote here: https://github.com/rainlab/translate-plugin now its work :)

Can you give your example how you was able to fix this and where did you put that code?

Thanks!

Check here

endorphinum21929
endorphinum21929

Hi Witul, i am having the same problem and in theory understand what has to be done. But where and why? Do you write this line of code

Post::transWhere('slug', 'hello-world', 'en')->first(); inside the PHP code section of the page or where? I am absolutely stuck with this problem. Thanks in advance for your support and time! Carlos

marco.messa325452
marco.messa325452

Up. I also can't get a rid of this. My single plugin page has this url /products/:slug I added [viewBag] localeUrl[it] = '/prodotti/:slug'

and of course in my product model I implemented translatable and indexes

 public $implement = ['@RainLab.Translate.Behaviors.TranslatableModel'];

    public $translatable = [
        'title',
        ['slug', 'index' => true]
    ];

When I switch language ad inspect a link to a translated single product page, the href is correctly set to /my-translated-base/my-translated-slug but is an empty page! If i switch language from inside the single product page, the url is /my-translated-base/MYORIGINALSLUG and I can see my product page translated.

I can't understand whats going on, and also how this code has to be used:

Post::transWhere('slug', 'hello-world', 'en')->first();

I tried in my single plugin page php zone, importing firstly the model and then triggering this code in onStart or onInt or onRun function:

===
use Mmes\Contents\Models\Content

function onRun(or start or init, whatever)() {
    Content::transWhere('slug', 'hello-world')->first();
or      Content::transWhere('slug', $this->params('slug'))->first();
}
===

The point is that I don't understand what this code i supposed to do, so I'm in a logical trap :D. If someone could help, I'll really appreciate!

Last updated

hellopaint
hellopaint

Use `Post::transWhere('slug', 'hello-world', 'en')->first();' for load in detail page the correct slug. For exemple, if you are using Builder Plugin, you can create a component detail:

$model = new $modelClassName();
$model = $model::transWhere($this->page['modelKeyColumn'], $this->identifierValue)->first();
marco.messa325452
marco.messa325452

Thank you for your reply! I already came up with the same solution, and it's working smoothly!

Thank you again!

hellopaint
hellopaint

I have one question about this. I generate the slug in backend form like preset from a title, but when I change language overwrite the other slug languages. Do you have any solution for this? Thanks.

Last updated

marco.messa325452
marco.messa325452

Do you use sluggable traits? I have no problems not using it and presetting slug creation from otherfileds' value.

EXAMPLE MODEL

public $implement = ['RainLab.Translate.Behaviors.TranslatableModel'];
public $translatable = ['name', [ 'slug', 'index' => true ], 'description', 'title', 'url'];

and then in fields.yaml

company:
        label: 'Azienda'
        span: left

    slug:
        label: 'Slug'
        span: right
        preset:
            field: company
            type: slug

I need then to manually change slug's value of other languages, because presets fill slug's field only with main language translation.

didier28788
didier28788

marco.messa325452 said:

Thank you for your reply! I already came up with the same solution, and it's working smoothly!

Thank you again!

Could you please now tell us where and how did you use the Transwhere method? Did you end up using it in the model or in the single page, and with which function? I'm exactly stuck where you were 9 months ago...

Many thanks!

Last updated

andrius
andrius

Hi every one, the same problem, slug translations not work for me (Record not found), work only with general language slug. What I am doing wrong?

The model page:

title = "Product details"
url = "/produktai/:seo_url"
layout = "default"
is_hidden = 0

[viewBag]
localeUrl[en] = "/products/:seo_url"

[builderDetails]
modelClass = "Myplugin\Products\Models\Product"
identifierValue = "{{ :seo_url }}"
modelKeyColumn = "seo_url"
displayColumn = "name"
notFoundMessage = "Record not found"``
==
<?php
    use Myplugin\Products\Models\Product;
    function onStart(){
        Product::transWhere('seo_url', $this->param('seo_url'))->first();
    }
?>
== 

In product model:

public $implement = ['@RainLab.Translate.Behaviors.TranslatableModel'];
    public $translatable = [
        'name',
        'text',
        'description',
        'meta_title',
        'meta_description',
        'meta_keywords',
        ['seo_url', 'index' => true]
    ];

Thanks!!!

1-13 of 13

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.