• Any support/planned support for Gravity Forms? Would the manually translated fields ([:en][:] syntax) still work?

Viewing 11 replies - 1 through 11 (of 11 total)
  • I plan this. But in paid version. It is currently in development.

    Thread Starter reddo

    (@reddo)

    Would the manually translated fields ([:en][:] syntax) still work?

    Yes. It is base syntax for WP Multilang.

    Thread Starter reddo

    (@reddo)

    Cool, thanks a lot. I’m considering switching from qtranslate-x before it breaks the site on an update.

    Use test server before.

    Thread Starter reddo

    (@reddo)

    That’s the plan.

    Thread Starter reddo

    (@reddo)

    I’ve been playing around with the plugin on a test server amd, after ironing out a few problems with migration, it doesn’t seem to work with gravity forms at all.

    See this screenshot: https://goo.gl/vWU6xV

    None of the (manually) translated fields get switched.

    You need add filters before displaying strings. If it possible in Gravity Form.

    Thread Starter reddo

    (@reddo)

    I wrote the following function:

    
    function translate_gravity_forms( $form ) {
      $form['title'] = wpm_translate_string($form['title']);
        
      if ($form['description']) {
        $form['description'] = wpm_translate_string($form['description']);
      }
    
      foreach( $form['fields'] as &$field ) {
        $field['label'] = wpm_translate_string($field['label']);
        
        if ($field['description']) {
          $field['description'] = wpm_translate_string($field['description']);
        }
    
        if ($field['content']) {
          $field['content'] = wpm_translate_string($field['content']);
        }
        
        if ($field['choices']) {
          foreach( $field['choices'] as &$choice ) {
            $choice['text'] = wpm_translate_string($choice['text']);
          }
        }
      }
    
      return $form;
    }
    add_filter( 'gform_pre_render', 'translate_gravity_forms' );
    

    And the fields still don’t get translated. Am I using the wrong function? which one should I use?

    This is getting more complicated than it needs to be ??

    Thread Starter reddo

    (@reddo)

    Any info on this?

    Thread Starter reddo

    (@reddo)

    To anyone concerned

    I’ve found the correct way to translate gravity fields:

    
    function translate_gravity_forms( $form ) {
      $form['title'] = wpm_translate_string($form['title']);
        
      if ($form['description']) {
        $form['description'] = wpm_translate_string($form['description']);
      }
    
      foreach( $form['fields'] as &$field ) {
        $field->label = wpm_translate_string($field->label);
        
        if ($field->description) {
          $field->description = wpm_translate_string($field->description);
        }
    
        if ($field->content) {
          $field->content = wpm_translate_string($field->content);
        }
        
        if ($field->choices) {
          foreach( $field->choices as &$choice ) {
            $choice['text'] = wpm_translate_string($choice['text']);
          }
        }
      }
    
      return $form;
    }
    add_filter( 'gform_pre_render', 'translate_gravity_forms' );
    

    References:
    Form Object Source
    Field Object Source

    I do not give my consent to include this in a paid version of this plugin, but it’s ok to include it in the free version or as a standalone plugin (with attribution).

    • This reply was modified 6 years, 9 months ago by reddo.
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Gravity Forms’ is closed to new replies.