Support Log in

44. Integration with LangForge (Multilingual Forms)

Developer Guide
Prefer video? Watch the Form Forge tutorials 9 short guides covering every feature Watch

Use Lang Forge to translate form labels, placeholders, and messages into multiple languages.

Registering Form Strings for Translation

php
add_action( 'plugins_loaded', function() {
    if ( ! class_exists( 'LANGFORGE_Core' ) || ! class_exists( 'FORMFORGE_Core' ) ) return;

    $forms = FORMFORGE_Form_Builder::instance()->get_all();
    foreach ( $forms as $form ) {
        // Register form title
        langforge_register_string( 'Form Forge', 'form_title_' . $form->id, $form->title );

        // Register field labels and placeholders
        foreach ( $form->fields as $field ) {
            if ( ! empty( $field['label'] ) ) {
                langforge_register_string( 'Form Forge', 'field_label_' . $field['id'], $field['label'] );
            }
            if ( ! empty( $field['placeholder'] ) ) {
                langforge_register_string( 'Form Forge', 'field_placeholder_' . $field['id'], $field['placeholder'] );
            }
        }

        // Register success message
        $msg = $form->settings['success_message'] ?? '';
        if ( $msg ) {
            langforge_register_string( 'Form Forge', 'success_' . $form->id, $msg );
        }
    }
}, 30 );

Applying Translations at Render Time

php
add_filter( 'formforge_field_render', function( $html, $field ) {
    if ( ! function_exists( 'langforge_translate_string' ) ) return $html;

    $label = langforge_translate_string( 'Form Forge', 'field_label_' . $field['id'] );
    if ( $label && $label !== $field['label'] ) {
        $html = str_replace(
            esc_html( $field['label'] ),
            esc_html( $label ),
            $html
        );
    }
    return $html;
}, 10, 2 );

Per-Language Form Variants

For complex multilingual sites, create separate forms per language and load based on locale:

php
function my_theme_multilingual_form() {
    $locale = get_locale();
    $form_map = [
        'en_US' => 10,
        'es_ES' => 11,
        'fr_FR' => 12,
        'de_DE' => 13,
    ];
    $form_id = $form_map[ $locale ] ?? $form_map['en_US'];
    return FORMFORGE_Form_Renderer::instance()->render( $form_id );
}

Forge AI Assistant Online

Hi! I'm the Form Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs