Jump to content

Multi-language support for module config fields


mach
 Share

Recommended Posts

Hi, as an example, if I have set up a module with the following code for the config fields:

public static function getModuleConfigInputfields(array $data) {

    $inputfields = new InputfieldWrapper(); 

    $field = wire('modules')->get('InputfieldText');
    $field->name = 'headline_default';
    $field->label = "Please enter the headline:";
    $inputfields->add($field); 

    return $inputfields; 
}

Is there a way for the input fields to support multiple languages, similar to TextLanguage fields?  The only alternative that I can think of now is to code in multiple fields for each language:

public static function getModuleConfigInputfields(array $data) {

    $inputfields = new InputfieldWrapper(); 

    $field = wire('modules')->get('InputfieldText');
    $field->name = 'headline_default';
    $field->label = "Please enter the promo headline:";
    $inputfields->add($field); 

    $field = wire('modules')->get('InputfieldText');
    $field->name = 'headline_french';
    $field->label = "Please enter the promo headline (French):";
    $inputfields->add($field); 

    return $inputfields; 
}

but that's not dynamic and would become a hassle if I add multiple modules and/or languages in the future.

Link to comment
Share on other sites

Still nope. There was same question some time ago. Module config is stored as json and you use Inputfields not Fieldtype.

There's the pager module I think where Ryan has text per language . Maybe worth a look.

Sorry I think its in LanguageSupportPageNames module.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Soma, you're right, there's something to be found in the source of LanguageSupportPageNames module: https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/LanguageSupport/LanguageSupportPageNames.module#L781

Actually, Ryan creates a new InputfieldName for each language there, no real Multilanguage Field. Shouldn't this be possible as well?

Edit: I just had a look at the relevant section in ProcessModule module and the way it is handled there sadly doesn't work together with "real" multilanguage fields.

Link to comment
Share on other sites

  • 1 year later...

Would be amazing to get multilanguage ckeditor in form api :)

Or am I mixing things up and it's only not supported for module configs? If so please let me know how to use multilanguage ckeditor with form api, I got a little Newsletter ProcessModule and right now I use 2 textareas side by side, would be neat two have 'em like on a page edit page ;)

Link to comment
Share on other sites

  • 10 months later...
  • 3 years later...

For anyone finding this thread after a google search:

The solution with ProcessWire 3x is

$field = wire('modules')->get('InputfieldText');
$field->name = 'headline_default';
$field->label = "Please enter the promo headline:";
$field->useLanguages = true; // add this line 
$inputfields->add($field);
  • Like 1
Link to comment
Share on other sites

  • 8 months later...

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
 Share

  • Recently Browsing   0 members

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