Jump to content

setOptionsStringLanguages() does not works (setOptionsString works, but only for default one, with translations...)


Recommended Posts

Posted (edited)

Hi everybody,

I'm trying to translate options into already activated languages, via hook: setOptionString works correctly for the default language, but I can't populate the options in other languages.
More specifically, changing the user profile language the titles are translated, but the options are overwritten in the "default" language tab.

So I have found the setOptionsStringLanguages method, but it seems to break someting (I have an error like: ProcessPageEdit:Multi language not enabled.. of course it's enabled)

The scenario is a hook for an inputfield:render

Spoiler
$wire->addHookBefore('InputfieldSelect::render', 'optionPopulate');

function optionPopulate($event){

    $inputfield = $event->object;
    if ($inputfield->name != "MY_FIELD_NAME") return;

    $pages = wire('pages')->find('template=MY_TEMPLATE, sort=sort, registration=1');

    // Set the groups in the field
    $field1 = wire('fields')->get('MY_FIELD_NAME');
    $field1->useLanguages = true; // It seems to do nothing (?)
    $manager1 = new SelectableOptionManager();
    $langOptions = [];
    foreach (wire('languages') as $lang) {
        $options = '';
        $langOptions[$lang->id] = '';
            foreach ($pages as $p){
                $options .= $p->id . '=' . ($p->getLanguageValue($lang->id,'title') ?? $p->title.$lang->id).'
            ';
            }
        $options .= '99=' . __('Independent', '/site/templates/transaltions/front_end.php').'
        ';
        $langOptions[$lang->id] = $options;

        // SECOND APPROACH: FORCING OPTION BY EACH LANGUAGES, BUT DO NOTHING
        // wire('user')->laguage = $lang;
        // $manager1->setOptionsString($field1, $langOptions[$lang->id], true);

    }
// FIRST APPROACH: PageEdit Error: MultiLanguage Support not activated (???)
$manager1->setOptionsStringLanguages($field1, $langOptions, true);
}

 

Any suggestion?

Thanks in advance.

Edited by Cybermano
Typos
  • Cybermano changed the title to setOptionsStringLanguages() does not works (setOptionsString works, but only for default one, with translations...)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...