Skip to content

Conversation

BernhardBaumrock
Copy link
Contributor

Hey @ryancramerdesign I'm developing a new module with RockMigrations. To create an options field the migration looks like this:

<?php

namespace ProcessWire;

return [
  'type' => 'options',
  'inputfieldClass' => 'InputfieldRadios',
  'options' => [
    10 => 'a|automatic',
    20 => 'm|manually',
  ],
];

The problem is that I can not TRANSLATE option labels in this migration file for several reasons. This is not specific to options fields, but on all other fields I was able to translate labes notes and descriptions like this:

  protected function translateField(HookEvent $event): void
  {
    $f = $event->object;
    if (!$f instanceof Inputfield) return;
    $this->translate($f, 'label');
    $this->translate($f, 'notes');
    $this->translate($f, 'description');

    // get fieldtype
    $type = $f->hasFieldtype;

    // translate options
    if ($type instanceof FieldtypeOptions) {
      $options = $type->getOptions($f->hasField);
      foreach ($options as $option) {
        $option->title = $this->x($option->title);
      }
      // dumping options - titles are translated here!
      bd($options);
      $f->options = $options;
    }
  }

Unfortunately the field renders options with their original titles:

image

This missing hook has been a challenge for others (and myself) in the past: https://processwire.com/talk/topic/20321-add-custom-options-to-inputfieldselect-via-a-hook/

If there is a way to modify options of an options field already please let me know!

Otherwise thx for considering this PR :)

@BernhardBaumrock BernhardBaumrock changed the base branch from master to dev July 9, 2025 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant